-
Notifications
You must be signed in to change notification settings - Fork 4
/
.zshrc
executable file
·276 lines (227 loc) · 9.26 KB
/
.zshrc
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
# Source: https://github.com/PonderingGrower/dotfiles
# allow of sourcing from ~/.zfunctions
fpath=(
~/.zfunctions
"${fpath[@]}"
)
[[ -f ~/.secret ]] && source ~/.secret
#[[ -f ~/.ssh-agent.env ]] && source ~/.ssh-agent.env
#[[ -f ~/.gnupg/gpg-agent-info-lilim ]] && source ~/.gnupg/gpg-agent-info-lilim
#export GPG_AGENT_INFO
# Preamble {{{
autoload colors # enable colors
autoload -U compinit # enable auto completion
autoload -U promptinit # advanced prompts support
autoload -U do-reboot # cloud reboot scripts
prompt off # disable system settings
colors # initialize
compinit # longest wait
promptinit
zmodload zsh/parameter # load to use $history[$HISTCMD] variable
# }}}
# Imports {{{
for file in ~/.zsh.conf.d/*; do
source "$file"
done
# }}}
# Display settings {{{
case $HOST in # change prompt depending on host
caspair*|lilim*)
COLOR="green" ;;
melchior*)
COLOR="cyan" ;;
leliel*)
COLOR="magenta" ;;
arael*)
COLOR="red" ;;
*)
COLOR="yellow" ;;
esac
export PURE_PROMPT_SYMBOL="%B%{$fg[$COLOR]%} >%{$reset_color%}%b"
prompt pure
# define colors for less to get colored manpages
# or wget nion.modprobe.de/mostlike.txt && mkdir ~/.terminfo && cp mostlike.txt ~/.terminfo && tic ~/.terminfo/mostlike.txt
export LESS_TERMCAP_mb=$'\E[0;34m' # begin blinking
export LESS_TERMCAP_md=$'\E[0;34m' # begin bold
export LESS_TERMCAP_us=$'\E[01;34m' # begin underline
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[01;47;34m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export GROFF_NO_SGR=1
# fix for inputting gpg pass in console
export GPG_TTY=$(tty)
# improve output format of 'time'
export TIMEFMT=$'\nreal\t%*Es\nuser\t%*Us\nsys\t%*Ss'
# }}}
# Exports {{{
if _exists nvim; then
EDITOR="nvim"
alias vim='nvim'
else
EDITOR="vim"
fi
export PATH="${PATH}:${HOME}/go/bin:${HOME}/bin"
export EDITOR
export VISION="$EDITOR"
export PAGER="less"
export BROWSER="thunar"
export TERMINAL="urxvtc"
export MANPAGER="/bin/sh -c \"col -b | nvim -c 'set ft=man nomod nolist' -\""
export FZF_DEFAULT_OPTS="--extended-exact --height=100% --layout=default"
export SOPS_GPG_KEYSERVER="https://keys.openpgp.org"
export ANSIBLE_REMOTE_USER="admin"
export RESTIC_REPOSITORY="sftp:[email protected]:/home/$(hostname)"
export RESTIC_PASSWORD_FILE='/home/jakubgs/.usb_backup_pass'
export PASSWORD_STORE_DIR="$HOME/work/infra-pass"
export DIRENV_LOG_FORMAT=''
# Magically link PYTHONPATH to the ZSH array pythonpath
typeset -T PYTHONPATH pythonpath
# Hacky way to provide python packages to Ansible for local tasks.
if [[ -d /etc/profiles/per-user ]]; then
for SITE_PACKAGES in /etc/profiles/per-user/$USER/lib/python3.*/site-packages; do
export PYTHONPATH="${PYTHONPATH}:${SITE_PACKAGES}"
done
fi
# Remove duplicates
typeset -U pythonpath
export PYTHONPATH
# }}}
# General settings {{{
export DIRSTACKSIZE=1000 # number of folder paths to remember
export HISTSIZE=4000 # number of lines kept in history
export SAVEHIST=4000 # number of lines saved in the history after logout
export HISTFILE="$HOME/.zhistory" # location of history
export HISTCONTROL=ignoreboth # ignore commands starting with space, dedupe
setopt INC_APPEND_HISTORY # append command to history file once executed
setopt SHARE_HISTORY # for sharing history between zsh proce'ses
setopt HIST_IGNORE_ALL_DUPS # Ignore duplicates in history
setopt HIST_IGNORE_SPACE # don't record entry if a space is preceeding it
setopt NO_CASE_GLOB # case insensitive globbing
setopt NOFLOWCONTROL # Nobody needs flow control anymore. Troublesome feature.
setopt AUTO_PUSHD # auto directory pushd that you can get dirs list by cd -[tab]
setopt AUTOCD # change directory without using cd command
setopt EXTENDEDGLOB # Regular expressions in files
setopt COMPLETE_IN_WORD # allow tab completion in the middle of a word
setopt AUTO_RESUME # Resume jobs after typing it's name
setopt CHECK_JOBS # Dont quit console if processes are running
setopt INTERACTIVE_COMMENTS # Allow for comments in interactive command line
setopt completealiases
# }}}
# Completion {{{
# history of changing directories (cd)
setopt AUTO_PUSHD # pushes the old directory onto the stack
setopt PUSHD_MINUS # exchange the meanings of '+' and '-'
setopt CDABLE_VARS # expand the expression (allows 'cd -2/tmp')
zstyle ':completion:*:directory-stack' list-colors '=(#b) #([0-9]#)*( *)==95=38;5;12'
# process autocompletion
zstyle ':completion:*:killall:*' command 'ps -u $USER -o cmd'
# hostname expansion from known_hosts
zstyle -e ':completion::*:*:*:hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null|sort -u)"}%%[# ]*}//,/ })'
# :completion:<func>:<completer>:<command>:<argument>:<tag>
# Expansion options
zstyle ':completion:*' completer _complete _prefix _expand _approximate
zstyle ':completion::prefix-1:*' completer _complete
zstyle ':completion:incremental:*' completer _complete _correct
zstyle ':completion:predict:*' completer _complete
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# Separate matches into groups
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:messages' format '%d'
# Messages/warnings format
zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
# set format for warnings
zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
# Describe options in full
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
# colorful listings
zmodload -i zsh/complist
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' special-dirs true
# activate color-completion(!)
#zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# Nicer copletion
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
# tab completion for PID
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*' force-list always
# on processes completion complete all user processes
zstyle ':completion:*:processes' command 'ps -au$USER'
# cache
zstyle ':completion:*' use-cache 1
zstyle ':completion:*' cache-path ~/.zsh/cache
zstyle ':completion:*' accept-exact '*(N)'
# format on completion
zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
# insert all expansions for expand completer
zstyle ':completion:*:expand:*' tag-order all-expansions
zstyle ':completion:*:history-words' list false
# activate menu
zstyle ':completion:*:history-words' menu yes
# ignore duplicate entries
zstyle ':completion:*:history-words' remove-all-dups yes
zstyle ':completion:*:history-words' stop yes
# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# offer indexes before parameters in subscripts
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# provide verbose completion information
zstyle ':completion:*' verbose true
# define files to ignore for zcompile
zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)'
zstyle ':completion:correct:' prompt 'correct to: %e'
# Ignore completion functions for commands you don't have:
zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
# arrow driven menu
zstyle ':completion:*' menu select
# How to handle different filetypes
zstyle ':mime:.jpg:' handler feh -x %s
# cd not select parent dir
# zstyle ':completion:*:cd:*' ignore-parents parent pwd
# }}}
# Key Bindings {{{
typeset -A key
# Vim mode
bindkey -v
# 10ms for key sequences
KEYTIMEOUT=1
# Use ESC to edit the current command line:
autoload -U edit-command-line
zle -N edit-command-line
bindkey "^E" edit-command-line
# fix backspace in append mode
bindkey "^?" backward-delete-char
key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
key[Insert]=${terminfo[kich1]}
key[Delete]=${terminfo[kdch1]}
bindkey "^[." insert-last-word # Alt + .
bindkey -s '\e.' insert-last-word # Alt + .
bindkey "^L" clear-screen # ctrl + l
bindkey "^Q" kill-word # ctrl + q
bindkey "^W" backward-kill-word # ctrl + w
bindkey "^R" history-incremental-pattern-search-backward # ctrl + r
bindkey "\e[2~" quoted-insert
# }}}
# FZF {{{
if [ -n "${commands[fzf-share]}" ]; then
# This is available on NixOS
source $(fzf-share)/completion.zsh
source $(fzf-share)/key-bindings.zsh
elif [[ -f ~/.fzf.zsh ]]; then
source ~/.fzf.zsh
fi
bindkey '^F' fzf-cd-widget
# }}}
# Direnv {{{
# Sources configs in infra repos.
if [ -n "${commands[direnv]}" ]; then
eval "$(direnv hook zsh)"
fi
# }}}