-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zshrc
370 lines (319 loc) · 10.9 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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# vim: foldmethod=marker:fen
#
# == Very top == {{{1
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# == Aliases == {{{1
# Processes
alias psa="ps aux | less"
alias psg="ps aux | grep "
alias psf="ps aux | fzf -m"
alias k9='kill -9'
# Moving around
alias ..='cd ..'
alias cdb='cd -'
# Quitting
alias ZZ='exit'
alias :q='exit'
# Show human friendly numbers
alias df='df -h'
alias ls='ls -h'
alias du='du -h -d 2'
# Long form ls with hidden info
alias ll="ls -lh"
alias la="ls -lah"
# show me files matching "ls grep"
alias lsg='ll | grep '
alias lsp='ll | fzf -m'
# Being careful on most commands
alias cp="cp -i"
alias ln="ln -i"
alias mv="mv -i"
alias rm="rm -i"
# Litra Glow control
# https://ultracrepidarian.phfactor.net/2022/03/09/controlling-the-logitech-litra-on-macos/
function _hid() {
if (( $+commands[hidapitester] )); then
hidapitester --vidpid 046D/C900 --open --length 20 --send-output $1
fi
}
# 2/17/22 Litra Glow aliases from https://github.com/kharyam/litra-driver/issues/13
function light() {
_hid 0x11,0xff,0x04,0x1c,0x01
}
function dark() {
_hid 0x11,0xff,0x04,0x1c
}
# ~10%
function glow(){
_hid 0x11,0xff,0x04,0x4c,0x00,20
}
# ~20%
function dim(){
_hid 0x11,0xff,0x04,0x4c,0x00,50
}
# tweaking by hand - less than 50%
function normal() {
_hid 0x11,0xff,0x04,0x4c,0x00,70
}
# ~50%
function medium() {
_hid 0x11,0xff,0x04,0x4c,0x00,100
}
# 90%
function bright(){
_hid 0x11,0xff,0x04,0x4c,0x00,204
}
# 2700K
function warmest() {
_hid 0x11,0xff,0x04,0x9c,10,140
}
# 3200K
function warm() {
_hid 0x11,0xff,0x04,0x9c,12,128
}
# 6500K
function coldest() {
_hid 0x11,0xff,0x04,0x9c,25,100
}
# Private chezmoi
alias pchezmoi="chezmoi -S ~/.local/share/chezmoi_private"
# git {{{2
# Branch (b)
alias gb='git branch'
alias gbc='git checkout -q -b'
alias gbl='git branch -v'
alias gbL='git branch -av'
alias gbx='git branch -d'
alias gbX='git branch -D'
alias gbm='git branch -m'
alias gbM='git branch -M'
alias gbs='git show-branch'
alias gbS='git show-branch -a'
# Commit (c)
alias gc='git commit --verbose'
alias gca='git commit --verbose --all'
alias gcm='git commit --message'
alias gco='git checkout'
alias gcO='git checkout --patch'
alias gcf='git commit --amend --reuse-message HEAD'
alias gcF='git commit --verbose --amend'
alias gcp='git cherry-pick --ff'
alias gcP='git cherry-pick --no-commit'
alias gcr='git revert'
alias gcR='git reset "HEAD^"'
alias gcs='git show'
alias gcrf='git commit --fixup=$(glg | fzf | cut -f 2 -d " ")'
alias gcrs='git commit --squash=$(glg | fzf | cut -f 2 -d " ")'
# Conflict (C)
alias gCl='git status | sed -n "s/^.*both [a-z]*ed: *//p"'
alias gCa='git add $(gCl)'
alias gCe='git mergetool $(gCl)'
alias gCo='git checkout --ours --'
alias gCO='gCo $(gCl)'
alias gCt='git checkout --theirs --'
alias gCT='gCt $(gCl)'
# Data (d)
alias gd='git ls-files'
alias gdc='git ls-files --cached'
alias gdx='git ls-files --deleted'
alias gdm='git ls-files --modified'
alias gdu='git ls-files --other --exclude-standard'
alias gdk='git ls-files --killed'
alias gdi='git status --porcelain --short --ignored | sed -n "s/^!! //p"'
# Fetch (f)
alias gf='git fetch'
alias gfc='git clone'
alias gfm='git pull'
alias gfr='git pull --rebase'
# Grep (g)
alias gg='git grep'
alias ggi='git grep --ignore-case'
alias ggl='git grep --files-with-matches'
alias ggL='git grep --files-without-matches'
alias ggv='git grep --invert-match'
alias ggw='git grep --word-regexp'
# Index (i)
alias gia='git add'
alias giaa='git add -A'
alias giA='git add --patch'
alias giu='git add --update'
alias gid='git diff --no-ext-diff --cached'
alias giD='git diff --no-ext-diff --cached --word-diff'
alias gir='git reset'
alias giR='git reset --patch'
alias gix='git rm -r --cached'
alias giX='git rm -rf --cached'
# Merge (m)
alias gm='git merge'
alias gmC='git merge --no-commit'
alias gmF='git merge --no-ff'
alias gma='git merge --abort'
alias gmt='git mergetool'
alias gmm='git merge origin/master'
# Push (p)
alias gp='git push'
alias gpf='git push --force'
alias gpa='git push --all'
alias gpA='git push --all && git push --tags'
alias gpt='git push --tags'
alias gpc='git push --set-upstream origin HEAD'
# Rebase (r)
alias gr='git rebase'
alias gra='git rebase --abort'
alias grc='git rebase --continue'
alias gri='git rebase --interactive'
alias grs='git rebase --skip'
# Remote (R)
alias gR='git remote'
alias gRl='git remote --verbose'
alias gRa='git remote add'
alias gRx='git remote rm'
alias gRm='git remote rename'
alias gRu='git remote update'
alias gRp='git remote prune'
alias gRs='git remote show'
# Stash (s)
alias gs='git stash'
alias gsa='git stash apply'
alias gsx='git stash drop'
alias gsl='git stash list'
alias gsd='git stash show --patch --stat'
alias gsp='git stash pop'
alias gss='git stash save --include-untracked'
alias gsS='git stash save --patch --no-keep-index'
alias gsw='git stash save --include-untracked --keep-index'
# Submodule (S)
alias gS='git submodule'
alias gSa='git submodule add'
alias gSf='git submodule foreach'
alias gSi='git submodule init'
alias gSI='git submodule update --init --recursive'
alias gSl='git submodule status'
alias gSm='git-submodule-move'
alias gSs='git submodule sync'
alias gSu='git submodule foreach git pull origin master'
alias gSx='git-submodule-remove'
# Working Copy (w)
alias gws='git status --ignore-submodules=none --short'
alias gwS='git status --ignore-submodules=none'
alias gwd='git diff --no-ext-diff'
alias gwD='git diff --no-ext-diff --word-diff'
alias gwr='git reset --soft'
alias gwR='git reset --hard'
alias gwc='git clean -n'
alias gwC='git clean -f'
alias gwx='git rm -r'
alias gwX='git rm -rf'
# Log
alias gl='git log --topo-order'
alias glg='git log --topo-order --graph --pretty=one --abbrev-commit --decorate'
alias gls='git log --topo-order --stat'
alias gld='git log --topo-order --stat --patch --full-diff'
alias glo='git oneline'
alias glb='git brief'
alias glc='git shortlog --summary --numbered'
# }}}2
# virtualenvs
alias mkvenv="python -m venv .venv"
alias govenv="source .venv/bin/activate"
# Generalized diff with colors
diff() {
if (( $+commands[colordiff] )); then
command colordiff --unified "$@"
else
command diff --unified "$@"
fi
}
# == Settings == {{{1
# History parameters
HISTFILE="$HOME/.zsh_history" # Path to the history file.
HISTSIZE=10000 # Max number of events to store in session.
SAVEHIST=10000 # Max number of history events to save.
# Editor and visual
export EDITOR='nvim'
export VISUAL='nvim'
export PAGER='less'
export LESS='-F -g -i -M -R -S -w -X -z-4'
# Changing directories
setopt AUTO_CD # Change to directory when just the name is specified.
setopt AUTO_PUSHD # Make cd push the old directory onto the stack.
setopt PUSHD_IGNORE_DUPS # Do not push duplicates onto the stack.
setopt PUSHD_SILENT # Do not print directory stack after pushd or popd.
setopt PUSHD_TO_HOME # Have pushd with no arguments act like `pushd $HOME'.
setopt CDABLE_VARS # Treat `cd var' as `cd ~var' when var is a variable.
# Completion
setopt AUTO_NAME_DIRS # Automatically create named directories for vars.
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
setopt ALWAYS_TO_END # Move cursor to the end of a completed word.
setopt AUTO_MENU # Show completion menu on a succesive tab press.
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash.
setopt NO_MENU_COMPLETE # Do not autoselect the first completion entry.
# Scripts and functions
setopt MULTIOS # Allow multiple input and output redirections.
# Expansion and globbing
setopt EXTENDED_GLOB # Enable extended glob matching.
setopt BRACE_CCL # Allow brace character class list expansion.
setopt NO_CASE_GLOB # Make globbing case insensitive.
# ZLE
setopt COMBINING_CHARS # Handle combining characters specially.
setopt BEEP # Beep on error in line editor.
WORDCHARS='*?_-.[]~&;!#$%^(){}<>' # Do not treat / and = as part of a word.
# Input/output
setopt NO_CLOBBER # Don't truncate existing files with '>'.
setopt RC_QUOTES # Allow '' to represent ' in single-quoted strings.
setopt NO_FLOW_CONTROL # Disable start/stop characters (^s and ^q).
setopt PATH_DIRS # Perform path search even on command names with slashes.
setopt CORRECT # Correct commands.
# Job control
setopt LONG_LIST_JOBS # List jobs in the long format by default.
setopt AUTO_RESUME # Attempt to resume existing jobs first.
setopt NOTIFY # Report status of background jobs immediately.
setopt NO_BG_NICE # Don't run all background jobs at a lower priority.
setopt NO_HUP # Don't kill jobs on shell exit.
setopt NO_CHECK_JOBS # Don't report on jobs when shell exits.
# History
setopt BANG_HIST # Treat the '!' character specially during expansion.
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_IGNORE_SPACE # Do not record an event starting with a space.
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 HIST_BEEP # Beep when accessing non-existent history.
# Make poetry and pipenv create virtualenvs in project directory
export POETRY_VIRTUALENVS_IN_PROJECT=1
export PIPENV_VENV_IN_PROJECT=1
# == New tools == {{{1
# Homebrew
if [[ -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Pyenv
if (( $+commands[pyenv] )); then
eval "$(pyenv init -)"
fi
# == iTerm shell integration == {{{1
if [[ -f ~/.iterm2_shell_integration.zsh ]]; then
source ~/.iterm2_shell_integration.zsh
fi
# == Secrets == {{{1
source ~/.zsh/secrets.zsh
if [[ -f ~/.config/op/plugins.sh ]]; then
source ~/.config/op/plugins.sh
fi
# == Source .zshrc_local file == {{{1
if [[ -f ~/.zshrc_local ]]; then
source ~/.zshrc_local
fi
# == Interactive stuff: should be last line because we load ZSH highlighting == {{{1
source ~/.zsh/interactive.zsh