-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
318 lines (271 loc) · 8.85 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# Ben's ZSHrc
#####################
# Shell Prefs #
#####################
# Set edditing and viewing preferences
export EDITOR='vim'
export PAGER='less'
export VISUAL='vim'
export GH_PAGER="cat"
export LESS='-X' # Don't send termcap initialization and deinitialization strings to the terminal
# Vi keys, what else?
bindkey -v
# Start a reverse search using ctrl+r
bindkey '^R' history-incremental-search-backward
# Make sure that the delete key actually deletes
bindkey '\e[3~' delete-char
# Using what is already on the current line, reverse search with up/down
autoload -Uz history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[[A" history-beginning-search-backward-end
bindkey "^[[B" history-beginning-search-forward-end
if [ $(uname) = "Linux" ]; then
bindkey "^[OA" history-beginning-search-backward-end
bindkey "^[OB" history-beginning-search-forward-end
fi
# 755 for directories, 644 for files
umask 0022
# Set PS1 to $PWD %>
export PS1='%F{cyan}%c %#>%f'
# Set right PS1 to VCS info
export RPS1='%F{cyan}${vcs_info_msg_0_}%f'
# Correct spelling
setopt CORRECT
# Load autocompletion
autoload -Uz compinit
compinit
# Do not remove trailing slashes from directories OR symlinks to directories
setopt no_auto_remove_slash
# Enable full screen command editing using 'v' in command mode
autoload edit-command-line; zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# Enable vcs_info
autoload -Uz vcs_info
setopt prompt_subst
# Configure vcs_info
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr ' *'
zstyle ':vcs_info:*' stagedstr ' +'
zstyle ':vcs_info:git:*' formats '(%b%u%c)'
zstyle ':vcs_info:git:*' actionformats '(%b|%a%u%c)'
precmd(){
# Load vcs_info
vcs_info
# Write some info to terminal title.
# This is seen when the shell prompts for input.
case $TERM in
(*xterm*)
print -Pn "\e]0;%n@%m: %~\a"
;;
esac
}
preexec(){
# Write command and args to terminal title.
# This is seen while the shell waits for a command to complete.
case $TERM in
(*xterm*)
printf "\033]0;%s\a" "$1"
;;
esac
}
#####################
# History Prefs #
#####################
export HISTFILE=~/.zsh_history # Save history here
export HISTSIZE=100000 # Maximum number of events stored in the internal history list.
export SAVEHIST=10000000 # Maximum number of history events to save in the history file.
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_REDUCE_BLANKS # Do not save blank lines
setopt HIST_IGNORE_SPACE # Do not save lines preceeded with a space
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
setopt HIST_NO_STORE # Remove the history (fc -l) command from the history list when invoked.
setopt INC_APPEND_HISTORY_TIME # Add history to file after execution
setopt HIST_FCNTL_LOCK # Lock history file using the system's fcntl call, where this method is available.
setopt HIST_SAVE_BY_COPY # write out a copy of the file named $HISTFILE.new and then rename it over the old one
alias history='fc -lni 0 -1'
#####################
# PATH Settings #
#####################
# If I'm on a Mac check this stuff out, if not then don't even bother
if [[ $(uname) == "Darwin" ]]; then
# Apple Developer Tools
if [ -d /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin ]; then
export PATH="$PATH:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin"
fi
#macOS seems to put useful things like ping and chown under /sbin or /usr/sbin...
export PATH="$PATH:/sbin:/usr/sbin"
fi
# For Go
if [ -d $HOME/go/bin ]; then
export PATH="$PATH:$HOME/go/bin"
fi
# Mostly I have scripts from nextcloud
if [ -d $HOME/nextcloud/scripts ]; then
export PATH="$HOME/nextcloud/scripts:$PATH"
elif [ -d $HOME/scripts ]; then
# Sometimes I have scripts in my home dir
export PATH="$HOME/scripts:$PATH"
fi
# Sometimes I have binaries in my home dir
if [ -d $HOME/bin ]; then
export PATH="$HOME/bin:$PATH"
fi
# Rancher Desktop
if [ -d $HOME/.rd/bin ]; then
export PATH="$HOME/.rd/bin:$PATH"
fi
if [ -d /usr/local/sbin ]; then
export PATH="/usr/local/sbin:$PATH"
fi
# Check homebrew
if [ -f /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
export PATH="$PATH:/opt/homebrew/bin"
elif [ -f /usr/local/bin/brew ]; then
eval "$(/usr/local/bin/brew shellenv)"
export PATH="$PATH:/usr/local/bin"
fi
# Make sure /usr/local/bin is at the forefront of PATH
if [ -d /usr/local/bin ]; then
export PATH="/usr/local/bin:$PATH"
fi
#####################
# Aliases #
#####################
if command -v less > /dev/null; then
alias more='less'
fi
if command -v vim > /dev/null; then
alias vi='vim'
alias view='vim -R'
fi
if command -v git > /dev/null; then
alias git='git --no-pager'
fi
if command -v kubectl > /dev/null; then
alias k='kubectl'
fi
alias mkdir='mkdir -p'
[ $(uname) = "Linux" ] && alias ls='ls -hF --color' || alias ls='ls -hF'
alias jsonformat="python -m json.tool"
alias _clear='clear'
alias clear='_clear && printf "\033[3J"'
#####################
# SSH #
#####################
# If we are coming in via SSH, turn the PS1 yellow
if [ -n "$SSH_CLIENT" ]; then
export PS1="%F{yello}%n@%m:%c %#>%f"
export RPS1='%F{yello}${vcs_info_msg_0_}%f'
fi
#####################
# Python Prefs #
#####################
# Specify python rc file, to enable vi style editing and persistent history
export PYTHONSTARTUP=~/.pyrc
#####################
# Docker help #
#####################
if command -v docker > /dev/null; then
dockerstop(){
docker stop $(docker ps -a -q)
}
dockerrm(){
docker rm -f $(docker ps -a -q)
}
dockerrmi(){
docker rmi -f $(docker images -q)
}
killdocker(){
dockerstop
dockerrm
dockerrmi
}
fi
#####################
# rmssh #
#####################
rmssh(){
for EACH in $@; do
cat ~/.ssh/known_hosts | grep -v $EACH > ~/.ssh/temp_known_hosts
mv ~/.ssh/temp_known_hosts ~/.ssh/known_hosts
done
}
#####################
# dirhash #
#####################
dirhash(){
if [ $# -gt 1 ]; then
for E in $*; do
dirhash ${E}
done
return 0
fi
if [ ! -d $1 ]; then
return 1
fi
cd $1
hash=$(find . -type f -exec shasum -a 256 {} + | awk '{print $2, "\t", $1}' | sort | shasum -a 256 | awk '{print $1}')
printf "%s\t%s\n" $1 $hash
cd - > /dev/null
}
#####################
# TILIX #
#####################
if [ -f /etc/profile.d/vte.sh ]; then
if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
source /etc/profile.d/vte.sh
fi
fi
#####################
# iTerm2 #
#####################
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
#####################
# Command Prefs #
#####################
# ls colours for BSD ls
# 'fb' f=foreground, b=background
ls_dir='hx' #...........................light-grey default
ls_sym='fx' #...........................magenta default
ls_sock='cx' #..........................green default
ls_pipe='dx' #..........................brown default
ls_exe='bx' #...........................red default
ls_blk='eg' #...........................blue cyan
ls_char='ed' #..........................blue brown
ls_setuid='ab' #........................black red
ls_setgid='ag' #........................black cyan
ls_dir_write_others_sticky='ac' #.......black green
ls_dir_write_others_no_sticky='ad' #....black brown
export LSCOLORS="${ls_dir}${ls_sym}${ls_sock}${ls_pipe}${ls_exe}${ls_blk}${ls_char}${ls_setuid}${ls_setgid}${ls_dir_write_others_sticky}${ls_dir_write_others_no_sticky}"
export CLICOLOR=yes
# ls colours for GNU
export LS_COLORS='di=37:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43'
###########################
# zsh-syntax-highlighting #
###########################
# This must be last:
if [ -f $HOME/.zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then
source $HOME/.zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
#####################
# Atuin #
#####################
if command -v atuin > /dev/null; then
eval "$(atuin init zsh)"
fi
#####################
# GPG #
#####################
export GPG_TTY=$(tty)
#####################
# LOCAL.RC #
#####################
if [ -f "$HOME/.zshrclocal" ]; then
source "$HOME/.zshrclocal"
fi