-
Notifications
You must be signed in to change notification settings - Fork 2
/
dot_zshrc
279 lines (231 loc) · 9.88 KB
/
dot_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
# Ported from bash 27 June 2021
DEBUG=""
#DEBUG="yes"
test $DEBUG && echo "SHELL: $SHELL HOST: ${HOST%.*} OS: ${OSTYPE:0:6} "
export PATH="${HOME}/bin/noarch:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
export WORDCHARS="${WORDCHARS//\//}" # / breaks a word
export HISTFILE=~/.zhistory
export HISTSIZE=100000 # the number of items for the internal history list
export SAVEHIST=100000
setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
# setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history.
setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a previously found event.
setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file.
setopt HIST_VERIFY # Do not execute immediately upon history expansion.
setopt APPEND_HISTORY # Append to history file
# added by adam as experiments (see man zshoptions)
setopt GLOB_STAR_SHORT # allows **.yml and ***.yml
setopt CHECK_JOBS # reminds you of background running jobs when exiting
setopt CHECK_RUNNING_JOBS # reminds you of suspended jobs when exiting
#setopt LIST_TYPES # show identifying character at end of possible tab completions
#setopt EXTENDED_GLOB # ls -ld ansible*~*docker*; ls **/*(-@)
# zle -al # list all available actions
# ctrl-w:del-back-word, opt-w:del-forward-word, ctrl-arrow:forward/back-word
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
#bindkey '^[[A' up-line-or-search # up arrow
#bindkey '^[[B' down-line-or-search # down arrow
bindkey '\CI' expand-or-complete-prefix # allows tab completiion in middle of word
bindkey '\e[1;5D' backward-word # ctrl-leftArrow move cursor back a word
bindkey '\e[1;5C' forward-word # ctrl-rightArrow move cursor forward a word
bindkey '^[w' kill-word # opt-w to delete forward word
#bindkey å accept-line # literally bind opt-a to an action
export SUDO_PROMPT="Sudo Password: "
export BC_ENV_ARGS="$HOME/.bc"
if [ "${OSTYPE:0:6}" = "darwin" ]; then
test $DEBUG && echo "DETECTED: darwin"
DARWIN="yes"
# do i ever use this? /Library/Developer/CommandLineTools/usr/bin
export PATH="${HOME}/bin/darwin:/opt/homebrew/bin:${PATH}"
# needs to come after PATH gets /opt/homebrew/bin
PYPATH="${HOME}/Library/Python/$(python3 --version | awk -F'[ .]' '{print $2"."$3}')/bin"
test -d "${HOME}/Library/pnpm" && export PNPM_HOME="${HOME}/Library/pnpm"
export PATH="${PATH}:${PNPM_HOME}:${PYPATH}"
#export MANPATH="${MANPATH}:/usr/share/man"
# export HOMEBREW_CASK_OPTS="--appdir=~/Applications"
# export HOMEBREW_AUTO_UPDATE_SECS=86400 # only update once a day
PSARG="auxww";
LARG="-lhPO"
if [ -r "${HOME}/.env" ]; then
export CF_API_TOKEN=$(awk -F= '/^CF_API_TOKEN=/{print $2}' ~/.env)
fi
alias airport="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport"
alias cpdir="pwd | pbcopy"
alias flushdns="sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder"
alias mkdir='mkdir -p'
alias top="top -o cpu -O vsize"
alias updatedb="sudo -b /usr/libexec/locate.updatedb"
elif [[ "$OSTYPE" = "linux-gnu" || "$OSTYPE" = "linux" ]]; then
test $DEBUG && echo "DETECTED: linux"
LINUX="yes"
export PATH="${HOME}/bin/linux:${PATH}:/usr/X11R6/bin:${HOME}/.local/bin"
export MANPATH="${MANPATH}:/usr/share/man:/usr/X11R6/man"
PSARG="-efww"
LARG="-lh"
sentry () {
if (( ${+commands[sentry.pl]} )); then
sudo ${commands[sentry.pl]} $*
fi; }
#test -z $DISPLAY && export DISPLAY="localhost:0.0"
if [ -f /etc/debian_version ]; then
export LESSOPEN="|/usr/bin/lesspipe %s";
export LESSCLOSE="/usr/bin/lesspipe %s %s";
elif [ -f /etc/redhat-release ]; then
eval $(lesspipe.sh)
fi
fi # end os specific
alias cp='cp -vi'
alias edpro="cme ~/.zshrc && cm re-add ~/.zshrc && exec zsh"
alias egrep='egrep --color=auto'
alias grep='grep --color=auto'
alias mv='mv -vi'
alias mkroot="sudo -E zsh"
alias pico='nano'
#alias nano='nano -EGilxz -T2'
alias pwgen='bw generate -cp --words 2 --separator . --includeNumber | tee >(pbcopy)'
mcd() { mkdir -p $1 && cd $1; }
smcd() { sudo mkdir -p $1 && sudo chown -R adam $1&& cd $1; }
pass() {
bw list items --search $* --pretty | egrep "(name|username|password)\":" | sed -e 's/^ *//' -e 's/^"//' -e 's/",$//' -e 's/": "/: /' -e 's/^name:/\nname: /'}
cm() { chezmoi $*; }
cma() { chezmoi add $*; } # add file to chezmoi
cmra() { chezmoi re-add $*; } # add file to chezmoi
cme() { chezmoi edit $*; }
cmf() { chezmoi forget $*; } # stop tracking file in chezmoi
cmg() { chezmoi git $*; }
cmi() { nano ~/.local/share/chezmoi/.chezmoiignore; }
cminit() { sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply adamshand --ssh --purge-binary; }
cmst() { chezmoi status $*; } # show status of chezmoi
cmu() { chezmoi update $*; } # pull updates from git and update $HOME from chezmoi
dps() { docker ps --format "table {{.Names}}\t {{.Size}}\t {{.Status}}\t {{.Ports}}" | sed -e 's/0.0.0.0://g' -e 's/, :::[0-9]*->[0-9]*\/[tu][cd][p]//g'; }
de() {
CONTAINER=$1
if [ ! "$2" ]; then
DCMD='sh'
else
DCMD=$2
fi
shift 2
docker exec -it ${CONTAINER} ${DCMD} $*; }
# docker exec -it $1 ${DCMD}; }
dl() { docker logs --since 24h -f $*; }
dsp() { docker stop $*; }
dst() { docker start $*; }
drs() { docker restart $*; }
if (( ${+commands[docker-compose]} )); then
dc() { docker-compose "$@"; }
else
dc() { docker compose "$@"; }
fi
dcl() { dc logs --follow --timestamps "$@"; }
dcu() { dc up -d "$@" && dcl "$@"; }
dcd() { dc down; }
dl() { docker logs --follow --since=1m --timestamps "$@"; }
dcdu() { dcd && dc up -d && dcl; }
dv() { docker volume "$@"; }
flaunt() { egrep "($1|$)"; } # highlight matches without filtering
gcp() {
git status -s;
echo -n "Commit message: ";
read MSG && \
git pull;
git commit -a -m "gcp: $MSG" && \
git push; }
ipsum() {
test $1 && P=$1 || P=5
test $2 && S=$2 || S=3
curl --silent http://metaphorpsum.com/paragraphs/${P}/${S} | tee >(pbcopy)
}
more () {
if (( ${+commands[bat]} )); then
bat $*
elif (( ${+commands[less]} )); then
less -iw $*
else
more $*
fi; }
p() {
if [ ! $1 ]; then
ps ${PSARG}
else
ps ${PSARG} | grep -iE "[^]]${1}"
fi; }
showip() {
# curl -4 ifconfig.co
dig -4 +short myip.opendns.com a @resolver1.opendns.com
dig -6 +short myip.opendns.com aaaa @resolver1.opendns.com
}
if (( ${+commands[ssh.sh]} )); then
s () { ssh.sh $*; }
fi
vade () { links -dump -width 512 http://adam.nz/vade/ | egrep -v '^ *\$' | egrep --color=auto -A2 "^ # .*${1}.*\$" ;}
autoload -U zmv # zmv '* *' '$f:gs/ /_'; more at: https://strcat.de/zsh/#zmv
autoload -U tetris tetris
if (( ${+commands[eza]} )); then
alias l='eza -lgh --group --group-directories-first --time-style=long-iso --colour-scale'
alias ls='eza -Fg --group-directories-first --colour-scale'
else;
alias l='ls $LARG'
alias ls='ls -F'
fi
if [[ "${HOST%.*}" = "chimera" ]]; then
test $DEBUG && echo "DETECTED: chimera"
elif [[ "${HOST%.*}" = "kauri" ]]; then
export RESTIC_PASSWORD_FILE="/home/adam/etc/restic.txt"
export RESTIC_REPOSITORY="/vol/obelix/restic/"
elif [[ "${HOST%.*}" = "beam" || "${HOST%.*}" = "ch-test1" ]]; then
test $DEBUG && echo "DETECTED: beam or ch-test1 (miro)"
unalias mkroot
fi # end host specific
if (( ${+commands[git]} )); then
test $DEBUG && echo "FOUND: git"
if [[ ! -f ${ZDOTDIR:-${HOME}}/.zcomet/bin/zcomet.zsh ]]; then
git clone https://github.com/agkozak/zcomet.git ${ZDOTDIR:-${HOME}}/.zcomet/bin
fi
source ${ZDOTDIR:-${HOME}}/.zcomet/bin/zcomet.zsh
# Load a prompt
zcomet load agkozak/agkozak-zsh-prompt
# Load some plugins
#zcomet load hlissner/zsh-autopair
zcomet load zsh-users/zsh-autosuggestions
zcomet load zsh-users/zsh-completions
zcomet load zsh-users/zsh-syntax-highlighting
zcomet load zsh-users/zsh-history-substring-search
#zcomet load zdharma-continuum/fast-syntax-highlighting
#zcomet load zdharma-continuum/history-search-multi-word
#zcomet load supercrabtree/k # ls with git information
#zcomet load agkozak/zsh-z # smart cd
#zcomet load ohmyzsh plugins/gitfast # can't remember
#zcomet load zpm-zsh/autoenv # auto run .in/.out when entering/exiting directory
#zcomet snippet https://iterm2.com/shell_integration/zsh
#zcomet snippet https://github.com/jreese/zsh-titles/blob/master/titles.plugin.zsh
#zcomet snippet https://raw.githubusercontent.com/wez/wezterm/main/assets/shell-integration/wezterm.sh
zcomet snippet https://github.com/wez/wezterm/blob/main/assets/shell-integration/wezterm.sh
# Run compinit and compile its cache
if [[ $UID != 0 ]]; then
# gets rid of "insecure directories" error when running mkroot
zcomet compinit
fi
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#708090"
#ZSH_AUTOSUGGEST_COMPLETION_IGNORE="git *"
AGKOZAK_LEFT_PROMPT_ONLY=1
AGKOZAK_PROMPT_CHAR=( ❯ ❯ ❮ )
AGKOZAK_COLORS_PROMPT_CHAR='yellow'
AGKOZAK_CUSTOM_SYMBOLS=( '⇣⇡' '⇣' '⇡' '+' 'x' '!' '>' '?' 'S')
AGKOZAK_BLANK_LINES=1
AGKOZAK_PROMPT_DIRTRIM=0
ZSHZ_CASE=smart
else
echo -e "\nerror: git not installed, skipping zcomet installation.\n"
fi
zstyle ':completion:*' menu select
# disables automatic filename completion of first match
setopt noautomenu
setopt nomenucomplete
# case insensitive path-completion
setopt nocaseglob
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'