-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
315 lines (289 loc) · 9.45 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
# ENV {{{
# LS_COLORS {{{
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36'
# }}}
# DATADIR {{{
if [ -n "${XDG_DATA_HOME-}" ] || [ -n "${HOME-}" ]; then
DATADIR="${XDG_DATA_HOME:-$HOME/.local/share}/zsh"
\mkdir -p -- "$DATADIR"
fi
# }}}
# }}}
# CHANGING DIRECTORIES {{{
setopt auto_cd auto_pushd cd_silent pushd_ignore_dups pushd_minus
# }}}
# COMPLETION {{{
setopt always_last_prompt auto_list auto_menu no_list_ambiguous
setopt list_packed no_list_types complete_in_word glob_complete
autoload -Uz compinit && compinit -D
zstyle ':completion:*:commands' rehash 1 # rehash before completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # case insensitive
zstyle ':completion:*' menu select # select with arrows
zstyle ':completion:*:default' list-colors "${LS_COLORS-}"
# }}}
# EXPANSION {{{
setopt bang_hist no_hist_verify hist_lex_words
setopt equals no_ignore_braces rc_expand_param
setopt magic_equal_subst glob_subst unset
# }}}
# GLOBBING {{{
setopt glob extended_glob bare_glob_qual glob_star_short
setopt case_glob glob_dots no_null_glob nomatch
# }}}
# HISTORY {{{
setopt inc_append_history hist_ignore_all_dups hist_ignore_space
HISTFILE="${DATADIR:+$DATADIR/history}"
HISTSIZE=10000
SAVEHIST=10000
# }}}
# JOB CONTROL {{{
setopt monitor auto_continue hup check_jobs check_running_jobs no_notify
# }}}
# PROMPT {{{
setopt prompt_cr prompt_percent prompt_subst
PROMPT_EOL_MARK=''
PS1='
%B%F{green}%n@%M %F{blue}%~ %F{magenta}$(git_status) %F{red}%(?..^%?)%f%b
%(!.#.$) '
PS2='> '
git_status() {
local branch
if branch="$(git branch --show-current)"; then
if [ -z "$branch" ]; then
branch="detached:$(git rev-parse --short HEAD)"
fi
printf '(%s' "$branch"
git status --porcelain --branch | awk -F '[][, ]' '
/^.?[AC]/ { add++ }
/^.?D/ { del++ }
/^.?[MR]/ { mod++ }
/^.?U/ { con++ }
/^.?\?/ { unt++ }
/^##/ {
if (NF > 2 && $(NF-2) == "behind")
behind = $(NF-1)
if (NF > 2 && $(NF-2) == "ahead")
ahead = $(NF-1)
if (NF > 5 && $(NF-5) == "ahead")
ahead = $(NF-4)
}
END {
if (add > 0) printf(" +%u", add)
if (del > 0) printf(" -%u", del)
if (mod > 0) printf(" ~%u", mod)
if (con > 0) printf(" !%u", con)
if (unt > 0) printf(" ?%u", unt)
if (ahead > 0) printf(" ^%u", ahead)
if (behind > 0) printf(" $%u", behind)
}'
printf ')'
fi 2> /dev/null
}
# }}}
# OTHER {{{
setopt no_flow_control no_ignore_eof interactive_comments rm_star_silent
MAILCHECK=0
# }}}
# KEYBINDS {{{
autoload -Uz up-line-or-beginning-search
autoload -Uz down-line-or-beginning-search
expand() {
zle _expand_alias
zle expand-word
}
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
zle -N expand
WORDCHARS='~!@#$%^&*_-+.?'
bindkey -d
bindkey '^A' beginning-of-line
bindkey '^E' end-of-line
bindkey '^H' emacs-backward-word
bindkey '^L' emacs-forward-word
bindkey '^K' up-line-or-beginning-search
bindkey '^J' down-line-or-beginning-search # this hangs mc after pressing enter
bindkey '^R' history-incremental-search-backward
bindkey '^F' history-incremental-search-forward
bindkey '^W' backward-kill-word
bindkey '^U' backward-kill-line
bindkey "${terminfo[kdch1]}" delete-char
bindkey '^ ' expand
bindkey '^I' expand-or-complete
bindkey "${terminfo[kcbt]}" reverse-menu-complete
# }}}
# BOOKMARKS {{{
BMFILE="${DATADIR:+$DATADIR/bookmarks}"
bm() {
local bmark
if [ -z "${BMFILE-}" ]; then
return 1
fi
if [ -z "${1-}" ]; then
hash -d
elif [ "${1-}" != '-' ]; then
unhash -d -- "$1" > /dev/null 2>&1
{
if [ -f "$BMFILE" ]; then
sed -e "/^$1=/d" -- "$BMFILE"
fi
if [ "${2-}" != '-' ]; then
bmark="$(cd -- "${2-.}" && pwd -L)"
hash -d -- "$1=$bmark" > /dev/null 2>&1
printf '%s=%s\n' "$1" "$bmark"
fi
} > "$BMFILE.tmp"
mv -f -- "$BMFILE.tmp" "$BMFILE"
else
hash -dr > /dev/null 2>&1
if [ -f "$BMFILE" ]; then
while read -r bmark; do
hash -d -- "$bmark" > /dev/null 2>&1
done < "$BMFILE"
fi
fi
}
bm -
# }}}
# ALIASES {{{
setopt aliases
# cd {{{
alias -- -='cd -'
alias -- -2='cd -2'
# }}}
# ls {{{
alias ls='ls --color=auto --group-directories-first'
alias l='ls -A'
alias ll='ls -Al'
# }}}
# du {{{
ds() { du -sh "$@" | sort -rh; }
# }}}
# fs {{{
alias cp='cp -RPf --'
alias cpr='rsync -ahh --info=progress2 --partial-dir=.rsync --'
alias lh='ln -fL --'
alias ln='ln -fs --'
alias mkdir='mkdir -p --'
alias mv='mv -f --'
alias rm='rm -Rf --'
alias rmdir='rmdir --'
# }}}
# archive {{{
alias x='unpack'
alias z='pack'
compdef _files unpack
compdef _files pack
# }}}
# find {{{
alias f='find . -name'
alias fd='find -L . -type d -name'
alias ff='find -L . -type f -name'
# }}}
# grep {{{
alias grep='grep --color=auto'
alias s='grep -n -RI'
alias sc='s --include="*.c"'
alias sh='s --include="*.h"'
# }}}
# jobs {{{
j() { jobs -l | grep -- "$1"; }
p() { ps -Af | { head -n 1; grep -- "$1"; }; }
alias k='kill -s TERM --'
alias kk='kill -s KILL --'
# }}}
# history {{{
h() { fc -l 0 | grep -- "$1"; }
d() { dirs -lv | grep -- "$1"; }
# }}}
# view {{{
alias v='head -n 1000 --'
# }}}
# sudo {{{
alias sudo='sudo ' # pass aliases over sudo
# }}}
# git {{{
alias gch='git checkout'
alias gst='git status'
alias gsh='git show --name-status --pretty=fuller --decorate=no'
alias gl='git log --oneline --decorate=no'
alias gl1='gl -n 10'
alias gl2='gl -n 20'
alias gl3='gl -n 30'
alias gl4='gl -n 40'
alias gl5='gl -n 50'
alias glg='git log --oneline --decorate=no --graph'
alias glg1='glg -n 10'
alias glg2='glg -n 20'
alias glg3='glg -n 30'
alias glg4='glg -n 40'
alias glg5='glg -n 50'
alias ga='git add'
alias gap='git add --patch'
alias gau='git add --update'
alias grs='git reset'
alias grh='git reset --hard'
alias gc='git commit'
alias gcm='git commit -m'
alias gca='git commit --amend'
alias gcn='git commit --all --amend --no-edit'
alias gsu='git submodule update'
alias gpr='git pull --rebase'
alias gpu='git push'
alias gpf='git push --force'
# TODO: change to difftool
alias gd='git diff'
alias gdc='git diff --cached'
# gds() { git diff $1~ $1 }
# compdef _git gds=git-show
alias gds='git show'
alias gm='git mergetool --no-prompt'
alias gma='git merge --abort'
alias gcp='git cherry-pick'
alias gcpa='git cherry-pick --abort'
alias gcpc='git cherry-pick --continue'
alias gr='git rebase'
alias gri='git rebase --interactive --autostash --committer-date-is-author-date'
alias gra='git rebase --abort'
alias grc='git rebase --continue'
alias ggc='git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 \
-c gc.rerereresolved=0 -c gc.rerereunresolved=0 \
gc --prune=now'
alias gx='mv .git/objects/pack/pack-* . && \
git unpack-objects < pack-*.pack && \
rm -f pack-*.*'
# blame bisect clean clone cherry-pick describe stash tag submodule
# TODO git log --follow -L<n,m:file> -- <file>
# }}}
# docker {{{
alias dl='docker images'
alias dll='docker images -a'
alias dc='docker container ls -a'
alias dp='docker ps'
alias dk='docker kill'
alias dgc='docker system prune -af'
# }}}
# ledger {{{
alias ledg='cat *.prices.ldg *.ledger.ldg | ledger --pedantic --check-payees -f *.accounts.ldg -f - balance'
alias ledg_assets='ledg \( "^assets" and not ":business:" \) or "^debts"'
alias ledg_pln='ledg_assets -X PLN'
alias ledg_eur='ledg_assets -X EUR'
alias ledg_iwda='ledg_assets -X IWDA'
alias ldg='ledg "^assets" "^debts"'
alias ldga='ledg_assets; echo; ledg_pln; echo; ledg_eur; echo; ledg_iwda'
# }}}
# picocom {{{
alias p0='picocom -s "sb -vv" -b 115200 /dev/ttyUSB0'
alias p1='picocom -s "sb -vv" -b 921600 /dev/ttyUSB0'
# }}}
# record {{{
alias record='ffmpeg -f x11grab -r 30 -s 1920x1080 -i :0.0 -f alsa -i default -c:v libx264 -crf 0 -c:a flac'
# }}}
# monitor {{{
alias mc='xrandr --output HDMI1 --same-as eDP1 --auto && pacmd set-default-sink alsa_output.pci-0000_00_03.0.hdmi-stereo-extra1'
alias md='xrandr --output HDMI1 --off && pacmd set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo'
# }}}
# ffmpeg {{{
video_downscale() { ffmpeg -i "$1" -c:v libx265 -c:a copy -s 1920x1080 -r 30 "$2"; }
video_downscale_pion() { ffmpeg -i "$1" -c:v libx265 -c:a copy -s 1080x1920 -r 30 "$2"; }
# }}}
# }}}