-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.zshrc
431 lines (376 loc) · 11.2 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
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#!/usr/bin/env zsh
# History
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
HISTSIZE=50000
SAVEHIST=10000
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_all_dups
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_reduce_blanks
setopt hist_verify
setopt inc_append_history
setopt share_history
# Directories
setopt auto_cd
setopt auto_pushd
setopt pushdminus
unsetopt pushd_ignore_dups
# Completion
setopt always_to_end
setopt auto_menu
setopt complete_in_word
unsetopt flow_control
unsetopt menu_complete
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path $ZSH_CACHE_DIR
zstyle ':completion:*' list-colors ''
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
bindkey "^[[A" history-beginning-search-backward
bindkey "^[[B" history-beginning-search-forward
setopt correct
setopt ignore_eof
setopt local_options
setopt local_traps
setopt no_bg_nice
setopt no_hup
setopt no_list_beep
setopt prompt_subst
autoload -Uz bashcompinit; bashcompinit
autoload -Uz promptinit; promptinit
autoload edit-command-line; zle -N edit-command-line
zmodload zsh/nearcolor
bindkey "^X^E" edit-command-line
# Kick homebrew off
if [[ -d ~/.linuxbrew ]]; then
eval "$(~/.linuxbrew/bin/brew shellenv)"
elif [[ -d /home/linuxbrew/.linuxbrew ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
elif [[ -f "/opt/homebrew/bin/brew" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# zplug
if [[ -f "$(command -v brew)" ]]; then
export ZPLUG_HOME=$(brew --prefix)/opt/zplug # homebrew-installed zplug
else
export ZPLUG_HOME=/usr/local/opt/zplug
fi
source $ZPLUG_HOME/init.zsh
# Plugins
plugins=(git fzf)
zplug 'zplug/zplug', hook-build:'zplug --self-manage'
zplug "zsh-users/zsh-autosuggestions"
zplug "zsh-users/zsh-completions"
zplug "zsh-users/zsh-syntax-highlighting", defer:2
zplug "zsh-users/zsh-history-substring-search", defer:3
zplug "spaceship-prompt/spaceship-prompt", use:spaceship.zsh, from:github, as:theme
zplug "spaceship-prompt/spaceship-vi-mode"
# zplug "mafredri/zsh-async", use:"async.zsh", hook-build:"ln -sf $ZPLUG_HOME/repos/mafredri/zsh-async/async.zsh $(brew --prefix)/share/zsh/site-functions/async"
# Install plugins if there are plugins that have not been installed
if ! zplug check --verbose; then
printf "Install? [y/N]: "
if read -q; then
echo; zplug install
fi
fi
zplug load
# Prompt
SPACESHIP_PROMPT_ORDER=(
time # Time stamps section
user # Username section
dir # Current directory section
host # Hostname section
git # Git section (git_branch + git_status)
# hg # Mercurial section (hg_branch + hg_status)
# package # Package version
# gradle # Gradle section
# maven # Maven section
node # Node.js section
ruby # Ruby section
# elixir # Elixir section
# xcode # Xcode section
# swift # Swift section
# golang # Go section
# php # PHP section
# rust # Rust section
# haskell # Haskell Stack section
# julia # Julia section
# docker # Docker section
# aws # Amazon Web Services section
# gcloud # Google Cloud Platform section
# venv # virtualenv section
# conda # conda virtualenv section
# pyenv # Pyenv section
# dotnet # .NET section
# ember # Ember.js section
# kubectl # Kubectl context section
# terraform # Terraform workspace section
# ibmcloud # IBM Cloud section
exec_time # Execution time
line_sep # Line break
battery # Battery level and status
vi_mode # Vi-mode indicator
jobs # Background jobs indicator
exit_code # Exit code section
char # Prompt character
)
# Spaceship
SPACESHIP_PACKAGE_SYMBOL=""
SPACESHIP_PROMPT_PREFIXES_SHOW=false
# SPACESHIP_PROMPT_SUFFIXES_SHOW=false
SPACESHIP_VI_MODE_INSERT=""
SPACESHIP_VI_MODE_NORMAL=""
# Source ~/.localrc if it exists
[[ -e "$HOME"/.localrc ]] && . "$HOME"/.localrc
# asdf
. "$HOME/.asdf/asdf.sh"
# append completions to fpath
fpath=(${ASDF_DIR}/completions $fpath)
# Base16 Shell (doesn't work in Terminal.app)
# if [[ "$TERM" =~ "256" ]] || [[ "$TERM" =~ "kitty" ]] || [[ "$TERM" =~ "screen" ]]; then
# BASE16_SHELL="$HOME/.config/base16-shell/"
# [ -n "$PS1" ] && [ -s "$BASE16_SHELL/profile_helper.sh" ] && source "$BASE16_SHELL/profile_helper.sh"
# fi
# TODO: auto-switch base16 theme
# if [[ defaults read -g AppleInterfaceStyle =~ "Dark" ]] && [[ ]]
# Completions
for f in "$HOME/.config/bash/completions/"*; do
. "$f"
done
# export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/usr/local/share/zsh-syntax-highlighting/highlighters
# ZSH_SYNTAX_HIGHLIGHT_PATH=/usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# [ -f $ZSH_SYNTAX_HIGHLIGHT_PATH ] && . $ZSH_SYNTAX_HIGHLIGHT_PATH
# Anybar
anybar() {
if [[ "$1" = 'open' ]]; then
open /Applications/AnyBar.app
fi
printf "%s" "${1:-white}" | nc -4u -w0 localhost "${2:-1738}"
}
# AWS
if [[ -s "$HOME"/.awsam/bash.rc ]]; then
export AWS_DEFAULT_USER=ubuntu
. "$HOME"/.awsam/bash.rc
fi
#ec2-find() {
# aws ec2 describe-instances --filters Name=tag-value,Values=*$1* | grep "$1\|InstanceId" | uniq | sed -e 's/^[ \t\]*//' -e 's/,//g' | paste - -
#}
# Browser
export BROWSER=open
alias chrome="/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome"
# Colors
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
WHITE="$(tput setaf 7)"
GRAY="$(tput setaf 8)"
BOLD="$(tput bold)"
UNDERLINE="$(tput sgr 0 1)"
INVERT="$(tput sgr 1 0)"
NOCOLOR="$(tput sgr0)"
export RED
export GREEN
export YELLOW
export BLUE
export MAGENTA
export CYAN
export WHITE
export GRAY
export BOLD
export UNDERLINE
export INVERT
export NOCOLOR
# cowsay
export COWPATH="$dotfiles/system/cows/:/usr/local/Cellar/cowsay/3.04/share/cows/"
alias bunny="cowsay -W 15 -f signbunny"
# ctop
alias ctop="TERM=xterm256-color ctop"
# Editor
if [[ -f "$(command -v nvim)" ]]; then
export EDITOR='nvim'
elif [[ -f "$(command -v vim)" ]]; then
export EDITOR='vim'
else
export EDITOR='vi'
fi
alias e="\$EDITOR"
# FZF
export FZF_DEFAULT_COMMAND='ag -g "" --hidden'
[ -f ~/.fzf.zsh ] && . ~/.fzf.zsh
# Git
alias g=git
# [[ -f "$(command -v hub)" ]] && eval "$(hub alias -s)" && alias g=hub
complete -o default -o nospace -F _git g
alias d='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
daa() {
d add $(d s | grep -v main | awk '{printf "%s ", $2}')
}
# GIT heart FZF
# -------------
is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
fzf-down() {
fzf --height 50% --min-height 20 --border --bind ctrl-/:toggle-preview "$@"
}
# File
_gf() {
is_in_git_repo || return
git -c color.status=always status --short |
fzf-down -m --ansi --nth 2..,.. \
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' |
cut -c4- | sed 's/.* -> //'
}
# Branch
_gb() {
is_in_git_repo || return
git branch -a --color=always | grep -v '/HEAD\s' | sort |
fzf-down --ansi --multi --tac --preview-window right:70% \
--preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1)' |
sed 's/^..//' | cut -d' ' -f1 |
sed 's#^remotes/##'
}
# Tag
_gt() {
is_in_git_repo || return
git tag --sort -version:refname |
fzf-down --multi --preview-window right:70% \
--preview 'git show --color=always {}'
}
# Commit
_go() {
is_in_git_repo || return
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always |
fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \
--header 'Press CTRL-S to toggle sort' \
--preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always' |
grep -o "[a-f0-9]\{7,\}"
}
# Remote
_gr() {
is_in_git_repo || return
git remote -v | awk '{print $1 "\t" $2}' | uniq |
fzf-down --tac \
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1}' |
cut -d$'\t' -f1
}
# Stash
_gs() {
is_in_git_repo || return
git stash list | fzf-down --reverse -d: --preview 'git show --color=always {1}' |
cut -d: -f1
}
join-lines() {
local item
while read item; do
echo -n "${(q)item} "
done
}
bind-git-helper() {
local c
for c in $@; do
eval "fzf-g$c-widget() { local result=\$(_g$c | join-lines); zle reset-prompt; LBUFFER+=\$result }"
eval "zle -N fzf-g$c-widget"
eval "bindkey '^g^$c' fzf-g$c-widget"
done
}
bindkey -r "^G"
bind-git-helper f b t r o s
unset -f bind-git-helper
# GnuPG
GPG_TTY="$(tty)"
export GPG_TTY
# GPGTools
# export GPG_TTY=$(tty)
# export PINENTRY_USER_DATA="USE_CURSES=1"
# if [[ -n "$SSH_CONNECTION" ]]; then
# export PINENTRY_USER_DATA="USE_CURSES=1"
# fi
# Go
# gotop
alias gotop="TERM=xterm256-color gotop"
# Heroku
alias h='heroku'
# Homebrew
export HOMEBREW_CASK_OPTS="--appdir=/Applications"
# Node
if [[ -f "$(command -v npm)" ]]; then
export NODE_PATH=$(npm root --quiet --location=global)
fi
# System
colours() {
for i in {0..255}; do
printf "%s" "\\x1b[38;5;${i}m${i} "
done
unset i
}
fixaudio() {
sudo killall coreaudiod
}
fixbluetooth() {
sudo killall bluetoothd
}
fixcamera() {
sudo killall VDCAssistant
}
proxy() {
if [[ "$1" ]]; then
# For socks5
# networksetup -setsocksfirewallproxystate Wi-Fi "$1"
networksetup -setsecurewebproxystate Wi-Fi "$1"
networksetup -setwebproxystate Wi-Fi "$1"
fi
local status="$(networksetup -getsecurewebproxy Wi-Fi | grep ^Enabled | cut -f 2 -d ' ')"
if [[ "$status" =~ 'no' ]]; then
anybar black
else
anybar white
fi
echo "$status"
}
publicip() {
curl https://api.ipify.org
}
alias c='caffeinate -d'
alias cta='caffeinate -d tmux at'
alias fliptable='echo (╯°□°)╯︵ ┻━┻'
alias lc='launchctl'
alias ll='ls -al'
alias lock='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
alias reload='. $HOME/.zshrc'
alias sound='afplay /System/Library/Sounds/Glass.aiff'
alias ssh_up='systemsetup -setremotelogin on'
alias ssh_down='systemsetup -setremotelogin off'
source_invision() {
. ~/Code/InVision_Docker/scripts-native/invision.sh
}
# Tmux
alias tmux='tmux -2'
if [[ -n "$TMUX" ]]; then
refresh() {
export "$(tmux show-environment | grep '^SSH_AUTH_SOCK')"
}
else
refresh() { exit 1; }
fi
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# bun completions
[ -s "$HOME/.bun/_bun" ] && source "$HOME/.bun/_bun"
# Bun
export BUN_INSTALL="$HOME/.bun"
start-dev() {
AWS_ACCESS_KEY_ID="$(op item get "Jeli AWS" --fields id)" AWS_SECRET_ACCESS_KEY="$(op item get "Jeli AWS" --fields secret)" aws ec2 start-instances --instance-ids "$(op item get "Jeli AWS" --fields instance)"
}
stop-dev() {
AWS_ACCESS_KEY_ID="$(op item get "Jeli AWS" --fields id)" AWS_SECRET_ACCESS_KEY="$(op item get "Jeli AWS" --fields secret)" aws ec2 stop-instances --instance-ids "$(op item get "Jeli AWS" --fields instance)"
}
show-path() {
echo $PATH | tr : '\n'
}
alias dev="nocorrect dev"