-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zshrc
More file actions
373 lines (315 loc) · 9.92 KB
/
.zshrc
File metadata and controls
373 lines (315 loc) · 9.92 KB
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
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$HOME/scripts:$HOME/repos/ops/bin:$HOME/.local/bin:/usr/local/go/bin:$HOME/go/bin:$PATH
# dolphin file manager stuff
[ "$XDG_CURRENT_DESKTOP" = "KDE" ] || [ "$XDG_CURRENT_DESKTOP" = "GNOME" ] || export QT_QPA_PLATFORMTHEME="qt5ct"
export _JAVA_AWT_WM_NONREPARENTING=1
export HYDRA_URL=http://127.0.0.1:4444
export HYDRA_ADMIN_URL=http://127.0.0.1:4445
export GOPATH=$HOME/go
export PGROOT="/var/lib/postgres"
export ZSH="$HOME/.oh-my-zsh"
export FZF_DEFAULT_COMMAND="rg --files --hidden -g '!.git' -g '!documentation/chat'"
export REPO_BASE_DIRECTORY="$HOME/repos"
export DISCOURSE_REPO_BASE_DIRECTORY="$REPO_BASE_DIRECTORY/discourse"
export DOCKER_GATEWAY_HOST=172.17.0.1
export HUB_BASE_URL="http://localhost:4001/api"
export FZF_DOCKER_PS_FORMAT="table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Ports}}"
export FZF_DOCKER_PS_START_FORMAT="table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}"
export VIM_AUTOSPEC=1
export BAT_THEME="gruvbox-dark"
export RIPGREP_CONFIG_PATH="$HOME/.ripgrep"
export DISCOURSE_ALLOW_UNSECURE_CHAT_UPLOADS=1
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
export BROWSER="google-chrome-stable"
export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=10000000
export SAVEHIST=10000000
# Enter instead of ^M
stty icrnl
# zsh config
ZSH_THEME="robbyrussell"
plugins=(git fzf-docker)
source $ZSH/oh-my-zsh.sh
source $HOME/scripts/fzf-kill.plugin.zsh
alias rgno="rg --no-ignore $@"
alias kk="kill -9 **"
alias gosrc="cd $GOPATH/src"
alias gcdd="git checkout ."
alias rr="cd ~/repos"
alias rubyst="RUBYOPT=\"-W0\" bundle exec stree write --print-width=100 --plugins=plugin/trailing_comma $@"
alias chrome="chromium"
alias lspec="bat ~/scripts/last_spec.txt"
alias revfix="git commit -m \"DEV: Review fixes\""
alias specfix="git commit -m \"DEV: Test fix\""
alias lintfix="git commit -m \"DEV: Lint\""
alias amend="git commit --amend"
alias amendno="git commit --amend --no-edit"
alias amendpush="git commit --amend --no-edit && git push -f"
alias bimig="bundle install && RAILS_ENV=test bundle exec rake db:migrate && RAILS_ENV=development bundle exec rake db:migrate"
alias ddmaster="cd $REPO_BASE_DIRECTORY/master/discourse"
alias gpickaxe="git log -p -S $@"
alias rrm="fzf | xargs -I '{}' rm {}"
alias down="cd ~/Downloads"
alias ccat="pygmentize -f terminal256 -P style=monokai -g $@"
alias dwmcfg="forge && cd dwm && vim config.h"
alias dmenucfg="forge && cd dmenu && vim config.h"
alias stcfg="forge && cd st && vim config.h"
alias lsraw="/usr/bin/ls"
alias ls="ls --color=tty -lah"
alias spotify="/usr/bin/spotify --force-device-scale-factor=1.5"
alias chmx="chmod +x $@"
alias tt="tmux"
alias killconsul="kill -9 $(pidof consul)"
alias killnomad="kill -9 $(pidof nomad)"
alias forge="cd ~/forge"
alias ss="cd ~/scripts"
alias irb="pry"
alias dcu="docker-compose up"
alias mkdir="mkdir -p "
alias gfix="git add . && git commit"
alias escaps="setxkbmap -option caps:swapescape"
alias vimrc="vim ~/.vimrc"
alias nvimrc="cd ~/.config/nvim && nvim ."
alias debugspec="RAILS_ENABLE_TEST_LOG=true RAILS_TEST_LOG_LEVEL=debug bundle exec rspec $@"
alias debugspecwarn="RAILS_ENABLE_TEST_LOG=true RAILS_TEST_LOG_LEVEL=warn bundle exec rspec $@"
alias chmp="git checkout master && git pull"
alias chma="git checkout main && git pull"
alias annotatemodels="bundle exec annotate"
alias plugspec="IMPROVED_SPEC_DEBUGGING=1 LOAD_PLUGINS=1 be rspec $@"
alias mainfile="git checkout origin/main -- $@"
alias remotelist="git remote -v"
alias commit="git commit"
alias gco="git commit"
alias gk="git commit"
alias gcb="git checkout -b $@"
alias gcl="git checkout -"
alias gll="git checkout -"
alias gpl="git pull"
alias gvv="git pull"
alias gg="git status"
alias lefthooklint="npx lefthook run lints"
alias zshreload="source ~/.zshrc"
alias v="vim"
alias vimold="/usr/local/bin/vim"
alias vim="nvim"
alias zshconfig="vim ~/.zshrc; zshreload"
alias hyprconfig="vim ~/.config/hypr/hyprland.conf"
alias zshall="vim ~/.config/zsh; zshreload"
alias tmuxconfig="vim ~/.tmux.conf"
alias it="git"
alias rsearch="be rails routes | rg $@"
alias be="bundle exec"
alias bi="bundle install"
alias bb="bundle install"
alias bmig="bin/rails rails g migration $@"
alias pgsql="psql postgres"
alias brc="bin/rails c"
alias mrs="bundle exec rails s -p 3001"
alias mig="LOAD_PLUGINS=1 bundle exec rake db:migrate RAILS_ENV=test && LOAD_PLUGINS=1 bundle exec rake db:migrate"
alias mm="bundle exec rake db:migrate RAILS_ENV=test && bundle exec rake db:migrate"
alias rollback="bundle exec rake db:rollback RAILS_ENV=test && bundle exec rake db:rollback"
alias gadd='git add "$({ git --no-pager diff --name-only; git ls-files --others --exclude-standard } | fzf)"'
alias grest='git restore "$({ git --no-pager diff --name-only; git ls-files --others --exclude-standard } | fzf)"'
alias gp='git add -p'
alias gap='git add -p'
alias gapp='git add -p "$({ git --no-pager diff --name-only; git ls-files --others --exclude-standard } | fzf)"'
alias chkfile='git checkout -- "$({ git --no-pager diff --name-only; git ls-files --others --exclude-standard } | fzf)"'
alias gunstage='git reset "$(git --no-pager diff --name-only --cached | fzf)"'
alias gu='git reset "$(git --no-pager diff --name-only --cached | fzf)"'
alias gdiff='git --no-pager diff "$({ git --no-pager diff --name-only; } | fzf)"'
alias gdiffc='git --no-pager diff --cached "$({ git --no-pager diff --name-only --cached; } | fzf)"'
alias vopen='vim $(fzf)'
alias cdiff="git diff-tree -p $@"
alias gmm="git merge main --no-edit"
alias gsl="git stash list"
alias fzcp="fzf | tr -d '\n' | xclip -selection clipboard"
cdd() {
cd $(fd --type directory | fzf)
}
cc() {
cd $(fd -i -I -t d -d 1 . $HOME/repos | fzf)
}
cdgems() {
cd $(fd -i -I -t d -d 1 . $HOME/.gem/ruby/2.7.5/gems | fzf)
}
cdr() {
cd $(fd -i -I -t d -d 1 . $HOME/repos | fzf)
}
cdc() {
cd $(fd -i -I -t d -d 1 . $HOME/repos/client-work | fzf)
}
cdf() {
cd $(fd -i -I -t d -d 1 . $HOME/forge | fzf)
}
cdb() {
cd $(fd -i -I -t d -d 1 . $HOME/bin | fzf)
}
cda() {
cd $(fd -i -I -t d -d 1 . $HOME | fzf)
}
lastcommitmsg() {
git log -1 --pretty=%B | sed -z 's/\n/ /g' | sed -z 's/ / /g'
}
chk() {
local branches branch
branches=$(git branch -a) &&
branch=$(echo "$branches" | fzf +s +m -e) &&
git checkout $(echo "$branch" | sed "s:.* remotes/origin/::" | sed "s:.* ::")
}
runmany() {
number=$1
shift
for i in `seq $number`; do
$@
done
}
chkpr() {
git fetch origin pull/$@/head:pr/$@ && git checkout pr/$@
}
branchlog() {
git --no-pager log --no-merges master..$(git rev-parse --abbrev-ref HEAD) --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cD) %C(bold blue)<%an>%Creset' --abbrev-commit
}
gpush() {
git push --set-upstream origin "$(git branch | grep \* | cut -d ' ' -f2)"
}
gpushr() {
gpush && gh pr create -w -f
}
ghprc() {
gh pr create -w -f
}
gblameline() {
git blame -L$1,$1 -- $2
}
scratchfile() {
vim ~/scratch/$(echo $(date +%Y-%m-%d-%H-%M-))$@.md
}
newscript() {
touch $1 && chmod +x $1
}
pasteimg() {
xclip -selection clipboard -t image/png -o > "$(date +%Y-%m-%d_%T).png"
}
cdgem() {
gempath=$(bundle show $@)
cd $gempath
}
commurl() {
local url=${$(git remote get-url origin)//git@github.com:/https://github.com/}
url=${url//.git//}
final="$url""commit/""$@"
echo $final | xclip -selection clipboard
}
dockerstop() {
docker stop $(docker ps -aq)
}
allplugrg() {
rg $1 ~/allthe/all-the-plugins
}
stashm() {
git stash push -m $@
}
stm() {
git add . && git stash push -m $@
}
gfl() {
git log -p $(fzf --preview 'bat --style=numbers --color=always --line-range :500 {}')
}
gclone() {
git clone "$1" && cd "$(basename $1)";
}
gclonerepo() {
git clone "git@github.com:$1"
}
dumptestdb() {
RAILS_ENV=test bin/rake db:drop db:create db:migrate
}
dumpparatestdb() {
RAILS_ENV=test bin/rake parallel:drop parallel:create parallel:migrate
}
cdgem() {
cd $(bundle show $1)
}
streefixer() {
bundle exec stree write $(git --no-pager diff --name-only --cached -- '*.rb')
}
comurl() {
echo "$(git config --get remote.origin.url | sed -e 's/\.git$//g' | sed -e 's/:/\//g' | sed -e 's/git@/https:\/\//g')/commit/$1"
}
pushsbx() {
local branch_name=$(git rev-parse --abbrev-ref HEAD)
local sandbox_branch="sandbox/$1"
git push -f origin $branch_name:$sandbox_branch
}
resetsbx() {
local sandbox_branch="sandbox/$1"
git push -f origin main:$sandbox_branch
}
gcbi() {
git checkout -b issue/$1
}
gcbf() {
git checkout -b feature/$1
}
gcbd() {
git checkout -b dev/$1
}
export EDITOR='vim'
if [ -S $SSH_AUTH_SOCK ]; then
ssh-add -l | grep "The agent has no identities" && ssh-add
fi
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Load seperated config files
for conf in "$HOME/.config/zsh/"*.zsh; do
source "${conf}"
done
unset conf
# Remove ctrl-t binding fzf
bindkey -r "^T"
bindkey -r "^[T"
# pnpm
export PNPM_HOME="/Users/mb/Library/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end
function current_dir() {
local current_dir=$PWD
if [[ $current_dir == $HOME ]]; then
current_dir="~"
else
current_dir=${current_dir##*/}
fi
echo $current_dir
}
function change_tab_title() {
zellij action rename-tab "$1" >/dev/null 2>&1
}
function set_tab_to_working_dir() {
local prefix="${1:-}"
local result=$?
if [[ -n $prefix ]]; then
change_tab_title "$prefix - $(current_dir)"
return
fi
change_tab_title "$(current_dir)"
}
function set_tab_to_command_line() {
local cmdline=$1
if [[ $cmdline == "nvim"* ]] || [[ $cmdline == "vim"* ]]; then
set_tab_to_working_dir "nvim"
return
fi
if [[ $cmdline == "claude"* ]]; then
set_tab_to_working_dir "claude"
return
fi
change_tab_title $cmdline
}
if [[ -n $ZELLIJ ]]; then
add-zsh-hook precmd set_tab_to_working_dir
add-zsh-hook preexec set_tab_to_command_line
fi