-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
317 lines (250 loc) · 7.86 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
#
# Aliases/Commands
#
# dotfiles (git alias)
alias dot='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
# git
alias gs='git status'
alias gsh='git stash'
alias gc='git commit -m'
alias gca='git commit --amend'
alias gcan='git commit --amend --no-edit'
alias gpsh='git push'
alias gpshu='git push --set-upstream origin HEAD'
alias gpl='git pull'
alias gplr='git pull --rebase'
alias ga='git add'
alias gd='git diff'
alias gr='git rebase'
alias gcl='git clone'
alias gch='git checkout'
alias gchb='git checkout -b'
alias grp='git remote prune origin'
alias gb='git branch'
# kubernetes
alias k='kubectl'
alias ka='kubectl apply -Rf'
alias kd='kubectl delete'
alias kg='kubectl get'
alias kl='kubectl logs'
alias kc='kubectl config current-context'
alias kx='kc | cut -d "_" -f 4'
alias ku='kubectl config use-context'
# kubernetes (switch context)
ks() {
if [[ $(kx) == "prod" ]] ; then
ku $(kc | cut -d "_" -f 1-3)_staging
else
ku $(kc | cut -d "_" -f 1-3)_prod
fi
}
# ls
alias la='ls -la'
# python
alias activate='source $(poetry env info | sed -n 5p | cut -d ":" -f 2 | xargs)/bin/activate; export PYTHONPATH=$PYTHONPATH:$(pwd)'
# render markdown to browser
rndr-md() {
markdown $1 > $1.html;
open $1.html;
rm $1.html;
}
# tmux
alias tx='tmux -2'
alias tn='tmux new -s'
alias ta='tmux a -t'
alias tk='tmux kill-server'
alias tks='tmux kill-session -t'
alias tl='tmux ls'
# tmux 2 pane
tx2() {
tmuxn $1 -d;
tmux split-window -h;
tmux -2 attach-session -d;
}
# tmux 3 pane
tx3() {
tmuxn $1 -d;
tmux split-window -h;
tmux split-window -h;
tmux select-layout even-horizontal;
tmux -2 attach-session -d;
}
# Typescript development set up
# Adapted from : http://ryan.himmelwright.net/post/scripting-tmux-workspaces/
ts-init() {
# set session name
SESSION=$1
SESSIONEXISTS=$(tmux list-sessions | grep $SESSION)
# only create tmux session if it doesn't already exist
if [ "$SESSIONEXISTS" = "" ]
then
# start new session with our name
tmux new-session -d -s $SESSION
# zsh window
tmux rename-window -t 0 'Main'
tmux send-keys -t 'Main' 'zsh' C-m 'clear' C-m # Switch to bind script?
# typescript build watch window
tmux new-window -t $SESSION:1 -n 'Build'
tmux send-keys -t 'Build' 'yarn run buildWatch' C-m # Switch to bind script?
# typescript lint watch window
tmux new-window -t $SESSION:2 -n 'Lint'
tmux send-keys -t 'Lint' "yarn run lintWatch" C-m
# typescript test watch window
tmux new-window -t $SESSION:3 -n 'Test'
tmux send-keys -t 'Test' "yarn run testWatch" C-m 'clear' C-m
fi
# attach session on the main window
tmux attach-session -t $SESSION:0
}
# util
alias sz='source ~/.zshrc'
alias timestamp='date -u "+%Y-%m-%dT%H:%M:%S"'
alias private_key='openssl rand -hex 32'
# vim
alias v='nvim'
alias vi='nvim'
#
# -> Start zsh configuration
#
### Setup
ZIM_HOME=~/.zim
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
curl -fsSL --create-dirs -o ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
### History
# Remove older command from the history if a duplicate is to be added.
setopt HIST_IGNORE_ALL_DUPS
### Input/output
# Set editor default keymap to emacs (`-e`) or vi (`-v`)
bindkey -v
# Prompt for spelling correction of commands.
setopt CORRECT
# Customize spelling correction prompt.
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
# Remove path separator from WORDCHARS.
WORDCHARS=${WORDCHARS//[\/]}
### Module configuration
## completion
# Set a custom path for the completion dump file.
# If none is provided, the default ${ZDOTDIR:-${HOME}}/.zcompdump is used.
zstyle ':zim:completion' dumpfile "${ZDOTDIR:-${HOME}}/.zcompdump-${ZSH_VERSION}"
## git
# Set a custom prefix for the generated aliases. The default prefix is 'G'.
# zstyle ':zim:git' aliases-prefix 'g'
## input
# Append `../` to your input for each `.` you type after an initial `..`
zstyle ':zim:input' double-dot-expand yes
## termtitle
# Set a custom terminal title format using prompt expansion escape sequences.
# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes
# If none is provided, the default '%n@%m: %~' is used.
zstyle ':zim:termtitle' format '%1~'
## zsh-autosuggestions
# Customize the style that the suggestions are shown with.
# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10'
## zsh-syntax-highlighting
# Set what highlighters will be used.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
# Customize the main highlighter styles.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[comment]='fg=10'
### Initialize modules
if [[ ${ZIM_HOME}/init.zsh -ot ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
# Update static initialization script if it's outdated, before sourcing it
source ${ZIM_HOME}/zimfw.zsh init -q
fi
source ${ZIM_HOME}/init.zsh
### Post-init module configuration
## zsh-history-substring-search
# Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
# Bind up and down keys
zmodload -F zsh/terminfo +p:terminfo
if [[ -n ${terminfo[kcuu1]} && -n ${terminfo[kcud1]} ]]; then
bindkey ${terminfo[kcuu1]} history-substring-search-up
bindkey ${terminfo[kcud1]} history-substring-search-down
fi
bindkey '^P' history-substring-search-up
bindkey '^N' history-substring-search-down
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
#
# -> End zsh configuration
#
#
# PATH
#
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
export PATH="$HOME/.poetry/bin:$PATH"
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init - --path)"
export PATH="$PATH:/Users/dino/.foundry/bin"
export PATH="$PATH:/Users/dinorodriguez/.foundry/bin"
#
# FZF
#
# Layout from bottom
# Show preview window by pressing ?
# Customize colors & prompt
# Shortcuts when in fzf
export FZF_DEFAULT_OPTS="
--layout=reverse
--info=inline
--height=80%
--multi
--preview-window=:hidden
--preview '([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
--color='hl:148,hl+:154,pointer:032,marker:010,bg+:237,gutter:008'
--prompt='∼ ' --pointer='▶' --marker='✓'
--bind '?:toggle-preview'
--bind 'ctrl-a:select-all'
--bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'
--bind 'ctrl-e:execute(echo {+} | xargs -o vim)'
--bind 'ctrl-v:execute(code {+})'
"
# Show hidden files, follow links, exclude git and node_modules
export FZF_DEFAULT_COMMAND="fd --hidden --follow --exclude '.git' --exclude 'node_modules'"
# CTRL-T's command
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
# ALT-C's command
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND --type d"
# Use :: as the trigger sequence instead of the default **
export FZF_COMPLETION_TRIGGER='::'
# Override to use fd for fuzzy completion
_fzf_compgen_path() {
fd . "$1"
}
_fzf_compgen_dir() {
fd --type d . "$1"
}
# Source fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Find in file
fif() {
bash ~/.scripts/fif.sh
}
# Create widget for find in file
zle -N fif-widget fif
# Bind keys for widgets
# Alt-C
bindkey "ç" fzf-cd-widget
# Alt-Z
bindkey "Ω" fzf-file-widget
# Alt-X
bindkey "≈" fzf-history-widget
# Alt-S
bindkey "ß" fif-widget
# PYENV SHELL
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# NPM globals
export PATH="/Users/dino/.nvm/versions/node/v18.6.0/bin:$PATH"