-
Notifications
You must be signed in to change notification settings - Fork 5
/
.zshenv
918 lines (891 loc) · 23.6 KB
/
.zshenv
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
###########################
### Aliases / Functions ###
###########################
# Aliases are in this .zshenv file to make them work in VIM's non-interactive shell
VIM_EDITOR=nvim
MAIN_EDITOR=$VIM_EDITOR
# Unix
alias ls='ls -G'
alias ll='ls -lh'
alias la='ls -A'
alias lla='ll -A'
alias lld='ll -d'
alias llrt='ll -rt'
alias llart='lla -rt'
alias rm='rm'
alias rmrf='rm -rf'
# alias grep='grep --color=auto'
alias cpr='cp -r'
.() {
if [[ $# -eq 0 ]]; then
cd .
else
source "$@"
fi
}
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
v() {
if [[ $# -eq 1 && -d $1 ]]; then
(cd $1; $VIM_EDITOR .)
else
$VIM_EDITOR "$@"
fi
}
alias v.='v .'
alias vi=v
alias vi.=v.
alias vim=v
alias vim.=v.
alias vimdiff="$VIM_EDITOR -d"
alias vd=vimdiff
dif() { colordiff -u $@ | less }
mkcd() { mkdir $1 && cd $1 }
alias dush='du -sh'
alias path='echo $PATH | tr -s ":" "\n"'
alias psgrep='pstree | grep'
psgrepp() {
grep $@ =(pstree | cut -c-$COLUMNS)
}
alias el=elinks
remove-colors() {
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
}
alias md5sum=md5
alias wcl='wc -l'
alias ct.='ctags -f .tags -R .'
alias chx='chmod +x'
ed() { command ed -p '*' "$@" }
alias wh='which'
alias cmd='command'
prepend() {
local text_to_prepend="$1"
local file=$2
local tmp_file="tmp_$file"
echo "Prepend\n"
echo "$text_to_prepend\n"
read -q "answer?to $file? "
echo "\n"
if [[ $answer != "y" ]]; then; return; fi
echo 'Prepending...'
echo $text_to_prepend > $tmp_file
cat $file >> $tmp_file
mv $tmp_file $file
echo 'Done'
}
# Confs
al() {
if [[ $# -eq 0 ]]; then
$MAIN_EDITOR ~/.zshenv
else
alias $1
if [[ $? -ne 0 ]]; then; which $1; fi
fi
}
alias conf="$MAIN_EDITOR ~/.zshrc"
alias sec="$MAIN_EDITOR ~/.secrets.zsh"
alias reload='. ~/.zshrc; . ~/.zshenv; . ~/.secrets.zsh'
alias rl='reload'
alias rel='reload'
alias i='arch -x86_64 zsh'
# Zsh
alias dirs='dirs -v'
alias '1'='cd -'
alias '2'='cd -2'
alias '3'='cd -3'
alias '4'='cd -4'
alias '5'='cd -5'
alias 6='cd -6'
alias 7='cd -7'
alias 8='cd -8'
alias 9='cd -9'
alias '--' -='cd -'
# Tmux
alias tl='tmux ls'
alias td='tmux detach'
alias kt='killall tmux'
t() {
if [[ $# -eq 0 ]]; then
tmux-start
else
tmux "$@"
fi
}
tmux-start() {
if (tmux ls | grep base | grep attached) &> /dev/null; then
tmux-new-unnamed-session
else
tmux new -As base
fi
}
tmux-new-unnamed-session() {
local i=1
while (tmux has-session -t $i 2> /dev/null); do; let i=i+1; done
tmux new -s $i
}
tn() {
if [[ $# -eq 0 ]]; then
tmux new
else
tmux new -s $1
fi
}
tk() {
if [[ $# -eq 0 ]]; then
tmux kill-session
else
for session in "$@"; do
tmux kill-session -t $session
done
fi
}
ta() {
if [[ $# -eq 0 ]]; then; tmux attach; fi
if [[ -z $TMUX ]]; then
tmux attach -t "=$1"
else
tmux switch -t "=$1"
fi
}
ts() {
if [[ $# -eq 0 ]]; then
tmux start-server \; source ~/.tmux.conf
return
fi
tmux start-server \; source ~/.tmux/sessions/$1.conf
ta $1
}
tgo() {
tmux new-session -d -s go
tmux send-keys -t go "cd $(pwd)" C-m
tmux send-keys -t go 'ts rails' C-m
tmux send-keys -t go 'ggo' C-m
ta go
}
to() {
if [[ $# -ne 1 ]]; then; return; fi
ta $1 2> /dev/null && return
local session_file=~/.tmux/sessions/$1.conf
if [[ -f $session_file ]]; then
ts $1
else
tmux new -d -s $1
ta $1
fi
}
trn() {
tmux rename-window $1
export TMUX_AUTOMATIC_RENAME=off
}
# Git
alias gi='git init'
alias ginit='git init'
alias gl='git pull --rebase --prune'
alias glall='ls | xargs -P10 -I{} git -C {} pull --rebase --prune'
alias gs='git status'
alias gc='git commit'
alias ga='git add'
alias gaa='git add --all'
alias gaac='gaa && gc'
alias gbr='gb -r'
alias gca='gc --amend'
alias gca!='gca --no-edit'
alias gaaca='gaa && gca'
alias gaaca!='gaa && gca!'
alias gaacapf!='gaaca! && gpf'
alias gaacm='gaa && gcm'
alias gic='gaacm Initial commit'
alias gci='gic'
alias gco='git checkout'
alias gcob='gco -b'
alias gc-='gco -'
alias gco-='gco -'
alias gcom='gco master --'
alias gcl='git clone'
alias gclone='git clone'
gg() {
local last_command=$history[$((HISTCMD-1))]
cd $(git_repo $last_command)
}
git-repo() {
echo $1 | sed 's/.git$//' | sed 's/\/$//' | awk -F/ '{print $NF}'
}
ggcl() {
local git_repo=$(git-repo $1)
gcl "$@"
cd $git_repo
}
alias gclg='ggcl'
gclv() {
local git_repo=$(git-repo $1)
gcl "$@"
v $git_repo
}
ggclv() {
ggcl "$@"
v.
}
ex() {
[ $# -eq 0 ] && return
local git_repo=$(git-repo $1)
cd ~/c/tmp
if [[ -d $git_repo ]]; then
cd $git_repo
v.
else
ggclv "$@"
fi
}
alias e='ex'
alias gm='git merge'
alias gm-='git merge -'
alias gmabort='git merge --abort'
gcm() {
if [[ $# -eq 0 ]]; then
git checkout $(git-main-branch)
else
gc -m "$*"
fi
}
git-main-branch() {
if [[ $(git branch --list 'main') ]]; then echo 'main'; else echo 'master'; fi
}
gcam() { gca -m "$*" }
alias gce='gc --allow-empty -m "Empty commit"'
gcem() { gc --allow-empty -m "$*" }
alias gclean='git clean -fd'
alias grhhc='grhh && gclean'
gd() {
if [[ $# -eq 0 ]]; then
gd HEAD
else
git diff "$@" | format-git-diff | eval $GIT_PAGER
fi
}
format-git-diff() {
sed -r "s/^([^-+ ]*)[-+ ]/\\1/"
}
alias gdiff='git diff'
gsh() {
git show "$@" | format-git-diff | eval $GIT_PAGER
}
alias gdc='gd --cached'
alias gdh='gd HEAD'
alias "gdh^"="gd 'HEAD^'"
alias glog='git log'
alias glo="git log --format=format:'%C(yellow)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)'"
alias glod="glo --date=format-local:'%a %b %d %Y %H:%M' --format=format:'%C(yellow)%h%C(reset) - %C(bold green)(%ad)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)'"
alias gloa='glo --author=jerome'
alias gloda='glod --author=jerome'
alias gload='gloda'
alias lw='gload --since="last Monday midnight"'
glop() {
glo -p "$@" | format-git-diff | eval $GIT_PAGER
}
alias gloo='git log --all --oneline --no-merges'
alias gloS='glo -S'
alias glo-='glo --'
alias gdt='git difftool'
alias gdtc='git difftool --cached'
alias gmt='git mergetool'
alias grm='git rm'
alias grmc='git rm --cached'
alias grv='git remote -v'
alias gre='grv'
alias gr='git reset'
alias grh='git reset HEAD'
alias "grh^"="git reset 'HEAD^'"
alias grhh='git reset HEAD --hard'
alias "grhh^"="git reset --hard 'HEAD^'"
alias gst='git stash -u'
alias gstm='gst -m'
alias gstp='git stash pop'
alias gstl='git stash list'
alias gstc='git stash clear'
alias gsts='git stash save'
alias grb='git rebase'
alias grb-='git rebase -'
grbm() { git rebase $(git-main-branch) }
alias grbi='git rebase -i'
alias grbi2='git rebase -i HEAD~2'
alias grbi3='git rebase -i HEAD~3'
alias grbi4='git rebase -i HEAD~4'
alias grbi5='git rebase -i HEAD~5'
grbim() { git rebase -i $(git-main-branch) }
alias grbir='git rebase -i --root'
alias gcon='git rebase --continue'
alias gaacon='gaa && gcon'
alias grabort='git rebase --abort'
alias gsk='git rebase --skip'
alias gb='git branch --sort=-committerdate'
gbcp() { echo $(current-git-branch) | pbcopy }
alias gbs='git branch -D sav &> /dev/null; git branch sav'
alias gcs='git checkout sav'
alias gbd='git branch -d'
alias gbD='git branch -D'
alias gbDs="git branch | remove-colors | cut -c3- | egrep -i '^s+a+v+.*' | xargs git branch -D"
alias gbDa='git branch | remove-colors | egrep -v "master|main|\*" | xargs git branch -D'
alias gbD-="gbD @{-1}"
gbDi() {
git branch --sort=-committerdate | remove-colors | egrep -v "master|main|\*" | cut -c3- > /tmp/branches && \
cp /tmp/branches /tmp/branches-to-keep && \
$MAIN_EDITOR /tmp/branches-to-keep && \
comm -23 <(sort /tmp/branches) <(sort /tmp/branches-to-keep) | xargs 2> /dev/null git branch -D
}
alias gbm='gb -m'
# alias gbDs="git-list-branches | egrep -i '^s+a+v+.*' | xargs git branch -D"
# alias gbDa='git-list-branches | grep -v "master\|$(current-git-branch)" | xargs git branch -D'
# git-list-branches() {
# git for-each-ref --format="%(refname:short)" HEAD refs/heads
# }
alias gignore='git update-index --assume-unchanged'
alias gunignore='git update-index --no-assume-unchanged'
alias gignored='git ignored'
alias gp='git push'
alias gpf='gp --force-with-lease'
alias gpf!='gp --force'
gpu() {
if [[ $# -eq 0 ]]; then
gp -u origin $(current-git-branch)
else
gp -u "$@"
fi
}
gpuf() {
if [[ $# -eq 0 ]]; then
gp -u -f origin $(current-git-branch)
else
gp -u -f "$@"
fi
}
gpd() {
if [[ $# -eq 0 ]]; then
gp -d origin $(current-git-branch)
else
gp -d "$@"
fi
}
alias gclo-'git clone'
alias gx='gitx'
alias ggx='gitx'
alias gu='gitup'
alias git-branch-previous='git check-ref-format --branch "@{-1}"'
ggo() {
current-git-branch > .git/previous_branch
gaacm "current work"
gcm
}
gback() {
if [[ -e '.git/previous_branch' ]]; then
gco $(cat .git/previous_branch)
rm .git/previous_branch
fi
last_commit_message=$(git log -1 --pretty=%B)
if [[ $last_commit_message == 'current work' ]]; then; grh^; fi
unset last_commit_message
}
alias gcurr='gaacm "current work"'
alias gcur=gcurr
grebase() {
local branch=${1:-$(git-main-branch)}
git checkout $branch && gl && gc- && grb-
}
gmerge() {
local branch=${1:-$(git-main-branch)}
git checkout $branch && gl && gc- && gm-
}
alias gt='git tag'
alias gcp='git cherry-pick'
alias gcp-='git cherry-pick -'
alias gcpc='git cherry-pick --continue'
alias gcpa='git cherry-pick --abort'
fix() {
vim +"silent! /<<<<<<<" $(git diff --name-only --diff-filter=U | xargs)
}
alias fx='fix'
alias gstats='git shortlog -sn'
alias gsa='git submodule add'
git-remove-submodule() {
local submodule="$@"
git submodule deinit -f $submodule
rm -rf .git/modules/$submodule
git rm -f $submodule
}
alias gsr='git-remove-submodule'
alias grev='git revert'
alias grevh='git revert HEAD'
alias grevnoe='git revert --no-edit'
git-churn() {
git log --all -M -C --name-only --format='format:' "$@" \
| sort \
| grep -v '^$' \
| uniq -c \
| sort -n \
| awk 'BEGIN {print "count\tfile"} {print $1 "\t" $2}'
}
git-unchanged-since() {
git log --name-only --since="$@" --pretty='format:' '*.rb' | egrep '^(app|lib)/' > /tmp/changed
git ls-files '*.rb' | egrep '^(app|lib)/' > /tmp/all
comm -23 <(sort -u /tmp/all) <(sort -u /tmp/changed)
}
alias gsquashall='git reset --soft master; gaacm "Squashed commits"'
# Github
alias hc='gh pr create --web'
alias hp='gh pr view --web'
alias hf='gh repo fork --remote --remote-name=jeromedalbert'
hb() {
local current_branch=$(current-git-branch)
if [[ $current_branch == $(git-main-branch) ]]; then
gh repo view --web
else
gh repo view --web --branch $current_branch
fi
}
hs() { gh repo sync jeromedalbert/$(basename $PWD) && gl }
gpuhc() { gpu "$@" && hc }
alias gpfhc='gpf && hc'
alias gpufhc='gpuf && hc'
alias gphc='gp && hc'
alias ghc='gh repo create --private --source=. $(basename $PWD)'
alias ghi='gi; gci; ghc; gpu'
# Docker
alias d='docker'
alias di='docker images'
alias dps='docker ps'
alias drmi='docker rmi'
alias drmif='docker rmi -f'
alias drma='docker rm $(docker ps -a -q)'
alias dr='docker run'
alias drit='docker run -it'
alias deit='docker exec -it'
alias ds='docker stop'
alias db='docker build'
alias db.='docker build .'
alias dl='docker pull'
alias dp='docker push'
alias dt='docker tag'
alias dh='docker history'
alias da='docker attach'
alias dm='docker-machine'
alias dms='docker-machine start'
alias dc='docker-compose'
alias dcb='docker-compose build'
alias dcr='docker-compose run'
alias dcu='docker-compose up'
alias dcud='docker-compose up -d'
alias dcs='docker-compose stop'
alias dcps='docker-compose ps'
# Directories
alias st2='cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages'
alias st3='cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages'
alias .vim='cd ~/.vim'
alias c='cd ~/c'
alias ctmp='cd ~/c/tmp'
alias ct='ctmp'
alias desk='cd ~/Desktop'
alias de='desk'
# SSH
alias ssh='TERM=xterm-256color ssh'
alias ssh_conf="$MAIN_EDITOR ~/.ssh/config"
alias ssh-key='cat ~/.ssh/id_jerome.pub | tee >(pbcopy)'
alias ssh-keys='ssh-key'
# Entertainment
alias cowfortune='clear && fortune -a | cowsay | lolcat'
alias cowfact="clear && elinks -dump http://randomfunfacts.com | sed -n '/^| /p' | tr -d \| | cowsay | lolcat"
alias dunnet='emacs -batch -l dunnet'
alias emacs-games='ls /usr/share/emacs/22.1/lisp/play/*.elc | column -t'
snow() {
clear;while :;do echo $LINES $COLUMNS $(($RANDOM%$COLUMNS));sleep 0.1;done|awk '{a[$3]=0;for(x in a) {o=a[x];a[x]=a[x]+1;printf "\033[%s;%sH ",o,x;printf "\033[%s;%sH*\033[0;0H",a[x],x;}}'
}
alias weather='curl wttr.in'
# Fzf
j() {
if [[ $# -gt 0 ]]; then
# _z "$@"
# cd "$(_z -l 2>&1 | fzf -f "$*" | sort -nr | head -n 1 | sed 's/^[0-9,.]* *//')"
cd "$(_z -l 2>&1 | fzf -f "$*" | head -n 1 | sed 's/^[0-9,.]* *//')"
else
cd "$(_z -l 2>&1 | fzf --height 40% --reverse --tac --query "$*" | sed 's/^[0-9,.]* *//')"
fi
}
vj() {
(jv "$@")
}
jv() {
local old_directory=$(pwd)
j "$@"
if [[ "$(pwd)" != "$old_directory" ]]; then; v.; fi
}
jj() {
cd "$(mdfind "kind:folder" -onlyin ~ -name 2> /dev/null | fzf)"
}
fgl() (
[ $# -eq 0 ] && return
cd /usr/local/Cellar/figlet/*/share/figlet/fonts
local font=$(ls *.flf | sort | fzf --no-multi --reverse --preview "figlet -f {} $@") &&
figlet -f "$font" "$@" | pbcopy
)
fkill() {
local pids=$(ps -f -u $USER | sed 1d | fzf --multi | tr -s '[:blank:]' | cut -d' ' -f3)
if [[ -n "$pids" ]]; then
echo "$pids" | xargs kill -9 "$@"
fi
}
flog() {
local commits=$(
glo --color=always "$@" |
fzf --ansi --no-sort --height 100% \
--preview "echo {} | grep -o '[a-f0-9]\{7\}' | head -1 |
xargs -I@ sh -c 'git show --color=always @'"
)
if [[ -n "$commits" ]]; then
local hashes=$(printf "$commits" | cut -d' ' -f2 | tr '\n' ' ')
git show $hashes
fi
}
freflog() {
local hash=$(
git reflog --color=always "$@" |
fzf --no-multi --ansi --no-sort --height 100% \
--preview "git show --color=always {1}"
)
echo $hash
}
# Ruby / Rails
alias b='bundle'
alias be='bundle exec'
alias bo='bundle open'
alias bi='bundle install'
alias bu='bundle update'
bundle-path() {
VISUAL=echo bundle open $1
}
alias bp='bundle-path'
rails() {
if [[ -e 'bin/rails' ]]; then bin/rails "$@"; else command rails "$@"; fi
if [[ $? -eq 0 && $1 == 'new' ]]; then; cd $2; fi
}
rake() { if [[ -e 'bin/rake' ]]; then bin/rake "$@"; else command rake "$@"; fi }
rspec() { if [[ -e 'bin/rspec' ]]; then bin/rspec "$@"; else command rspec "$@"; fi }
spring() { if [[ -e 'bin/spring' ]]; then bin/spring "$@"; else command spring "$@"; fi }
kamal() { if [[ -e 'bin/kamal' ]]; then bin/kamal "$@"; else command kamal "$@"; fi }
alias dev='bin/dev'
alias r='rails'
alias rs='rails server'
alias rg='rails generate'
alias rgm='rails generate migration'
alias rgs='rails generate scaffold'
alias rdm='rails destroy migration'
alias rd='rails destroy'
alias rc='rails c'
alias rcs='rails c --sandbox'
alias rr='rails routes'
alias rdb='rails db'
alias mi='rake db:migrate'
alias ro='rake db:rollback'
alias romi='ro && mi'
# alias mi1='rake db:migrate'
# alias mi2='rake db:migrate && RAILS_ENV=test rake db:migrate'
# alias mi='rake db:migrate db:rollback && mi2'
# alias ro1='rake db:rollback'
# alias ro2='rake db:rollback && RAILS_ENV=test rake db:rollback'
# alias ro='ro2'
alias rT='rake -T'
alias st='spring stop'
alias strc='st && rc'
alias ss='spring status'
# alias irb='pry'
# alias debug='pry-remote'
fs() {
if [[ -e 'bin/dev' ]]; then; bin/dev; return; fi
local options=''
if [[ -e '.env' ]]; then; options='-e .env'; fi
if [[ -e '.env.local' ]]; then; options="$options,.env.local"; fi
if [[ -e 'Procfile.dev' ]]; then; options="$options -f Procfile.dev"; fi
eval "foreman start $options $@"
}
alias rru='rails runner'
alias rhash='asdf reshim ruby'
alias gmo='gem open'
alias gmi='gem install'
alias gmins='gmi'
alias gminf='gem info'
alias gmun='gem uninstall'
alias gmuns='gmun'
alias gmup='gem update'
alias gmupd='gmup'
alias gmu='gem update'
gmd() { open "http://www.rubydoc.info/gems/$1" }
gman() { man $(gem-path $1)/man/* }
gmcd() { cd $(gem-path $1) }
gem-path() {
VISUAL=echo gem open $1
}
alias gmp='gem-path'
gmb() {
open $(gem info $1 | awk '/Homepage/ { print $2 }')
}
alias gml='gem list'
alias ocov='open coverage/index.html '
alias cov='COVERAGE=true rspec && ocov'
steps() {
git checkout $(git-main-branch) &> /dev/null
local main_mig_num=$(ls db/migrate | wc -l)
git checkout - &> /dev/null
local mig_num=$(ls db/migrate | wc -l)
local delta=$(($mig_num - $main_mig_num))
echo $delta
}
alias sw='stree write'
rdbg() {
if [[ $# -eq 0 ]]; then
rdbg -An
else
command rdbg "$@"
fi
}
# Javascript
alias y='yarn'
alias yr='yarn run'
alias ya='yarn add'
alias yu='yarn upgrade'
alias yrm='yarn remove'
alias yre='yrm'
alias nhash='asdf reshim nodejs'
# Python
alias py='python'
# PHP
alias phpa='php -a'
# Ansible
alias an='ansible'
alias ans='an'
alias anp='ansible-playbook'
alias apl='anp'
alias and='ansible-doc'
alias anc='ansible-console'
alias anv='ansible-vault'
alias ang='ansible-galaxy'
# Heroku
alias hps='heroku ps'
alias hl='heroku logs -t'
alias hmi='heroku run rake db:migrate'
alias hap='heroku accounts:set personal'
alias haw='heroku accounts:set work'
alias haa='heroku apps --all'
alias hcs='heroku config:set'
alias hcu='heroku config:unset'
alias hr='heroku run'
alias hrd='heroku run:detached'
alias hrc='heroku run rails console'
# alias hro='heroku run rake db:rollback'
alias hpr='heroku run "printenv | sort"'
alias he='hpr'
alias hrp='hpr'
alias hrb='heroku run bash'
hurl() {
heroku info -s "$@" | grep web_url | cut -d= -f2
}
gph() { git push heroku $(git-main-branch) }
gpfh() { gpf heroku $(git-main-branch) }
alias gphm='gph'
# Kube
alias kr='kube run'
krc() { kube run $@ rails c }
krb() { kube run $@ bash }
kpr() { kube run $@ printenv | sort }
krru() { kube run $1 $2 rails runner $3 }
alias krbg='kube run:bg'
krrubg() { kube run:bg $1 $2 rails runner $3 }
alias kl='kube logs'
alias ke='kube env'
alias kp='kube pods'
# Kamal
alias km='kamal'
alias kms='kamal setup'
alias kmd='kamal deploy'
alias kmlo='kamal lock'
alias kmlr='kamal lock release'
alias kmrm='kamal remove'
alias kma='kamal app'
kml() {
kamal app logs -f -n 0 "$@" | sed '/Started GET "\/up"/,/Completed/d'
}
alias kmae='kamal app exec'
alias kmc="kamal app exec -q -i 'bin/rails console'"
alias kmrc='kmc'
alias kmb='kamal app exec -q -i bash'
alias kmrb='kmb'
alias kme="kamal app exec -q 'printenv | sort'"
alias kmpr='kme'
alias kmep='kamal env push'
alias kmepb='kmep && kmab'
alias kmeu='kmepb'
alias kmu='kmepb'
kmr() {
set -x
bin/kamal app exec -q -p "bin/rails runner '$*'"
}
alias kmru='kmru'
alias kmrru='kmru'
alias kmh='kamal healtcheck'
alias kmdt='kamal details -q'
alias kmac='kamal app containers -q'
alias kmab='kamal app boot'
alias kmacc='kamal accessory'
alias kmaccdt='kamal accessory details all -q'
alias kmacce='kamal accessory exec'
kmaccb() { kamal accessory exec $1 -q -i bash }
alias kmt='kamal traefik'
# Brew
brupd() {
if [[ $# -eq 0 ]]; then
brew update
else
brew upgrade "$@"
fi
}
alias brupg='brew upgrade'
alias brupgr='brupg'
alias brins='brew install'
alias brinst='brins'
alias brinf='brew info'
alias brinfo='brinf'
alias brun='brew uninstall'
alias bruns='brun'
alias brs='brew search'
alias brl='brew list'
alias brls='brl'
alias bcupd='brupd'
alias bcupg='brew upgrade --cask'
alias bcupgr='bcupg'
alias bcins='brew install --cask'
alias bcinst='bcins'
alias bcinf='brew info --cask'
alias bcinfo='bcinf'
alias bcun='brew uninstall --cask'
alias bcuns='bcun'
alias bcuni='bcun'
alias bcs='brew search --cask'
alias bcl='brew list --cask'
alias bcls='bcl'
alias bsl='brew services list'
alias bss='brew services start'
alias bst='brew services stop'
alias bsta='brew services stop --all'
# Apps / Binaries
alias subl="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
alias subl.='subl .'
alias subl3='command subl'
alias subl3.='subl3 .'
alias zzz='pmset sleepnow'
alias say_good='say -v Good ooooooooooooooooooooooooooooooooooooooooooooooooooo'
alias say_bad='say -v Bad ooooooooooooooooooooooooooooooooooooooooooooooooooo'
alias keyboard_disable='sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext'
alias keyboard_enable='sudo kextload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext'
alias iphone="open '/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'"
timer() { sleep $(($1*60)); terminal-notifier -message "${*:2}" }
localip() {
local ip=$(ipconfig getifaddr en0)
echo $ip | tr -d '\n' | pbcopy
echo $ip
}
alias privateip='localip'
publicip() {
local ip=$(curl -s ipinfo.io/ip)
echo $ip | pbcopy
echo $ip
}
alias ip='publicip'
alias myip='publicip'
iploc() {
curl -s ipinfo.io/"$@" | jq '.city + ", " + .region + ", " + .country' | tr -d '"'
}
alias whereami='iploc'
alias res='system_profiler SPDisplaysDataType | grep Resolution'
function cdf() {
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
}
alias o='open'
alias o.='open .'
alias toggle-cam='tcam'
alias dpad='sudo kextunload /System/Library/Extensions/AppleUSBMultitouch.kext' # 2> /dev/null"
alias epad='sudo kextload /System/Library/Extensions/AppleUSBMultitouch.kext'
alias emouse='dpad'
alias dmouse='epad'
alias archey='archey -c'
serve() { ruby -run -e httpd . -p 8000 }
servepy() { python -m http.server 8000 }
alias mounted='mount | column -t'
sman() { man "${1}" | col -b | subl }
alias rtop='top -o rsize'
alias ctop='top -o cpu'
alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'"
alias sub='subliminal download -l en'
alias sub2='filebot -get-subtitles'
minivim() {
local conf=$(awk 'NF > 0 { printf ":" $0 "\\\\n" }' ~/.vimrc.minimal)
echo $conf | tee >(pbcopy)
}
killui() {
for app in "Dock" "Finder" "SystemUIServer"; do
killall "${app}"
done
}
alias nra='~/c/boilerplate/new-rails-app'
alias nrg='~/c/boilerplate/new-ruby-gem'
alias nsa='~/c/boilerplate/new-sinatra-app'
mkpwd() {
local max_chars=${1:-28}
cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w $max_chars | head -n 1
}
mkpwd2() {
local password=$(openssl rand -base64 300 | tr -d '\n=/+')
local max_chars=${1:-28}
echo $password | cut -c-$max_chars
}
alias mkpw='mkpwd'
alias pw='mkpw'
alias fd='fd --type f'
alias ng='ngcp && ngrok http --domain $NGROK_DOMAIN 5000'
alias ngcp='echo "https://$NGROK_DOMAIN" | pbcopy'
smee() {
echo $SMEE_URL | pbcopy
command smee -u $SMEE_URL -p 5000 "$@"
}
alias smeecp='echo $SMEE_URL | pbcopy'
alias smeego='open $SMEE_URL'
tess() {
local file=$1
if [[ -z $file ]]; then
file=$(ls -dt ~/Desktop/* | head -n 1)
fi
tesseract $file stdout | tee >(pbcopy)
}
gq() {
local escaped_query=$(printf "%q" ${@: -1})
curl -X POST -H 'Content-Type: application/json' $1 -d "{ \"query\": \"$escaped_query\" }"
}
alias pj='pbpaste | jq .'
parsecron() {
ruby -e "require 'cronex'; puts Cronex::ExpressionDescriptor.new('$1').description" \
| tee >(pbcopy)
}
alias curljs='curl -H "Content-type: application/json"'
curlgql() {
curljs --X POST -s -w '%{time_total}' "$@" | jq
}
alias unused='unused -t .tags'
alias ytdlp='yt-dlp'
alias chrome_no_ssl='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --ignore-certificate-errors --ignore-urlfetcher-cert-requests &> /dev/null'
alias macname='scutil --get ComputerName'
alias speedtest='networkQuality'
alias cores='nproc'
bench() {
if [[ $# -eq 0 ]]; then; browsertime --help; return; fi
browsertime --headless --skipHar --resultDir=/tmp "$@"
echo
cat /tmp/browsertime.json | jq -r '.[0].statistics.timings.pageTimings | "Average DOM Load Time: \(.domContentLoadedTime.mean) ms\nAverage Load Time: \(.pageLoadTime.mean) ms\n\nMean DOM Load Time: \(.domContentLoadedTime.mean) ms\nMean Load Time: \(.pageLoadTime.mean) ms"'
}
alias nosleep='caffeinate -d'