-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
304 lines (269 loc) · 8.64 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
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
#!/bin/zsh
# vim: filetype=zsh tabstop=8 shiftwidth=4 expandtab
# Purpose of this file, .zshrc: set up aliases, functions (although
# these are defined in $fpath), options, key bindings, etc.
# Interactive stuff.
zstyle :compinstall filename "$HOME/.zshrc"
zstyle ':completion:*' completer _complete _approximate
if type brew &>/dev/null
then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
fi
autoload -Uz compinit
compinit
#### ZSH INTERACTIVE VARIABLES
HISTFILE=~/.histfile
HISTSIZE=100000
SAVEHIST=100000
WORDCHARS=${WORDCHARS:s#/##:s/.//:s/-//:s/_//:s/*//:s/=//:s/&//}
#### ALIASES
# standard aliases
if whence -p vim &> /dev/null
then
alias vim='vim -X'
alias vi='vim'
fi
if whence -p rename &> /dev/null
then
alias rename='rename --verbose'
fi
LS_OPTIONS='--color=auto --classify --human-readable'
alias aoeu='echo us;setxkbmap us'
alias asdf='echo dvorak;setxkbmap dvorak'
alias bc='bc --mathlib'
alias chcon='chcon --verbose'
alias chgrp='chgrp --changes'
alias chmod='chmod --changes'
alias chown='chown --changes'
alias cp='nocorrect cp --verbose --interactive'
alias df='df --si --human-readable --print-type'
alias dscverify='dscverify --keyring ~/.gnupg/pubring.gpg'
alias du='du --human-readable'
alias e='emacsclient --tty'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias free='free --total --human --wide'
alias gcal='gcal --starting-day=Monday'
alias grep='grep --color=auto'
alias ip='ip -color=auto'
alias l="ls $LS_OPTIONS --almost-all"
alias ll="ls $LS_OPTIONS --format=long --all"
alias ln='nocorrect ln --verbose --interactive'
alias ls="ls $LS_OPTIONS"
alias mdstat='cat /proc/mdstat'
alias mkdir='nocorrect mkdir --verbose'
alias mv='nocorrect mv --verbose --interactive'
alias pwed="vim $PWGPG"
alias pwview="view $PWGPG"
alias rm='nocorrect rm --verbose --interactive'
alias rmdir='nocorrect rmdir --verbose'
# OS-specific aliases
case $(uname -a) in
*Darwin*)
LS_OPTIONS='-FGh'
alias chgrp='chgrp -v'
alias chmod='chmod -v'
alias chown='chown -v'
alias cp='nocorrect cp -iv'
alias df='df -h'
alias du='du -h'
alias l="ls $LS_OPTIONS -CFA"
alias ll="ls $LS_OPTIONS -la"
alias ln='nocorrect ln -iv'
alias ls="ls $LS_OPTIONS"
alias mkdir='nocorrect mkdir -v'
alias mv='nocorrect mv -iv'
alias rm='nocorrect rm -iv'
unalias chcon
unalias rmdir
;;
*FreeBSD*)
LS_OPTIONS='-FGh'
alias chflags='chflags -v'
alias chgrp='chgrp -v'
alias chmod='chmod -v'
alias chown='chown -v'
alias cp='nocorrect cp -iv'
alias df='df -h'
alias du='du -h'
alias l="ls $LS_OPTIONS -CFA"
alias ll="ls $LS_OPTIONS -la"
alias ln='nocorrect ln -ivw'
alias ls="ls $LS_OPTIONS"
alias mkdir='nocorrect mkdir -v'
alias mv='nocorrect mv -iv'
alias rm='nocorrect rm -iv'
alias rmdir='nocorrect rmdir -v'
alias spm='sudo portmaster'
;;
*SunOS*)
LS_OPTIONS='-Fh'
alias cp='nocorrect cp -i'
alias ll="ls $LS_OPTIONS -la"
alias l="ls $LS_OPTIONS -CFA"
alias ls="ls $LS_OPTIONS"
alias mkdir='nocorrect mkdir'
alias mv='nocorrect mv -i'
alias rm='nocorrect rm -i'
unalias chgrp
unalias chmod
unalias chown
unalias chcon
unalias ln
unalias mdstat
unalias rmdir
;;
*Cygwin*)
alias npp='notepad++'
;;
esac
#### ZSH INTERACTIVE STUFF
bindkey -e
autoload edit-command-line
zle -N edit-command-line
bindkey '^xe' edit-command-line
# From <http://zshwiki.org/home/zle/bindkeys>:
# create a zkbd compatible hash;
# to add other keys to this hash, see man 5 terminfo
typeset -g -A key
key[Home]="$terminfo[khome]"
key[End]="$terminfo[kend]"
key[Insert]="$terminfo[kich1]"
key[Backspace]="$terminfo[kbs]"
key[Delete]="$terminfo[kdch1]"
key[Up]="$terminfo[kcuu1]"
key[Down]="$terminfo[kcud1]"
key[Left]="$terminfo[kcub1]"
key[Right]="$terminfo[kcuf1]"
key[PageUp]="$terminfo[kpp]"
key[PageDown]="$terminfo[knp]"
# set up key accordingly
[[ -n "$key[Home]" ]] && bindkey -- "$key[Home]" beginning-of-line
[[ -n "$key[End]" ]] && bindkey -- "$key[End]" end-of-line
[[ -n "$key[Insert]" ]] && bindkey -- "$key[Insert]" overwrite-mode
[[ -n "$key[Backspace]" ]] && bindkey -- "$key[Backspace]" backward-delete-char
[[ -n "$key[Delete]" ]] && bindkey -- "$key[Delete]" delete-char
[[ -n "$key[Up]" ]] && bindkey -- "$key[Up]" up-line-or-history
[[ -n "$key[Down]" ]] && bindkey -- "$key[Down]" down-line-or-history
[[ -n "$key[Left]" ]] && bindkey -- "$key[Left]" backward-char
[[ -n "$key[Right]" ]] && bindkey -- "$key[Right]" forward-char
# Finally, make sure that the terminal is in application mode when zle
# is active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init () {
echoti smkx
}
function zle-line-finish () {
echoti rmkx
}
zle -N zle-line-init
zle -N zle-line-finish
fi
# disable flow control. necessary for my ^s binding.
stty -ixon
# make less more friendly for non-text input files, see lesspipe(1)
if [[ -x /usr/bin/lesspipe ]] # Linux lesspipe
then
eval "$(SHELL=/bin/sh lesspipe)"
elif [[ -x /usr/local/bin/lesspipe.sh ]] # FreeBSD lesspipe
then
eval "$(SHELL=/bin/sh /usr/local/bin/lesspipe.sh)"
fi
# set colors for use in prompts
if autoload colors && colors 2>/dev/null
then
BLUE="%{${fg[blue]}%}"
RED="%{${fg_bold[red]}%}"
GREEN="%{${fg[green]}%}"
CYAN="%{${fg[cyan]}%}"
MAGENTA="%{${fg[magenta]}%}"
YELLOW="%{${fg[yellow]}%}"
WHITE="%{${fg[white]}%}"
NO_COLOUR="%{${reset_color}%}"
else
BLUE=$'%{\e[1;34m%}'
RED=$'%{\e[1;31m%}'
GREEN=$'%{\e[1;32m%}'
CYAN=$'%{\e[1;36m%}'
WHITE=$'%{\e[1;37m%}'
MAGENTA=$'%{\e[1;35m%}'
YELLOW=$'%{\e[1;33m%}'
NO_COLOUR=$'%{\e[0m%}'
fi
EXITCODE="%(?..%?%1v )"
PROMPT2='\`%_> ' # secondary prompt, printed when the shell needs more information to complete a command.
PROMPT3='?# ' # selection prompt used within a select loop.
PROMPT4='+%N:%i:%_> ' # the execution trace prompt (setopt xtrace). default: '+%N:%i>'
if whence -p dircolors &> /dev/null
then
if [[ -r ~/.dircolors ]]
then
eval "$(dircolors ~/.dircolors)"
else
eval "$(dircolors)"
fi
fi
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
#### FUNCTIONS
for f in ~/{.puppet-managed,git}/dotfiles/zshfuncs/*~(*.zwc|*~)
do
autoload $f:t
done
[[ -r ~/.zshrc.local ]] && source ~/.zshrc.local
# remove duplicates from these arrays
typeset -U path cdpath fpath manpath
if uname | grep -qi cygwin
then
export TERM=cygwin
fi
if [[ "$TERM" == "dumb" ]]
then
unsetopt zle
unsetopt prompt_cr
unsetopt prompt_subst
PROMPT='$ '
else
if [[ -r ~/.puppet-managed/dotfiles/git-prompt.sh ]]
then
source ~/.puppet-managed/dotfiles/git-prompt.sh
elif [[ -r ~/git/dotfiles/git-prompt.sh ]]
then
source ~/git/dotfiles/git-prompt.sh
fi
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWSTASHSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export GIT_PS1_SHOWUPSTREAM="verbose"
export GIT_PS1_SHOWCOLORHINTS=true
# The print command here sets the PuTTY or whatever terminal window title.
precmd () {__git_ps1 '${RED}${EXITCODE}${WHITE}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<<' ' %{${fg_bold[green]}%}%#${NO_COLOUR} ' ; print -Pn "\e]0;%n@%m %~\a"}
if whence -p keychain &> /dev/null
then
if whence -p systemctl &> /dev/null
then
eval $(keychain --eval --nogui --ignore-missing --inherit any --systemd id_ed25519 id_rsa id_ecdsa)
else
eval $(keychain --eval --nogui --ignore-missing --inherit any id_ed25519 id_rsa id_ecdsa)
fi
fi
if whence -p fortune &> /dev/null
then
echo
fortune
echo
fi
if [[ -r /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]]
then
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
elif [[ -r /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]]
then
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
if [[ -r /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]]
then
source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
elif [[ -r /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]]
then
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
fi
fi