summaryrefslogtreecommitdiff
path: root/tw/home/files/zshrc
blob: 3bde2704f3d3e5f24ec5bd5b4d2e2c7e251c03c3 (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
# Zsh configuration  -*- sh -*-

# Load functions from Guix profile, where packages like
# zsh-completions are installed.
if [ -d ~/.guix-home/profile/share/zsh/site-functions ]; then
  fpath+=(~/.guix-home/profile/share/zsh/site-functions)
fi

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 Guix's home environment service.
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 rot13='caesar 13'
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"

# Git aliases
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gd='git diff'
alias gds='git diff --staged'
alias gf='git fetch'
alias gfa='git fetch --all --prune --tags'
alias gk='git checkout'
alias gkb='git checkout -b'
alias gg='git glog'
alias gl='git pull'
alias gp='git push'
alias gr='git rebase'
alias gri='git rebase --interactive'
alias gs='git status'

if recsel --version 2>/dev/null | grep -qFx 'recsel (GNU recutils) 1.8'; then
  # 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
fi

## 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