-
Notifications
You must be signed in to change notification settings - Fork 1
/
dot_zshrc
276 lines (221 loc) · 6.39 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
#zmodload zsh/zprof
#
# Oh My ZSH config
#
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="spaceship"
#
# Spaceship prompt
#
SPACESHIP_DIR_PREFIX="🦊 "
SPACESHIP_JOBS_SYMBOL="🔧"
SPACESHIP_PROMPT_ADD_NEWLINE=false
SPACESHIP_PROMPT_DEFAULT_PREFIX=
SPACESHIP_PROMPT_FIRST_PREFIX_SHOW=true
SPACESHIP_VI_MODE_SHOW=false
# AWS
SPACESHIP_AWS_PREFIX=
SPACESHIP_AWS_SYMBOL=
# custom AWS region section
SPACESHIP_AWS_REGION_SHOW=true
SPACESHIP_AWS_REGION_PREFIX=
SPACESHIP_AWS_REGION_SUFFIX=" "
SPACESHIP_AWS_REGION_SYMBOL=
SPACESHIP_AWS_REGION_COLOR=208
spaceship_aws_region() {
# do not show if false
[[ $SPACESHIP_AWS_REGION_SHOW == false ]] && return
local region=${AWS_DEFAULT_REGION}
# exit if not set
[[ -z $region ]] && return
# show prompt section
spaceship::section \
"$SPACESHIP_AWS_REGION_COLOR" \
"$SPACESHIP_AWS_REGION_PREFIX" \
"${SPACESHIP_AWS_REGION_SYMBOL}${region}" \
"$SPACESHIP_AWS_REGION_SUFFIX"
}
# Docker
SPACESHIP_DOCKER_CONTEXT_SHOW=false
# GCP
SPACESHIP_GCLOUD_PREFIX=
SPACESHIP_GCLOUD_SHOW=false
# GIT
SPACESHIP_GIT_PREFIX=
# Golang
SPACESHIP_GOLANG_SHOW=false
# Kubernetes
SPACESHIP_KUBECONTEXT_SHOW=true
SPACESHIP_KUBECTL_VERSION_SHOW=false
SPACESHIP_PROMPT_ORDER=(
user # Username section
dir # Current directory section
git # Git section (git_branch + git_status)
aws # Amazon Web Services section
aws_region # CUSTOM: show AWS region
kubectl_context # Kubectl context section
venv # virtualenv section
terraform # Terraform workspace 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
)
#
# Completion plugin config
#
COMPLETION_WAITING_DOTS="true"
#
# TMUX plugin config
#
# enable autostart only if not running on i3
[ ! -z "$(pgrep '^i3$')" ] && ZSH_TMUX_AUTOSTART=false || ZSH_TMUX_AUTOSTART=true
export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/local/games:/usr/games:$HOME/.cargo/bin:$HOME/.bin:$HOME/.scripts:$HOME/.local/bin:$PATH:$HOME/.arkade/bin"
plugins=(aws git ssh-agent tmux kubectl docker history-substring-search fasd zsh-autosuggestions zsh-syntax-highlighting)
SHOW_AWS_PROMPT=false
#
# User config
#
#
# Functions
#
keyadd() {
KEY_PREFIX='_key-'
ssh-add ~/.ssh/${KEY_PREFIX}${1}/id_rsa || ssh-add -L
}
osx() {
[ $(uname) = 'Darwin' ]
}
linux() {
[ $(uname) = 'Linux' ]
}
fixssh() {
for key in SSH_AUTH_SOCK SSH_CONNECTION SSH_CLIENT; do
if (tmux show-environment | grep "^${key}" > /dev/null); then
value=`tmux show-environment | grep "^${key}" | sed -e "s/^[A-Z_]*=//"`
export ${key}="${value}"
fi
done
}
rmtrailspaces() {
sed -i 's/[[:space:]]\+$//' $1
}
#
# Exports
#
source $ZSH/oh-my-zsh.sh
linux && export VIM_EXECUTABLE=$(which nvim.appimage)
osx && export VIM_EXECUTABLE=$(which nvim)
export GIT_AUTHOR_NAME="Riccardo M. Cefala"
export GIT_AUTHOR_EMAIL="[email protected]"
export GIT_COMMITTER_NAME="Riccardo M. Cefala"
export GIT_COMMITTER_EMAIL="[email protected]"
export EDITOR=$VIM_EXECUTABLE
osx && export VIMRUNTIME=/usr/local/Cellar/neovim/0.5.0/share/nvim/runtime
# revert ls quoting behaviour introduced in coreutils 8.25
export QUOTING_STYLE=literal
#
# Golang
#
export GOROOT=$HOME/go
export GOPATH=$HOME/Development/golang
osx && export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
#
# Python (virtualenvwrapper)
#
export WORKON_HOME=$HOME/.virtualenvs
linux && source /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh
osx && export PATH=$PATH:$HOME/Library/Python/3.9/bin
#
# Google Cloud SDK
#
#source ~/opt/google-cloud-sdk/path.zsh.inc
#source ~/opt/google-cloud-sdk/completion.zsh.inc
#
# Gradle
#
export PATH=$HOME/opt/gradle-4.5.1/bin:$PATH
#
# Aliases
#
alias mypublicip='wget http://ipinfo.io/ip -qO -'
alias vim=$VIM_EXECUTABLE
linux && alias pbcopy='xsel --clipboard --input'
linux && alias pbpaste='xsel --clipboard'
linux && alias vpnup='nmcli c up riccardo_teal --ask'
linux && alias vpndown='nmcli c down riccardo_teal'
# kubectl
alias k='kubectl'
alias kns='k get namespaces'
path+=~/.krew/bin
# Openfiles quick in vim with FASD
alias v='f -e nvim.appimage'
# grep through history
alias hg="history | grep"
# chezmoi
alias cm=chezmoi
#
# Completion - aws, ssh, ...
#
fpath+=~/.oh-my-zsh/custom/functions
linux && source ~/.local/bin/aws_zsh_completer.sh
autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
osx && complete -C $(which aws_completer) aws
# ssh host completion
[ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
hosts=(
"$_ssh_hosts[@]"
"$_etc_hosts[@]"
`hostname`
localhost
)
zstyle ':completion:*:hosts' hosts $hosts
# enable vim bindings
bindkey -v
export KEYTIMEOUT=1
bindkey "^I" expand-or-complete-with-dots #fix dot completion
# backward and forward history search
bindkey '^r' history-incremental-pattern-search-backward
bindkey '^t' history-incremental-pattern-search-forward
# Ctrl+space: print Git status
bindkey -s '^s' 'git status^M'
# Fix home end keys
bindkey "^a" beginning-of-line
bindkey "^e" end-of-line
bindkey "^u" backward-kill-line
bindkey "^k" kill-line
bindkey "^w" backward-kill-word
bindkey "^p" kill-word
bindkey "^[OH" beginning-of-line
bindkey "^[OF" end-of-line
bindkey "^[[1~" beginning-of-line
bindkey "^[[4~" end-of-line
bindkey "^[[3~" delete-char
#
# Nike
#
path+="$HOME/Development/gimme-aws-creds/bin"
#
# NPM
#
# https://stackoverflow.com/a/13021677
#
# NPM packages in homedir
NPM_PACKAGES="$HOME/.npm-packages"
# Tell our environment about user-installed node tools
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath` command
unset MANPATH # delete if you already modified MANPATH elsewhere in your configuration
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
# Tell Node about these packages
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
#zprof