summaryrefslogtreecommitdiff
path: root/zshrc
blob: 607fec77439254d689b8ed185ce5a0bd0606ea8e (about) (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
zmodload zsh/attr
zmodload -F zsh/cap b:cap
zmodload zsh/datetime
zmodload zsh/system
zmodload zsh/terminfo

setopt extendedglob interactivecomments

# So we don't have to call tput.
autoload -Uz colors
colors

# GPG-agent setup
GPG_TTY=$(tty) && export GPG_TTY

## Key bindings
# vi-like key mappings
bindkey -v

bindkey '^[[A' up-line-or-history               # up
bindkey '^[[B' down-line-or-history             # down

bindkey '^[[1;5A' up-line-or-history            # C-up
bindkey '^[[1;5B' down-line-or-history          # C-down
bindkey '^[[1;5C' vi-forward-word               # C-right
bindkey '^[[1;5D' vi-backward-word              # C-left

bindkey '^[[H' vi-beginning-of-line             # home
bindkey '^[[F' vi-end-of-line                   # end

## History setup
# HISTSIZE should be set through ~/.pam_environment.
HISTSIZE=10000000
HISTFILE=${XDG_DATA_HOME:-$HOME/.local/share}/zsh/history
SAVEHIST=$HISTSIZE
setopt appendhistory sharehistory incappendhistory extendedhistory histverify histreduceblanks

## Completion setup

# don't need to run 'hash -r' after commands are added/removed
zstyle ':completion:*' rehash true

# enable completion list colours
# http://linuxshellaccount.blogspot.com/2008/12/color-completion-using-zsh-modules-on.html
zstyle ':completion:*:*:*:*:hosts' list-colors "=*=${fg[blue]}"
zstyle ':completion:*:*:*:*:users' list-colors "=*=${fg[green]}=${fg[red]}"

# formatting and messages
# http://www.masterzen.fr/2009/04/19/in-love-with-zsh-part-one/
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format "${fg[green]}%B--- %d%b"
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format "${fg[red]}%BNo matches for:%b %d"
zstyle ':completion:*:corrections' format "${fg[yellow]}%B%d (%e char)%b"

# https://stackoverflow.com/a/24237590
#zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

# (mostly) from compinstall
zstyle ':completion:*' auto-description '(param: %d)'
zstyle ':completion:*' completer _expand _complete _ignored _approximate
zstyle ':completion:*' expand prefix suffix
zstyle ':completion:*' file-sort name
zstyle ':completion:*' group-name ''
zstyle ':completion:*' ignore-parents parent pwd directory
zstyle ':completion:*' insert-unambiguous false
eval "$(dircolors)"    # set LS_COLORS
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' list-suffixes true
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*'
zstyle ':completion:*' max-errors 3
zstyle ':completion:*' original true
zstyle ':completion:*' verbose true

autoload -Uz compinit
if mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}/zsh"; then
  compinit -d "${XDG_CACHE_HOME:-$HOME/.cache}/zsh/zcompdump-$ZSH_VERSION"
else
  # Don't use dump file.
  compinit -D
fi

## Aliases
# Use ASYNC_EDITOR so I can continue using the shell while the editor
# remains open in a separate window.
alias em="$ASYNC_EDITOR"
alias se='sudo -e'
alias ls='\ls --color=auto -h'
alias la='\ls --color=auto -hA'
alias grep='\grep --color=auto'
alias diff='\diff -s --color=auto'
alias cdiff='\diff -s --color=always'
alias ipy='ipython3 --autoindent --automagic --pprint --no-banner --no-confirm-exit --term-title --autocall=1 --colors=Neutral'
alias ispy="isympy -qI -- $(whence ipy | cut -d ' ' -f 2-)"
alias rot13='caesar 13'
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gd='git diff'
alias gf='git fetch'
alias gk='git checkout'
alias gg='git glog'
alias gl='git pull'
alias gp='git push'
alias gs='git status'
alias sc='systemctl'
alias scu='systemctl --user'
alias sclog='sudo journalctl --system -xfu'
alias sculog='journalctl --user -xfu'
alias wget='\wget --hsts-file="${XDG_CACHE_HOME:-$HOME/.cache}/wget-hsts"'
alias aurora="REQUESTS_CA_BUNDLE=${XDG_CONFIG_HOME:-$HOME/.config}/cern-ca-bundle.crt \aurora"
alias aurora_admin="REQUESTS_CA_BUNDLE=${XDG_CONFIG_HOME:-$HOME/.config}/cern-ca-bundle.crt \aurora_admin"

# Recutils 1.8 has a bug when TMPDIR is on a different mount point, see
# https://lists.gnu.org/archive/html/bug-recutils/2019-08/msg00001.html.
for _recutil in rec2csv recdel recfix recfmt recinf recins recsel recset; do
  alias "$_recutil=TMPDIR=. $_recutil"
done
unset _recutil

# Arch
_cmds=('in' -S sinfo -Si linfo -Qi grp -Sg own -Qo lsf -Ql lsr -Sl lst -Qdt lstt -Qdtt)
_sudo_cmds=(upg -Syu ins -U ind '-S --asdeps' dep '-D --asdeps' re -R rem -Rns rec -Rnsc
            ssch -Ss lsch -Qs upd -Sy rmt '-Rs $(paclst -q)' rmtt '-Rs $(paclstt -q)'
            remt '-Rns $(paclst -q)' remtt '-Rns $(paclstt -q)')
for _cmd _args in ${(kv)_cmds}; do
  alias "a$_cmd=pikaur $_args"
  alias "pac$_cmd=pacman $_args"
done
for _cmd _args in ${(kv)_sudo_cmds}; do
  alias "a$_cmd=pikaur $_args"
  alias "pac$_cmd=sudo pacman $_args"
done
unset _cmd _args _cmds _sudo_cmds

ppscm () {
  guile -c "(use-modules (ice-9 pretty-print)) (with-input-from-file \"$1\" (compose pretty-print read))" |
    source-highlight -s scheme -f esc | less -RSM
}

# Less: use pretty colours for bold/underline/... -- mostly in `man'
# https://wiki.archlinux.org/index.php/Color_output_in_console#less
# See terminfo(5) for tput code names.
# blink -> italic white-on-red
export LESS_TERMCAP_mb=$'\e'"[${color[standout]}m${fg[white]}${bg[red]}"
# bold -> bold blue
export LESS_TERMCAP_md="${fg_bold[blue]}"
# reverse video -> reverse, bright yellow background
export LESS_TERMCAP_so=$'\e'"[${color[reverse]}m${fg_bold[yellow]}"
# underline -> italic green
export LESS_TERMCAP_us=$'\e'"[${color[standout]}m${fg[green]}"
# reset bold/blink, reverse video, underline
export LESS_TERMCAP_me="$reset_color" LESS_TERMCAP_se="$reset_color" LESS_TERMCAP_ue="$reset_color"

## Plugins
_load_plugin () {
  local _try_path
  for _try_path in {/usr,"$GUIX_ENVIRONMENT","$HOME/.guix-profile","$HOME/.guix-home/profile"}"/share/zsh/plugins/$1/$1"{.plugin,}.zsh; do
    [ -r "$_try_path" ] && . "$_try_path" && return 0
  done
  return 1
}

if _load_plugin zsh-autosuggestions; then
  bindkey '^ ' autosuggest-accept
  bindkey -M vicmd '^I' autosuggest-accept
  ZSH_AUTOSUGGEST_STRATEGY=(history completion)
  ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
  ZSH_AUTOSUGGEST_USE_ASYNC=1
  ZSH_AUTOSUGGEST_MANUAL_REBIND=1
fi

if _load_plugin zsh-history-substring-search; then
  bindkey '^[[A' history-substring-search-up
  bindkey '^[[B' history-substring-search-down
  bindkey -M emacs '^P' history-substring-search-up
  bindkey -M emacs '^N' history-substring-search-down
  bindkey -M vicmd 'k' history-substring-search-up
  bindkey -M vicmd 'j' history-substring-search-down
fi

_load_plugin zsh-autopair

_load_plugin fast-syntax-highlighting ||
  _load_plugin zsh-syntax-highlighting

unset _load_plugin