-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshrc
312 lines (265 loc) · 8.35 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
if [ -f $HOME/xterm-256color-italic.ti ]; then
export TERM="xterm-256color-italic"
else
export TERM="xterm-256color"
fi
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
# eval "$(starship init zsh)"
fpath+=~/.zfunc
fpath=("/usr/local/bin/" $fpath)
setopt AUTO_CD
setopt MULTIOS
setopt AUTO_PUSHD
setopt AUTO_NAME_DIRS
setopt GLOB_COMPLETE
setopt PUSHD_MINUS
setopt PUSHD_TO_HOME
setopt PUSHD_IGNORE_DUPS
setopt RM_STAR_WAIT
setopt ZLE
setopt NO_HUP
setopt IGNORE_EOF
setopt NO_FLOW_CONTROL
setopt NO_CLOBBER
setopt NO_CASE_GLOB
setopt NUMERIC_GLOB_SORT
setopt EXTENDED_GLOB
setopt RC_EXPAND_PARAM
# Zinit -----------------------------------------------{{{{
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
print -P "%F{33}▓▒░ %F{220}Installing DHARMA Initiative Plugin Manager (zdharma/zinit)…%f"
command mkdir -p "$HOME/.zinit" && command chmod g-rwX "$HOME/.zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.zinit/bin" && \
print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \
print -P "%F{160}▓▒░ The clone has failed.%f%b"
fi
source "$HOME/.zinit/bin/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
zinit light zsh-users/zsh-autosuggestions
zinit light zdharma-continuum/fast-syntax-highlighting
# }}}}
eval "$(starship init zsh)"
# aliases ---------------------------------------------{{{{
alias k=kubectl
alias d=docker
alias rtest='bundle exec rspec'
alias gpu=push_upstram_origin
alias mk=make
alias kali='docker run -it --rm kalilinux/kali-linux-docker'
alias ubuntu='docker run -it --rm dockerfile/ubuntu'
alias rsa='railgun status -a -H -o name | xargs -n1 railgun stop'
alias ll='eza -bghHliSa'
alias py='python'
# alias tmux='tmux -2'
alias gitset='git push --set-upstream'
if [ -n $TMUX ]; then
alias vim="TERM=screen-256color vim"
fi
alias disableChrome='defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool FALSE'
alias tf='terraform'
alias bsl='brew services list'
alias so='source'
alias o=open
alias sync_branches='git fetch --all --prune && git branch -vv --no-color | grep "\[.*: gone\]" | awk "{print \$1}" | xargs git branch -D'
source ~/.aliases
# }}}}
command -v fzf > /dev/null && source <(fzf --zsh)
export FZF_DEFAULT_OPTS='--extended'
if command -v fd > /dev/null; then
export FZF_DEFAULT_COMMAND='fd --type file'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
fi
export GPG_TTY=$(tty)
export PYENV_ROOT="$HOME/.pyenv"
export GOPATH=$HOME/src/github.com
export PATH=$GOPATH/bin:$PATH
export PATH="$PYENV_ROOT/bin:$PATH"
export PATH=$PATH:$HOME/swap
export PATH="$HOME/src/github.com/abdulwahaab710/dotfiles/bin:$PATH"
export PATH="$HOME/.config/zsh/fp:$PATH"
export CHEATCOLORS=true
export EDITOR=nvim
export VISUAL=nvim
export GIT_EDITOR="nvim"
export LANG="en_US.UTF-8"
export KUBECONFIG=$HOME/.kube/config
# functions -------------------------------------------{{{{
update() {
sudo softwareupdate -i -a
brew update
brew upgrade --all
brew cask upgrade --all
brew cleanup
sudo gem update --system
sudo gem update
}
s() {
branch="$(git branch | fzf-tmux -p --reverse --query="$1" --select-1 --exit-0)"
if [ ! -z $branch ]
then
BRANCH_NAME="$(echo -e "${branch}" | sed -e 's/^[[:space:]]*//')"
git checkout $BRANCH_NAME
fi
}
sr() {
branch="$(git branch -a | fzf-tmux -p --reverse --query="$1" --select-1 --exit-0)"
if [ ! -z $branch ]
then
BRANCH_NAME="$(echo -e "${branch}" | sed -e 's/^[[:space:]]*//')"
git checkout $BRANCH_NAME
fi
}
ts() {
session="$(tmux ls | fzf-tmux -p --reverse --query="$1" --select-1 --exit-0)"
if [ ! -z $session ]
then
SESSION_NAME="$(echo -e "${session}" | sed -e 's/^[[:space:]]*//' | sed -e 's/: .*//')"
tmux attach -t $SESSION_NAME
fi
}
git-nvim() {
git status -s -u | fzf -m --ansi --preview-window "right:33%" --preview "echo {} | cut -d' ' -f 3 | xargs head -$LINES" | cut -d' ' -f 3 | xargs nvim
}
push_upstram_origin() {
BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD)"
if [ ! -z $BRANCH_NAME ]
then
git push origin -u $BRANCH_NAME
fi
}
sp() {
DIRECTORIES=$((cd ~/src/github.com ;ls -dl1 */**) | rg '[^/;]+/[^/;]+$' -o);
PROJECT_NAME=$(echo $DIRECTORIES | fzf-tmux -p --reverse --query="$1" --select-1 --exit-0)
if [ ! -z $PROJECT_NAME ]
then
cd "$HOME/src/github.com/$PROJECT_NAME"
fi
}
swap_file_names() {
first_file=$1
second_file=$2
tmp_name="tmp:$first_file+$second_file"
mv $first_file $tmp_name
mv $second_file $first_file
mv $tmp_name $second_file
}
unalias g 2>/dev/null
g() {
if [[ $# > 0 ]]; then
git $@
else
git status
fi
}
tn() {
if [[ $# > 0 ]]; then
tmux new -s $@
else
tmux new -s ${PWD##*/}
fi
}
rm_orig() {
find . -name *.orig | xargs rm
}
compdef g=git
docker_clean_all() {
alias docker_clean_images='docker rmi $(docker images -a --filter=dangling=true -q)'
alias docker_clean_ps='docker rm $(docker ps --filter=status=exited --filter=status=created -q)'
docker kill $(docker ps -q) 2>/dev/null
docker_clean_ps 2>/dev/null
docker_clean_images 2>/dev/null
docker rmi $(docker images -a -q) 2>/dev/null
}
fm() {
if [[ $# > 0 ]]; then
CURRENT_DIR=$(pwd) vifm $@
else
CURRENT_DIR=$(pwd) vifm .
fi
}
searchAllGit() {
{
find .git/objects/pack/ -name "*.idx" |while read i;do
git show-index < "$i"|awk '{print $2}'
done
find .git/objects/ -type f|grep -v '/pack/'|awk -F'/' '{print $(NF-1)$NF}';
}|while read o;do
git cat-file -p $o
done|grep -E $@
}
docker-shell() {
shell=${1:-bash}
container=$(docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Ports}}\t{{.Command}}" | tail -n+2 | fzf | cut -d ' ' -f1)
if [[ ! -z "$container" ]]; then
docker exec -it $container $shell
fi
}
vimwiki () {
if [[ $# == 0 ]]
then
nvim +'VimwikiIndex'
elif [[ $1 == 'git' ]]
then
git -C ~/vimwiki/ ${@:2}
else
echo 'Usage: vimwiki [git] [args ...]'
fi
}
# Bindkeys --------------------------------------------{{{
bindkey -s '^f' "$HOME/src/github.com/abdulwahaab710/dotfiles/bin/.local/tmux-sessionizer^M"
# bindkey -s '^d' "tmux display-popup -E -h 80% -w 80% \"nvim -c VimwikiMakeDiaryNote; exit\"^M"
bindkey -s jj '\e'
autoload edit-command-line; zle -N edit-command-line
bindkey '^e' edit-command-line
# Who doesn't want home and end to work?
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
# Incremental search is elite!
bindkey -M vicmd "/" history-incremental-search-backward
bindkey -M vicmd "?" history-incremental-search-forward
# Search based on what you typed in already
bindkey -M vicmd "//" history-beginning-search-backward
bindkey -M vicmd "??" history-beginning-search-forward
bindkey "\eOP" run-help
# oh wow! This is killer... try it!
bindkey -M vicmd "q" push-line
# it's like, space AND completion. Gnarlbot.
bindkey -M viins ' ' magic-space
# }}}
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
[[ -f /opt/homebrew/opt/chruby/share/chruby/chruby.sh ]] && ! (type chruby > /dev/null 2>&1) && chruby () { source /opt/homebrew/opt/chruby/share/chruby/chruby.sh }
type chruby >/dev/null 2>&1 && chruby; chruby 3
[ -f "$HOME/.zshrc.work" ] && source "$HOME/.zshrc.work"
[ -f "$HOME/.zshrc.local" ] && source "$HOME/.zshrc.local"
if [ -e /Users/abdulwahaabahmed/.nix-profile/etc/profile.d/nix.sh ]; then . /Users/abdulwahaabahmed/.nix-profile/etc/profile.d/nix.sh; fi # added by Nix installer
### End of Zinits installer chunk
[[ -x /opt/homebrew/bin/brew ]] && eval $(/opt/homebrew/bin/brew shellenv)
function nvims() {
items=("default" $(ls ~/.config | rg 'nvim-'))
config=$(printf "%s\n" "${items[@]}" | fzf --prompt=" Neovim Config " --height=~50% --layout=reverse --border --exit-0)
if [[ -z $config ]]; then
echo "Nothing selected"
return 0
elif [[ $config == "default" ]]; then
config=""
fi
NVIM_APPNAME=$config nvim $@
}
function switch_nvim_config() {
items=("default" $(ls ~/.config | rg 'nvim-'))
config=$(printf "%s\n" "${items[@]}" | fzf --prompt=" Neovim Config " --height=~50% --layout=reverse --border --exit-0)
if [[ -z $config ]]; then
echo "Nothing selected"
return 0
elif [[ $config == "default" ]]; then
config=""
fi
export NVIM_APPNAME=$config
}
# bindkey -s ^a "nvims\n"