summaryrefslogtreecommitdiff
path: root/archive/.zshrc
blob: b37003b6531ce9212ab623f1cd74fc94ae540184 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# Credits for much of the following config file: tomaw,
# <slarti@gentoo.org>, <spider@gentoo.org>, <ciaranm@gentoo.org>

# --- personal settings

# basic env
source ~/.shenv
export GPG_TTY=$(tty)

# colours
if ! [[ "$TERM" == "dumb" ]]; then
    autoload -U colors; colors
    export PS1="%(?..%? )%{$fg[${1:-yellow}]%}%m %{$fg[${1:-green}]%}%~ %{$fg[${1:-blue}]%}%#%{$reset_color%} "
fi

# add newer GHC to PATH if interactive shell (can't just add in .shenv
# because xmonad needs the old one)
# if [[ $- == *i* ]]; then
#     if [ -d "$HOME/local/stow/ghc/bin" ]; then
#        export PATH=$HOME/local/stow/ghc/bin:$PATH
#     fi
# fi

# TODO more robust way to find develacc -- perhaps drop a flagfile
# /etc/in-develacc
# TODO add to enter-develacc-i3 too?  needed?
if [ "$(whoami)" = "spw" \
                 -a "$(systemd-detect-virt)" = "systemd-nspawn" \
                 -a "$(hostname -d)" = "silentflame.com" ]; then
    umask 002
fi

# --- terminals

# From dev.gentoo.org/~ciaranm/configs/bashrc
if [[ "${TERM}" == "rxvt-unicode" ]] ; then
    export TERMTYPE="256"
elif [[ "${TERM}" != "dumb" ]] ; then
    export TERMTYPE="16"
fi

if [[ "${TERM}" == "rxvt-unicode" ]] && \
    [[ ! -f /usr/share/terminfo/r/rxvt-unicode ]] && \
    [[ ! -f ~/.terminfo/r/rxvt-unicode ]] ; then
    export TERM=rxvt
fi

# set window title

precmd() {
    #    [[ -t 1 ]] || return
    case $TERM in
        *xterm*|rxvt*) print -Pn "]2;%n@%m:%~\a"
            ;;
        # screen*) print -Pn "\"%n@%m:%~\134"
        # ;;
    esac
}

# --- aliases

alias ls="ls -F --color=always"
alias ll="ls -al"
alias g="git"
alias ga="git annex"
alias gs="git status"
# better: pa fax | grep
# alias pg="ps auxxxxxxxxxxxxxxxxxxx | grep"
alias d="emacsclient -c -n -e '(dired \".\")'"
alias mg=$EDITOR
alias mrs="mr -m status"

alias screen="screen -U" # enable UTF-8
alias tmux="tmux"
alias rax="screen -URaAx"
alias ta="tmux attach-session"

alias blogdates="rdate.py-dir ~/html/blog/entries"
alias httpdir="sudo python -m SimpleHTTPServer 80"
alias sdfvpn="sshuttle -r ma 0/0 --dns --auto-hosts --python /usr/pkg/bin/python2.7"
alias athvpn="sshuttle -r athena 0/0 --dns"
alias calup="emacs -batch -l /home/swhitton/.emacs.d/init.el -eval \"(org-batch-store-agenda-views)\""
alias dotex="texi2dvi --pdf --clean --batch"
alias whitenoise="cvlc --quiet --loop ~/lib/annex/doc/sounds/R*.ogg"
alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
alias mailnow="pkill mbsync ; mbsync -q fastmail && mutt -Z"
alias mykb="setxkbmap gb; setxkbmap -option ctrl:nocaps"
alias fixmacs="pkill -USR2 emacs"
alias myfiles="cadaver https://myfiles.messagingengine.com/"
alias unstow="stow -D"
alias sid="sudo /usr/local/bin/enter-sid /bin/sh -c \"export DISPLAY=${DISPLAY}; su - swhitton\""
alias uavpn="pkill rtorrent && sudo openconnect https://vpn.arizona.edu/ && TERM=dumb rt"
alias loungempd="ssh TallGeese /Applications/VLC.app/Contents/MacOS/VLC -I rc --loop http://192.168.1.72:8000"
alias sid-build-deps="sudo mk-build-deps -irt 'apt-get -o Debug::pkgProblemResolver=yes -t sid --no-install-recommends'"
alias testing-build-deps="sudo mk-build-deps -irt 'apt-get -o Debug::pkgProblemResolver=yes -t testing --no-install-recommends'"
alias stable-build-deps="sudo mk-build-deps -irt 'apt-get -o Debug::pkgProblemResolver=yes -t stable --no-install-recommends'"
alias test-package-plan="schroot -d $HOME -- /bin/sh -c \"cabal --no-require-sandbox update && cd src/package-plan && perl test-packages.pl\""
alias wnpomodoro="mplayer ~/lib/annex/doc/sounds/*pomodoro.mp3"
alias ghc8-sbuild="sbuild --extra-repository='deb http://httpredir.debian.org/debian experimental main' --build-dep-resolver=aspcud --add-depends=\"ghc (>= 8)\""
alias dq="dgit --quilt=gbp"
alias qsbuild="sbuild --no-apt-update --no-apt-distupgrade --no-run-piuparts --no-run-lintian"
alias qqsbuild="DEB_BUILD_OPTIONS=nocheck sbuild --no-apt-update --no-apt-distupgrade --no-run-piuparts --no-run-lintian --no-run-autopkgtest"
alias b="bts --mbox show"
alias test-reproducible="reprotest auto . -- schroot sid"
alias dinstall="curl https://ftp-master.debian.org/dinstall.status;echo -n 'Now: ';date -u"
alias disable-propellor="sudo rm /etc/cron.d/propellor"
alias ls="ls --literal"

# copy files into persistent part of develacc chroot, ensuring that we
# don't give spw write access to packages
# THIS IS NOT SAFE there is a race.  file could be modified before chown.
# instead, should be copying into /root
copy-to-develacc () {
    sudo cp -RL "$@" /home/spw/tmp/
    for f in /home/spw/tmp/*; do
        if ! [ "${f##*.}" = "deb" ]; then
            sudo chown spw:spw "$f"
        fi
    done
}

# idea from
# https://coderwall.com/p/aohfrg/smux-ssh-with-auto-reconnect-tmux-a-mosh-replacement
smux () {
    autossh -M 0 -t "$@" "tmux attach-session"
}

# This alias is more reliable than calling `server-start' in my Emacs
# init file.  Previously, I was seeing Emacs fail to start with "Error
# reading from stdin."  See <http://emacs.stackexchange.com/a/12789>

# `switch-to-buffer' means that there is some chance the new window
# will show a buffer I want to see (tip from the frames-only-mode
# README)
alias emacscd="emacsclient -c -a '' -n -e '(switch-to-buffer nil)'"

dak-rdeps () {
    ssh mirror.ftp-master.debian.org "dak rm -Rn $@"
}
madison () {
    ssh mirror.ftp-master.debian.org "dak ls $@"
}

build-for-upload () {
    dgit=""
    sbuild=""
    for key in "$@"; do
        case $key in
            --gbp|--dpm|--quilt=*)
                dgit="$dgit $key"
                shift
                ;;
            *)
                sbuild="$sbuild $key"
                shift
                ;;
        esac
    done
    if [[ $(pwd) =~ "src/DHG_packages/p" ]]; then
        sbuild $sbuild \
             --no-run-lintian --run-piuparts --run-autopkgtest
    else
        eval dgit $dgit sbuild $sbuild \
             --no-run-lintian --run-piuparts --run-autopkgtest
    fi
    lintian
}

# based on gregor hermann's dh-make-perl-dev he posted on bugs.d.o
dh-make-elpa-dev () {
    PERL5LIB=~/src/dh-make-elpa/lib/ ~/src/dh-make-elpa/dh-make-elpa "$@"
}

# cd to top of git checkout
alias cg='cd $(git rev-parse --show-toplevel)'

# try to stop dpkg-buildpackage from invoking gpg2 and thereby messing
# with ~/.gnupg
alias dpkg-buildpackage="dpkg-buildpackage -pgpg"

# add a project to projectile's known projects
projectile () {
    local dir="$(pwd)"
    chronic emacsclient -c -n -e "(projectile-switch-project-by-name \"$dir\")"
}

# clone with git and open in Emacs
clone () {
    cd $HOME/src
    git clone $1
    name=$(basename $1 | cut -d: -f2)
    cd $name
    mr register
    projectile
}

# tmux is smart and it detects a changed SSH_AUTH_SOCK and any newly
# created shells use that.  But not old ones: this should pull the
# newly detected value into the old sehll.

# check tmux is running first by seeing if we're inside it
if ! [ "$TMUX" = "" ]; then
    alias fixsshagent="eval $(tmux show-environment | grep '^SSH_AUTH_SOCK')"
fi

# append a stream to mpd's playlist, and play it
mpc_play_stream () {
    mpc stop
    mpc add $1
    mpc play $(mpc playlist | wc -l)
}

# BBC radio stream URIs:
# http://www.suppertime.co.uk/blogmywiki/2015/04/updated-list-of-bbc-network-radio-urls/
alias radio4="mpc_play_stream http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p"
alias worldservice="mpc_play_stream http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk"

# Manipulate Policy bugs.  (from Russ Allbery)
bts-policy () {
    bts user debian-policy@packages.debian.org , source debian-policy , "$@"
}

dgit-view () {
    if [ $# = 0 ]; then
        1="--gbp"
    fi
    dgit "$@" --dgit-view-save=unquilted quilt-fixup
    git checkout unquilted
}

dhtunpack () {
    exists=/tmp/cabal/$1*
    if [ -e $exists ]; then
        cd $exists
    else
        mkdir -p /tmp/cabal
        cd /tmp/cabal
        cabal unpack $1
        cd $1*
        dir=$(pwd)
        dir=$(basename $dir)
        package=${dir%-*}
        version=${dir##*-}
        mkdir -p ~/src/package-plan/patches/$package/$version
        ln -s ~/src/package-plan/patches/$package/$version patches
        if [ -e ~/src/package-plan/additional-cabals/$package-$version.cabal ]; then
            cp ~/src/package-plan/additional-cabals/$package-$version.cabal $package.cabal
        fi
    fi
}

# --- load zsh features

# Change word boundary characters. Nabbed from
# http://zshwiki.org/KeyBindings.

# by default: export WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>'
# we take out the slash, period, angle brackets, dash here.
export WORDCHARS='*?_-[]~=&;!#$%^(){}'

# Follow GNU LS_COLORS for completion menus
zmodload -i zsh/complist
#eval $(dircolors -b /home/tom/.dir_colors)
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*:*:kill:*' list-colors '=%*=01;31'

# Load the completion system
autoload -U compinit; compinit

# Very powerful version of mv implemented in zsh. The main feature I
# know of it that seperates it from the standard mv is that it saves you
# time by being able to use patterns which are expanded into positional
# parameters. So:
#
# slarti@pohl % zmv (*)foo ${1}bar
#
# On a series of files like onefoo, twofoo, threefoo, fivefoo would be
# renamed to onebar twobar threebar fourbar.
#
# Although that's nifty enough, I suspect there are other features I
# don't know about yet...
#
# Read $fpath/zmv for some more basic examples of usage, and also use
# run-help on it :)
autoload -U zmv

# automatically escape URLs
autoload -U url-quote-magic
zle -N self-insert url-quote-magic

# Incremental completion of a word. After starting this, a list of
# completion choices can be shown after every character you type, which
# can deleted with ^H or delete. Return will accept the current
# completion. Hit tab for normal completion, ^G to get back where you
# came from and ^D to list matches.
autoload -U incremental-complete-word
zle -N incremental-complete-word
bindkey "^Xi" incremental-complete-word

# This function allows you type a file pattern, and see the results of
# the expansion at each step.  When you hit return, they will be
# inserted into the command line.
autoload -U insert-files
zle -N insert-files
bindkey "^Xf" insert-files

# This set of functions implements a sort of magic history searching.
# After predict-on, typing characters causes the editor to look backward
# in the history for the first line beginning with what you have typed so
# far.  After predict-off, editing returns to normal for the line found.
# In fact, you often don't even need to use predict-off, because if the
# line doesn't match something in the history, adding a key performs
# standard completion - though editing in the middle is liable to delete
# the rest of the line.
autoload -U predict-on
zle -N predict-on
zle -N predict-off
bindkey "^X^Z" predict-on
bindkey "^Z" predict-off

# _gnu_generic is a completion widget that parses the --help output of
# commands for options. df and feh work fine with it, however options
# are not described.
compdef _gnu_generic feh df

compdef _pkglist ecd emetadataviewer
compdef _useflaglist explainuseflag
compdef _category list_cat

compdef _nothing etc-update dispatch-conf fixpackages

# History things
HISTFILE=$HOME/.zshist
SAVEHIST=10000
HISTSIZE=10000
TMPPREFIX=$HOME/tmp

# Key bindings

# You can use:
# % autoload -U zkbd
# % zkbd
# to discover your keys.

bindkey -e

# C-x C-k to kill region
bindkey "^X^K" kill-region

# Up, down left, right.
# echotc is part of the zsh/termcap module. It outputs the termcap value
# corresponding to the capability it was given as an argument. man zshmodules.
zmodload -i zsh/termcap
bindkey "$(echotc kl)" backward-char
bindkey "$(echotc kr)" forward-char
bindkey "$(echotc ku)" up-line-or-history
bindkey "$(echotc kd)" down-line-or-history

bindkey '\e[3~' delete-char # Delete

if [[ "$TERM" == "rxvt-unicode" || "$TERM" == "screen" ]]; then
    bindkey '\e[7~' beginning-of-line # Home
    bindkey '\e[8~' end-of-line # End
elif [[ "$TERM" == "linux" ]]; then
    bindkey '\e[1~' beginning-of-line # Home
    bindkey '\e[4~' end-of-line # End
else # At least xterm; probably other terms too
    bindkey '\e[H~' beginning-of-line # Home
    bindkey '\e[F~' end-of-line # End
fi

bindkey '\e[5~' up-history # PageUp
bindkey '\e[6~' down-history # PageDown

# --- completion

# Pretty menu!
zstyle ':completion:*' menu select=1

# Completion options
zstyle ':completion:*' completer _complete _prefix
zstyle ':completion::prefix-1:*' completer _complete
zstyle ':completion:incremental:*' completer _complete _correct
zstyle ':completion:predict:*' completer _complete

# Completion caching
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST

# Expand partial paths
zstyle ':completion:*' expand 'yes'
zstyle ':completion:*' squeeze-slashes 'yes'

# Include non-hidden directories in globbed file completions
# for certain commands
zstyle ':completion::complete:*' '\'

# Use menuselection for pid completion
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always

#  tag-order 'globbed-files directories' all-files
zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)'

# Don't complete backup files as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'

# Don't complete non-.tex LaTeX files with mg
zstyle ':completion:*:*:mg:*:*files' ignored-patterns '*?.aux' '*?.log' '*?.pdf' '*?.toc' '*?.bak' '*?.fdb_latexmk'

# Separate matches into groups
zstyle ':completion:*:matches' group 'yes'

# With commands like rm, it's annoying if you keep getting offered the same
# file multiple times. This fixes it. Also good for cp, et cetera..
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:cp:*' ignore-line yes

# Describe each match group.
zstyle ':completion:*:descriptions' format "%B---- %d%b"

# Messages/warnings format
zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b'

# Describe options in full
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'

# Simulate spider's old abbrev-expand 3.0.5 patch
#zstyle ':completion:*:history-words' stop verbose
#zstyle ':completion:*:history-words' remove-all-dups yes
#zstyle ':completion:*:history-words' list false

# From the zshwiki. Hide CVS files/directores from being completed.
zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'

# Also from the wiki. Hide uninteresting users from completion.
zstyle ':completion:*:*:*:users' ignored-patterns \
    adm apache bin daemon games gdm halt ident junkbust lp mail mailnull \
    named news nfsnobody nobody nscd ntp operator pcap postgres radvd \
    rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs backup  bind  \
    dictd  gnats  identd  irc  man  messagebus  postfix  proxy  sys \
    www-data alias amavis at clamav cmd5checkpw cron cyrus dhcp dnscache \
    dnslog foldingathome guest haldaemon jabber ldap mailman mpd mysql \
    nut p2p portage postmaster qmaild qmaill qmailp qmailq qmailr qmails \
    smmsp tinydns vpopmail wasabi zope

# Pull hosts from $HOME/.ssh/known_hosts, also from the wiki
# local _myhosts
_myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )
zstyle ':completion:*' hosts $_myhosts

# Approximate completion. From the wiki.
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric

# --- zsh options

setopt                   \
    NO_all_export        \
    always_last_prompt   \
    always_to_end        \
    append_history       \
    share_history        \
    auto_cd              \
    auto_list            \
    auto_menu            \
    auto_name_dirs       \
    auto_param_keys      \
    auto_param_slash     \
    auto_pushd           \
    auto_remove_slash    \
    NO_auto_resume       \
    bad_pattern          \
    bang_hist            \
    NO_beep              \
    brace_ccl            \
    NO_bsd_echo          \
    NO_cdable_vars       \
    NO_chase_links       \
    clobber              \
    complete_aliases     \
    complete_in_word     \
    NO_correct           \
    NO_correct_all       \
    csh_junkie_history   \
    NO_csh_junkie_loops  \
    NO_csh_junkie_quotes \
    NO_csh_null_glob     \
    equals               \
    NO_extended_glob     \
    extended_history     \
    function_argzero     \
    glob                 \
    NO_glob_assign       \
    glob_complete        \
    NO_glob_dots         \
    NO_glob_subst        \
    NO_hash_cmds         \
    NO_hash_dirs         \
    hash_list_all        \
    hist_allow_clobber   \
    hist_beep            \
    hist_ignore_dups     \
    hist_ignore_space    \
    NO_hist_no_store     \
    hist_verify          \
    NO_hup               \
    NO_ignore_braces     \
    NO_ignore_eof        \
    interactive_comments \
    inc_append_history   \
    NO_list_ambiguous    \
    NO_list_beep         \
    list_types           \
    long_list_jobs       \
    magic_equal_subst    \
    NO_mail_warning      \
    NO_mark_dirs         \
    NO_menu_complete     \
    multios              \
    nomatch              \
    notify               \
    noflowcontrol        \
    NO_null_glob         \
    numeric_glob_sort    \
    NO_overstrike        \
    path_dirs            \
    posix_builtins       \
    NO_print_exit_value  \
    NO_prompt_cr         \
    prompt_subst         \
    pushd_ignore_dups    \
    NO_pushd_minus       \
    pushd_silent         \
    pushd_to_home        \
    rc_expand_param      \
    NO_rc_quotes         \
    NO_rm_star_silent    \
    NO_sh_file_expansion \
    sh_option_letters    \
    short_loops          \
    NO_sh_word_split     \
    NO_single_line_zle   \
    NO_sun_keyboard_hack \
    NO_verbose           \
    zle

# --- compatibility

# # allow zenity to be called from cron

# # per http://promberger.info/linux/2009/01/02/running-x-apps-like-zenity-from-crontab-solving-cannot-open-display-problem/
# if which pgrep && pgrep Xorg >/dev/null; then
#     xhost local:${USER} > /dev/null 2> /dev/null
# fi
# # per http://superuser.com/questions/111771/using-either-notify-send-or-zenity-in-cron
# echo $DBUS_SESSION_BUS_ADDRESS > ~/.tmp-dbus-addr

# Make BiBTeX and Org play nice together due to security change in
# TeXLive 2010.  See
# http://lists.gnu.org/archive/html/emacs-orgmode/2011-04/msg00845.html

export BIBINPUTS="$HOME/doc:$HOME/doc/papers:$BIBINPUTS"

# If we're on a weak terminal (probably non-interactive) such as
# TRAMP, kill off a bunch of the cool stuff we just set-up.
                
if [[ "$TERM" == "dumb" ]]; then
    unsetopt zle
    unsetopt prompt_cr
    unsetopt prompt_subst
    unfunction precmd
    unfunction preexec
    export TERMTYPE=""
    export NOCOLOR="true"
    PS1='$ '
fi

if [[ -n ${INSIDE_EMACS} ]]; then
    unsetopt zle
fi