-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
284 lines (227 loc) · 8.4 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
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="spaceship"
source $HOME/.oh-my-zsh/custom/themes/spaceship.zsh-theme
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
[[ $TMUX = "" ]] && export TERM="screen-256color"
# disable tmux auto title
export DISABLE_AUTO_TITLE=true
# disable Ctrl-D so not to close terminal by accident
setopt ignoreeof
# to be able to ctrl-s in vim!
stty -ixon
# https://htmlhive.com/fixing-your-terminal-unix-history-command/
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTFILESIZE=1000000
export HISTSIZE=$HISTFILESIZE
export SAVEHIST=$HISTFILESIZE
export KEYTIMEOUT=1
# https://stackoverflow.com/questions/12247777/share-history-between-panes-windows
setopt inc_append_history # share history betweent tmux panes/windows
plugins=(bower brew git heroku node npm tmux tmuxinator emoji colored-man-pages docker docker-compose)
source $ZSH/oh-my-zsh.sh
source $HOME/.bin/tmuxinator.zsh
source $HOME/.shfiles/z.sh
[ -f $HOME/.fzf.zsh ] && source $HOME/.fzf.zsh
# source $HOME/.rvm/scripts/rvm
fpath=(/usr/local/share/zsh-completions $fpath)
# zsh docker plugin seems to run only with this command
# if insecure dirs warning comes up - run this -> compaudit | xargs chmod g-w
autoload -U compinit && compinit
# Set HOMEBREW dir for Apple Silicon vs Intel
export NVM_DIR="$HOME/.nvm"
if [[ $(uname -m) == 'arm64' ]]; then
export HOMEBREW_BIN="/opt/homebrew/bin"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# https://github.com/zsh-users/zsh-syntax-highlighting
source /opt/homebrew/opt/zsh-syntax-highlighting/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
export PATH=$HOMEBREW_BIN:$PATH # not needed to set in else path as usr/local/bin is part of $PATH already
else
export HOMEBREW_BIN="/usr/local/bin"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# https://github.com/zsh-users/zsh-syntax-highlighting
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
export MYVIMRC=$HOME/.vimrc
export MYNVIMRC=$HOME/.config/nvim/init.vim
export EDITOR='$HOMEBREW_BIN/nvim'
export VISUAL='$HOMEBREW_BIN/nvim'
export GIT_EDITOR='$HOMEBREW_BIN/nvim'
export MDV_THEME=579.6579
export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow --exclude '.git' --exclude 'node_modules'"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND --type d --hidden --follow --exclude '.git' --exclude 'node_modules'"
export FZF_COMPLETION_TRIGGER='``'
export FZF_COMPLETION_OPTS='+c -x'
export FZF_DEFAULT_OPTS='--extended --cycle --reverse'
# function below is required to respect .agignore for completion
_fzf_compgen_path() {
ag -g "" "$1"
}
# export PORT=3000
# Below is causing issue with Gogo Portal unit tests due to different code path in development - not good!
# Commenting the line below for now
# export NODE_ENV=development
export NODE_OLD_VERSION=6
export NODE_LATEST_VERSION=16
export NODE_GGS_VERSION=10
DIRSTACKSIZE=8
setopt autopushd pushdminus pushdsilent pushdtohome
function ggr() { grep "$1" ${@:2} -R . }
function mcd() { mkdir -p "$1" && cd "$1"; }
function cht() { curl cht.sh/$1 }
function gdd() {
case "$3" in
vim) nvim $(git diff HEAD~$1 HEAD~$2 --name-only) ;;
vimr) vimr $(git diff HEAD~$1 HEAD~$2 --name-only) ;;
tool) git difftool HEAD~$1 HEAD~$2 ${@:4} ;;
name) git diff HEAD~$1 HEAD~$2 --name-only ;;
*) git diff HEAD~$1 HEAD~$2 | delta -s ${@:3} ;;
esac
}
function cdnode() {
case "$1" in
6) cd ~/.nvm/versions/node/v6.17.1/lib/node_modules ;;
10) cd ~/.nvm/versions/node/v10.24.1/lib/node_modules ;;
12) cd ~/.nvm/versions/node/v12.22.12/lib/node_modules ;;
16) cd ~/.nvm/versions/node/v16.19.0/lib/node_modules ;;
*) cd ~/.nvm/versions/node/v16.19.0/lib/node_modules ;;
esac
}
function cdd() {
cd $(fd -t d "$1" | fzf)
}
function t() {
# Defaults to 3 levels deep, do more with `t 5` or `t 1`
# pass additional args after
local levels=${1:-3}; shift
tree -I '.git|node_modules|bower_components|.DS_Store' --dirsfirst -L $levels -aC $@
}
# google autocomplete
function c() { curl -sS "https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=$1" | json_pp | sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'; }
# pipe to h to highlight text in terminal
h() {
_usage() {
echo "usage: YOUR_COMMAND | h [-idn] args...
-i : ignore case
-d : disable regexp
-n : invert colors"
}
local _OPTS
# detect pipe or tty
if test -t 0; then
_usage
return
fi
# manage flags
while getopts ":idnQ" opt; do
case $opt in
i) _OPTS+=" -i " ;;
d) _OPTS+=" -Q " ;;
n) n_flag=true ;;
Q) _OPTS+=" -Q " ;;
# let's keep hidden compatibility with -Q for original ack users
\?) _usage
return ;;
esac
done
shift $(($OPTIND - 1))
# check maximum allowed input
if (( ${#@} > 12)); then
echo "Too many terms. h supports a maximum of 12 groups. Consider relying on regular expression supported patterns like \"word1\\|word2\""
exit -1
fi;
# set zsh compatibility
[[ -n $ZSH_VERSION ]] && setopt localoptions && setopt ksharrays && setopt ignorebraces
local _i=0
if [ -z $n_flag ]; then
#inverted-colors-last scheme
_COLORS=( "underline bold red" "underline bold green" "underline bold yellow" "underline bold blue" "underline bold magenta" "underline bold cyan" "bold on_red" "bold on_green" "bold black on_yellow" "bold on_blue" "bold on_cyan" "bold on_magenta" )
else
#inverted-colors-first scheme
_COLORS=( "bold on_red" "bold on_green" "bold black on_yellow" "bold on_blue" "bold on_magenta" "bold on_cyan" "bold black on_white" "underline bold red" "underline bold green" "underline bold yellow" "underline bold blue" "underline bold magenta" )
fi
# build the filtering command
for keyword in "$@"
do
local _COMMAND=$_COMMAND"ack $_OPTS --noenv --flush --passthru --color --color-match=\"${_COLORS[$_i]}\" '$keyword' |"
_i=$_i+1
done
#trim ending pipe
_COMMAND=${_COMMAND%?}
#echo "$_COMMAND"
cat - | eval $_COMMAND
}
rgv() {
nvim $(rg -l "$1" -g !"node_modules")
}
rgvi() {
nvim $(rg -li "$1" -g !"node_modules")
}
topc() {
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n${1:-20}
}
# ctrl-z to go back to suspended Vim
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
# work-around to fix bug in npm install, where it reports EMFILE or glob error
ulimit -n 2560
cdf() {
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
if [ "$target" != "" ]; then
cd "$target"; pwd
else
echo 'No Finder window found' >&2
fi
}
# curl commands
weather() { curl wttr.in/"$@"; }
cheat() { curl cheat.sh/"$@"; }
crypto() { curl rate.sx }
# ---------------------------- OSX only ----------------------------- #
case `uname` in
Darwin)
export NOTES_DIR=$HOME/Dropbox/NOTES
;;
Linux)
export LANG=en_US.UTF-8
export SHELL=/opt/homebrew/bin/zsh
# Linuxbrew
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
;;
esac
# bin for python2
export PATH="${HOME}/.pyenv/shims:${PATH}"
# ruby - bin path and settings
export PATH="$HOME/.gem/ruby/2.6.0/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
# load aliases
if [ -f ~/.aliases ]; then
. ~/.aliases
fi
# load gogoenv
if [ -f ~/.gogoenv.sh ]; then
. ~/.gogoenv.sh
fi
# Set bat/cat theme
export BAT_THEME=ansi
export QMK_HOME=$HOME/dev/mechanicalkeyboards/qmk_firmware
# Set less to search case-insensitive
export LESS=-iR
fpath=($fpath "/Users/felipe/.zfunctions")
fpath=($fpath "/Users/felipe/.zfunctions")
cd ~/Documents/projects/portalui/portal