-
Notifications
You must be signed in to change notification settings - Fork 1
/
.aliases
693 lines (573 loc) · 26.1 KB
/
.aliases
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
#!/usr/bin/env bash
# =============================================================================
# ✨ HELPERS
# =============================================================================
NUM_CORES=`getconf _NPROCESSORS_ONLN`
# =============================================================================
# List aliases
# =============================================================================
alias dot='ets ~/.dotjitsu/bin/dot'
alias gls='gls --color=auto --group-directories-first'
alias eza='eza --group-directories-first --color=always'
alias ls='gls --color --group-directories-first'
alias l='eza -Ga --icons' # Lists in multi column, hidden files.
# alias ll='eza --icons -Lah --no-permissions --no-user -T -L1'
alias ll='eza --icons -la --no-permissions --no-user -T -L1 --no-time'
alias lll='eza --icons -la --no-permissions --no-user -T --no-time --git -g -R --git-ignore -L2 -I "*.git"'
alias llll='eza --icons -la --no-permissions --no-user -T --no-time --git -g -R --git-ignore -L3 -I "*.git"'
#alias ll='eza -lah' # Lists in one column, hidden files.
alias lr='ll -R' # Lists human readable sizes, recursively.
alias la='ll -A' # Lists human readable sizes, hidden files.
alias lm='la | "$PAGER"' # Lists human readable sizes, hidden files through pager.
alias lx='ll -XB' # Lists sorted by extension (GNU only).
alias lk='ll -Sr' # Lists sorted by size, largest last.
alias lt='ll -tr' # Lists sorted by date, most recent last.
alias lc='lt -c' # Lists sorted by date, most recent last, shows change time.
alias lu='lt -u' # Lists sorted by date, most recent last, shows access time.
alias sl='ls' # I often screw this up.
# =============================================================================
# Find aliases
# =============================================================================
ff () {
IFS=""
local result=`fd $1`
echo -e $result
echo -e $result | wc -l
}
#alias fff='ag -G "\.(js?x|ts?x|json)$" '
alias fic='find $( pwd ) -follow -name "*.c" -o -name "*.cc" -o -name "*.cpp" | xargs grep --color -e '
alias fih='find $( pwd ) -follow -name "*.h" | xargs grep --color -e '
alias fis='find $( pwd ) -follow -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.h" | xargs grep --color -e '
alias fif='find $( pwd ) -follow -ty
pe f -not -name "*~" -not -name "*swp" | xargs grep --color -e '
alias fip='find $( pwd ) -follow -name "*.ts" | xargs grep --color -e '
alias qff='find $( pwd ) -follow 2>/dev/null -name '
alias qfic='find $( pwd ) -follow -name "*.c" -o -name "*.cc" -o -name "*.cpp" 2>/dev/null | xargs grep --color -e '
alias qfih='find $( pwd ) -follow -name "*.h" 2>/dev/null | xargs grep --color -e '
alias qfis='find $( pwd ) -follow -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.h" 2>/dev/null | xargs grep --color -e '
alias qfif='find $( pwd ) -follow -type f 2>/dev/null| xargs grep --color -e '
alias qfip='find $( pwd ) -follow -name "*.py" 2>/dev/null | xargs grep --color -e '
# =============================================================================
# ✨ Globals & overrides
# =============================================================================
alias ag='ag --hidden --stats'
alias code="code -n"
alias cp='gcp -v'
alias cpr='rsync -aAHXv --info=progress2 --human-readable'
alias dfc="dfc -Wdluh -q mount -t apfs"
alias fd="fd --ignore-case --hidden --exclude '.git' --ignore-file=$HOME/.dotjitsu/.rgignore"
alias cat='\bat --paging=never --style="plain" --decorations=auto'
#alias gdu="timeout --foreground -s SIGTERM 10m $HOMEBREW_PREFIX/Cellar/gdu/*/bin/gdu -a || (stty sane &> /dev/null; tput reset &> /dev/null; clear;)";
function gdu() {
timeout --foreground -s SIGTERM 10m $HOMEBREW_PREFIX/Cellar/gdu/*/bin/gdu-go -x -a -C -I "$HOME/Library/Containers,$HOME/.local/share/pnpm,$HOME/.local/share/fnm" "$@" || (stty sane &> /dev/null; tput reset &> /dev/null; clear; echo "[timeout]: 10m gdu")
}
alias hb='HandBrakeCLI'
alias killall="killall -v"
alias less="less --incsearch"
alias mkdir='gmkdir -pv'
#alias mtr="grc -es --colour=auto mtr"
alias mv='gmv -vi'
alias grep="$HOMEBREW_PREFIX/bin/ggrep -i"
alias pgrep='pgrep -fli'
alias pigz='pigz -v'
alias qmv='qmv -e "subl -w -n" -f destination-only'
alias rg='rg --hidden --smart-case'
alias rm='grm -v'
alias date='gdate'
alias sort="LC_ALL=C sort -S 50% --parallel=$NUM_CORES"
alias sudo='nocorrect sudo '
alias vnstat="vnstat -i en0"
alias wget="wget --no-check-certificate --compression auto --trust-server-names -nv --show-progress"
#alias wget2="wget --no-check-certificate --compression auto --trust-server-names -nv --show-progress --content-disposition"
alias curl="$HOMEBREW_PREFIX/opt/curl/bin/curl"
#alias wget="wget --no-check-certificate --compression auto --content-disposition --trust-server-names -nv -q --show-progress"
alias ws='ws -d'
alias tailscale='/Applications/Tailscale.app/Contents/MacOS/Tailscale'
alias ts="$HOMEBREW_PREFIX/Cellar/moreutils/*/bin/ts"
alias j=just
alias ping='grc --colour=auto ping'
alias dig='grc --colour=auto dig'
alias env='grc --colour=auto env'
alias speedtest.tele2='wget -O /dev/null http://speedtest.tele2.net/10GB.zip'
function speedtest.ookla() {
local size=${1:-"1000"}
local bytes="$(printf "$size" | numfmt --from-unit=Mi)";
local url="https://ook-sto-x1.puregig.net.prod.hosts.ooklaserver.net:8080/download?nocache=$RANDOM$RANDOM$RANDOM$RANDOM=&size=$bytes";
xh \
-p bB \
--https \
--check-status \
--download \
--output /dev/null \
"${url}" 2>&1
# dl -o /dev/null "https://ook-sto-x1.puregig.net.prod.hosts.ooklaserver.net:8080/download?nocache=$RANDOM$RANDOM$RANDOM$RANDOM=&size=$bytes";
}
alias ets='~/.go/bin/ets -s -f "%s.%Ls ┃ "'
function cd {
builtin cd "$@"
# Update iTerm2's tab title
if [[ $TERM_PROGRAM == "iTerm.app" ]]; then
echo -ne "\033]0;$(pwd | sed -e "s#/Users/$(whoami)#~#" -e 's#~/git/##')\007"
fi
}
# =============================================================================
# ✨ GIT
# =============================================================================
alias g='git'; #compdef g='git'
alias gu='gitui'
function clone {
url=$1;
reponame=$(echo $url | awk -F/ '{print $NF}' | sed -e 's/.git$//');
echo "🦄 Reponame: $reponame"
echo
# git clone $*;
gh repo clone $*
cd "$reponame";
echo "" && git log --oneline --graph --date=short -n 5 && echo ""
}
# =============================================================================
# ✨ Shortcut & Utils
# =============================================================================
alias ..="cd .."
alias ...='cd ../../'
alias ..2="cd ../.."
alias ..3="cd ../../.."
alias ..4="cd ../../../.."
alias ..5="cd ../../../../.."
alias python="/opt/homebrew/opt/python/libexec/bin/python"
alias sqlite='sqlite3'
# =============================================================================
# ✨ Custom utils
# =============================================================================
#alias todo="ag --color-line-number '1;36' --color-path '1;36' --ignore-case --silent '(?:<!-- *)?(?:#|//|/\*+|<!--|--) *(TODO|FIXME|FIX|BUG|UGLY|HACK|NOTE|IDEA|REVIEW|DEBUG|OPTIMIZE)(?:\([^(]+\))?:?(?!\w)(?: *-->| *\*/|(?= *(?:[^:]//|/\*+|<!--|@|--))|((?: +[^\n@]*?)(?= *(?:[^:]//|/\*+|<!--|@|--))|(?: +[^@\n]+)?))'"
alias b='bump'
alias bat.preview='bat --list-themes | fzf --preview="bat --theme={} --color=always $HOME/.dotjitsu/package.json"'
alias bif='brew info'
alias cask='brew install --cask'
alias cgrep="grep --color=always"
alias crontab='VISUAL=micro EDITOR=micro crontab'
alias ctp="bat package.json | jq"
alias ffind='noglob fd -g --no-ignore'
alias h="history | fzf --reverse"
alias ios="open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app"
alias n='ncdu -1'
alias nano='micro'
alias ncdu="gdu"
alias ncdu2="ncdu"
alias neofetch='neofetch --config ~/.dotjitsu/neofetch.conf'
alias macchina="macchina --config ~/.dotjitsu/macchina.toml"
alias nx='PATH=$(npm bin):$PATH'
alias path='echo -e ${PATH//:/\\n}'
alias retroarch="~/Applications/RetroArch.app/Contents/MacOS/RetroArch -vf"
alias rmf='grm -rfv'
alias serve='ws -f stats -d '
alias smartgit='/Applications/SmartGit.app/Contents/MacOS/SmartGit'
alias todo="rg -p --pcre2 '(?:<!-- *)?(?:#|//|/\*+|<!--|--) *(TODO|FIXME|FIX|BUG|UGLY|HACK|NOTE|IDEA|REVIEW|DEBUG|OPTIMIZE)(?:\([^(]+\))?:?(?!\w)(?: *-->| *\*/|(?= *(?:[^:]//|/\*+|<!--|@|--))|((?: +[^\n@]*?)(?= *(?:[^:]//|/\*+|<!--|@|--))|(?: +[^@\n]+)?))' | sed 's/[[:space:]]\+/ /g' | bat"
alias watchos="open /Applications/Xcode.app/Contents/Developer/Applications/Simulator\ \(Watch\).app"
# alias zup='rm -f ~/.ssh/control/git@github.com:22; zinit update -p -v; zr'
alias zup='zinit update --all -p -v; zr'
alias rp='rust-parallel'
#alias imageoptim='ets ~/Applications/ImageOptim.app/Contents/MacOS/ImageOptim'
cs () { bat "$@" | jq '.scripts' | tr -d '{}' | sed 's/^[[:space:]]*//' | column -t -s':' 2>/dev/null; }
touch2() { [[ ! -f "$1" ]] && mkdir -pv "$(dirname "$1")" && gtouch "$1" && echo "gtouch: created file $1"; open -a "Sublime Text" "$1"; }
zclearcache () { rm -rfv .repos/zplug/cache; rm -rfv ~/.cache/prezto ;}
#alias ncdu="ncdu -x -1bre"
#alias git=hub
wherebat () { where "$1" | fzf --preview 'bat -p {}' ;}
alias ytdl='yt-dlp --config-location ~/.dotjitsu/packages/youtube-dl/config'
alias duf='duf -hide-fs devfs'
alias showcursor='tput cvvis'
alias hidecursor='tput civis'
# ⚡️ =============================================================================
# ️️⚡️ Filters & Pipes
# ⚡️ =============================================================================
alias string-trim-leading-whitespace="sed -e 's/^[[:space:]]*//'"
alias string-trim-all-whitespace="tr -d '[:space:]'"
find-sum () {
local DIR='.'; local EXT=$1
# find $DIR -type f -name "*.$EXT" -printf "%s\n" | gawk -M '{t+=$1}END{print t}'
# gfind $DIR -type f -iname "*$EXT" -printf '%s\n' | gawk -M '{t+=$1}END{print t}'
fd --no-ignore-vcs --hidden --glob "$EXT" --print0 $DIR | xargs -0 stat -c "%s" | gawk -M '{t+=$1}END{print t}'
}
cpw () { cp -v $(command -v $1) $2; }
# Intuitive map function
# For example, to list all directories that contain a certain file:
# find . -name .gitattributes | map dirname
alias map="xargs -n1"
# Lock the screen (when going AFK)
alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
#
# Apps
#
alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
alias chrome-canary="/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary"
alias chromium="/Applications/Chromium.app/Contents/MacOS/Chromium"
alias firefox="/Applications/Firefox.app/Contents/MacOS/firefox"
wh () { which -a "$@" | bat ;}
# Compare original and gzipped file size
function gz() {
local origsize=$(wc -c < "$1");
local gzipsize=$(gzip -c "$1" | wc -c);
local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l);
printf "orig: %d bytes\n" "$origsize";
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio";
}
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
# the `.git` directory, listing directories first. The output gets piped into
# `less` with options to preserve color and line numbers, unless the output is
# small enough for one screen.
function tre() {
tree -aC -I '.git|node_modules|bower_components|.tmp|tmp|dist' --dirsfirst "$@" | less -FRNX;
}
function gthumbnails() {
local sec=${1:-1} # Default 1 sec
for file in *.mp4; do
#ffmpeg -y -i "$file" -f image2 -ss $sec -vframes 1 -an "${file%.mp4}.jpg";
ffmpeg -ss 1 -i "$file" -vframes 1 -vcodec png -an -y "${file%.mp4}.png"
done
}
# =============================================================================
# GOTO aliases
# =============================================================================
alias -- -="cd -"
# alias dl="cd $HOME/Downloads"
alias dt="cd $HOME/Desktop"
# alias c="cd $HOME/code"
alias work="cd $HOME/work"
alias dj="code $HOME/.private/dotjitsu.code-workspace"
alias djp='pull $HOME/.dotjitsu; pull $HOME/.private;'
gd() { git st; hr; git diff -- :!package-lock.json :!yarn.lock :!pnpm-lock.yaml; }
gdc() { git st; hr; git diff --cached -- :!package-lock.json :!yarn.lock :!pnpm-lock.yaml; }
alias gda="git diff HEAD -- :!package-lock.json :!yarn.lock :!pnpm-lock.yaml"
alias gds="git diff --cached -- :!package-lock.json :!yarn.lock :!pnpm-lock.yaml"
append() { grep -q -F $1 $2 || echo $1 >> $2 ;}
# =============================================================================
# Gnu utils (to enforce presedence)
# =============================================================================
alias xargs="gxargs"
alias find="gfind"
alias locate="glocate"
alias updatedb="gupdatedb"
alias tar="gtar"
# =============================================================================
# Others
# =============================================================================
alias spotlight.access='sudo fs_usage -w -f filesys -e Terminal gtee iTerm2 | tee fs_usage.log'
spotlight.rebuild () { sudo mdutil -i off /; sudo rm -rf /.Spotlight*; sudo mdutil -i on /; sudo mdutil -E /; }
spotlight.search () { mdfind . ;}
# =============================================================================
# Boilerplate shortcuts
# =============================================================================
# Create directory and immediately move into that dir
mk () { mkdir -p "$@" && cd "$_"; }
mkt () { hr -; cd $(mktemp -d); pwd; echo; }
mktt () { hr -; cd $(mktemp -d -p $HOME/tmp); pwd; echo; }
mktcopy () { hr -; cd $(mktemp -d -p $HOME/tmp); pwd | tee /dev/tty | pbcopy; echo; }
mktclone () { cd $(mktemp -d) && pwd && hr - && clone $1; }
# Opens file in EDITOR.
edit () {
local dir=$1
[[ -z "$dir" ]] && dir='.'
$EDITOR $dir
}
alias e='edit'
alias zr='echo "Reloading zsh..."; rm -fv ~/.zcompdump*; reset; exec $SHELL -l;'
alias zra='echo "Reloading aliases..."; source ~/.dotjitsu/aliases;'
alias reload='zr'
alias reloadshell='zr'
alias brew.info='brew-info'
brew.info2 () {
grep desc $(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/*.rb | perl -ne 'm{^.*/(.*?)\.rb.*?\"(.*)"$} and print "$1|$2\n"' | column -t -s '|' | fzf --reverse -e
}
cask.info () {
grep desc $(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/*.rb | perl -ne 'm{^.*/(.*?)\.rb.*?\"(.*)"$} and print "$1|$2\n"' | column -t -s '|' | fzf --reverse -e
}
# =============================================================================
# Cli Tricks
# =============================================================================
alias history.stat="history 0 | awk '{print \$2}' | sort | uniq -c | sort -n -r | head -n 50"
die () {
[[ -n "$1" ]] && echo "$1"
[[ -n "$2" ]] && exit $2 || exit 1
}
# =============================================================================
# OSX tricks
# =============================================================================
# Open curr dir in preview.app.
osx.openPreview () {
local item=$1
[[ -z "$item" ]] && item='.'
open $1 -a 'Preview'
}
# Show current Finder directory in terminal
osx.finderDir () {
osascript 2>/dev/null <<EOF
tell application "Finder"
return POSIX path of (target of window 1 as alias)
end tell
EOF
}
# Lock current session and proceed to the login screen.
alias lock='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
# =============================================================================
# SSH
# =============================================================================
addkey () {
# ssh $1 "tee -a ~/.ssh/authorized_keys" < ~/.ssh/id_?sa.pub
ssh $1 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_?sa.pub # '?sa' is a glob, not a typo!
echo "sshkey done."
}
alias pubkey="more ~/.ssh/id_rsa.pub | pbcopy | echo '=> Public key copied to pasteboard.'"
alias keygen='ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa; ssh.pubkey'
alias ssh.pubkey="pubkey"
alias ssh.addkey="addkey"
alias ssh.update-known-hosts='ssh-keygen -R'
alias ssh.remove-tunnels='rm ~/.ssh/control/*'
alias ssh.clean='rm -fv ~/.ssh/control/*'
# =============================================================================
# ✨ GIT
# =============================================================================
# Checkout git branches
# git.co () {
# local branches branch
# local date=$(date '+%Y-%m-%d %H:%M:%S')
# local branches=$(git branch -a)
# echo $date
# branch=$(echo "$branches" | fzf +m -x -e --height=30 --reverse) &&
# ~/.repos/git-friendly/stash && ~/.repos/git-friendly/branch $(echo "$branch" | sed "s:.* remotes/origin/::" | sed "s:.* ::") && pull
# }
git.co() {
result=($(git branch -a --color=always | grep -v '/HEAD\s' | sort |
fzf --height 80% --border --ansi --tac --preview-window right:70% \
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1) | head -'$LINES |
sed 's/^..//' | cut -d' ' -f1))
if [[ $result != "" ]]; then
if [[ $result == remotes/* ]]; then
git checkout --track $(echo $result | sed 's#remotes/##')
else
git checkout "$result"
fi
fi
}
gf() {
git -c color.status=always status --short |
fzf --height 50% --border --ansi -multi --ansi --nth 2..,.. \
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500' |
cut -c4- | sed 's/.* -> //'
}
alias co='git.co'
#alias ghc='cd $(ghq list --full-path | fzf)'
#alias ghf='find $(git rev-parse --show-cdup) -type f | grep -v "/.git/" | fzf'
#alias gho='(cd $(ghq list --full-path | fzf) && git browse)'
# =============================================================================
# CD
# =============================================================================
# cd to the default working directory set by current_working_project
chdir.default () {
export wdir=`cat $HOME/.tmp/current_project_path`
echo "Change current working project to $wdir"
cd $wdir
}
chdir.set () {
cwd=pwd > $HOME/.tmp/current_project_path
echo "Set current working project to `$cwd`"
}
chdir.rm () {
echo "Remove current working project: `cat $HOME/.tmp/current_project_path`"
'~' >> $HOME/.tmp/current_project_path
}
# =============================================================================
# System stuff
# =============================================================================
# Load 8 cores at once.
system.maxcpu () {
stress --cpu 64 --timeout 60
}
ps.kill () { kill -9 `ps ax | grep $1 | grep -v grep | awk '{print $1}'`; }
# =============================================================================
# Lists (with fzf magic)
# =============================================================================
# List of available VM's - with fbr magic
vm.vbox () {
vm=$(VBoxManage list vms | fzf +s +m -e --reverse) &&
uuid=$(echo "$vm" | ack --cc '{([a-z0-9\-]+)}' --output '$1') &&
VBoxManage startvm $uuid
}
vm.fusion () {
vm=`vmrun list | fzf +s +m -e --reverse` &&
echo $vm
#uuid=`echo "$vm" | ack --cc '{([a-z0-9\-]+)}' --output '$1'` &&
#VBoxManage startvm $uuid
}
# =============================================================================
# File related stuff
# =============================================================================
file.size () { wc -c < $1; }
# Monitor IO in real-time (open files etc).
files.open () { sudo dtrace -n 'syscall::open*:entry { printf("%s %s",execname,copyinstr(arg0)); }'; }
# Files used, anywhere on the filesystem
alias files.usage='sudo fs_usage -e -f filesystem|grep -v CACHE_HIT|grep -v grep';
# Files being opened (OSX Only)
# alias files.open='sudo fs_usage -e -f filesystem|grep -v CACHE_HIT|grep -v grep|grep open'
# Files in use in the Users directory
alias files.usage.user='sudo fs_usage -e -f filesystem|grep -v CACHE_HIT|grep -v grep|grep Users'
files.last_modified_directory() { echo `\ls -t | head -n 1`; }
ddd() {
local cmd="dd if='"$1"' | pv | sudo dd of=/dev/rdisk"$2" bs=1m"
echo $cmd
sudo sh -c "$cmd"
}
# =============================================================================
# Network stuff
# =============================================================================
alias airport='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
alias net.connections='lsof -l -i +L -R -V'
alias net.established='lsof -l -i +L -R -V | grep ESTABLISHED'
alias net.available_ip="ping -t 1 255.255.255.255 > /dev/null; arp -a"
alias net.sockets_numerical='netstat -tulpn'
alias net.sockets_services='netstat -tulp'
alias net.sniff0="sudo ngrep -d 'en0' -t '^(GET|POST) ' 'tcp and port 80'"
alias net.sniff1="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias net.sniff4="sudo ngrep -d 'en4' -t '^(GET|POST) ' 'tcp and port 80'"
alias net.flushdns='flushdns'
flushdns() { echo "DNS cache flushing ..."; sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache; echo "✓ DNS cache cleared!"; }
reconnect() { sudo networksetup -setnetworkserviceenabled Wi-Fi off; sudo networksetup -setnetworkserviceenabled Wi-Fi on; }
# =============================================================================
# Compression
# =============================================================================
z1 () {
local input=$1; local output=${2:-$1}.tar.gz
echo "Compressiong $input into $output"
#tar cf - $input | pv -s $(du -sk $input | awk '{print $input*1024}') | pigz -c -9 > $output
tar cf - $input | pigz -c -9 > $output
}
z2 () {
local input=$1; local output=${2:-$1}.tar.lz
tar cf - $input | pv -s $(du -sk $input | awk '{print $input*1024}') | plzip -c -9 > $output
}
z3 () {
local input=$1; local output=${2:-$1}.tar.bz2
tar cf - $input | pv -s $(du -sk $input | awk '{print $input*1024}') | pbzip2 -c -9 > $output
}
alias xtract='unar'
# =============================================================================
# Useful file size aliases
# =============================================================================
randfile () {
local size=$1
time openssl rand $size | head -c $size > $size.bin
}
# 1500 -> 1.500
to_kb () { echo $(bc <<< "scale=3; $1/1000"); }
# 10000 -> 10,000
format_number () { printf "%'.3f\n" $1; }
# ./some_file.txt -> 11496328
size_in_bytes () { stat -f %z "$1"; }
# ./some_file.txt -> 11,496.328 KB
echo_size () { echo $(format_number $(to_kb $(size_in_bytes "$1")))"kB"; }
# =============================================================================
# TMUX
# =============================================================================
ta_function() { tmux attach -t $1; }
tk_function() { tmux kill-session -t $1; }
alias tm='tmux'
alias 'tmux-new'='tmux new-session -A -s $(basename $PWD | tr -d .)'
alias 'tmux-ls'='tmux ls'
alias 'tmux-attach'=ta_function
alias 'tmux-at'=ta_function
alias 'tmux-kill'=tk_function
# =============================================================================
# FZF
# =============================================================================
# Fuzzy match against history, edit selected value
fhist() {
local history=$( ( fc -l 1 || history) | tail -2000 | fzf --tac --reverse --no-sort | sed 's/ *[0-9]* *//')
print -z $history
}
#bindkey -s '^r' 'fhist\n'
# Copied from https://github.com/junegunn/dotfiles/blob/master/bashrc
# fd - cd to selected directory
# fd() {
# DIR=`find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf-tmux` \
# && cd "$DIR"
# }
fkill() {
# fkill - kill processes
ps -ef | sed 1d | fzf -m | awk '{print $2}' | xargs kill -${1:-9}
}
fe() {
# fe [FUZZY PATTERN] - Open the selected file with the default editor
# - Bypass fuzzy finder if there's only one match (--select-1)
# - Exit if there's no match (--exit-0)
local file
file=$(fzf-tmux --query="$1" --select-1 --exit-0)
[ -n "$file" ] && ${EDITOR:-vim} "$file"
}
fo() {
# Modified version where you can press
# - CTRL-O to open with `open` command,
# - CTRL-E or Enter key to open with the $EDITOR
local out file key
out=$(fzf-tmux --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)
key=$(head -1 <<< "$out")
file=$(head -2 <<< "$out" | tail -1)
if [ -n "$file" ]; then
[ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file"
fi
}
# Switch tmux-sessions
ft() {
local session
session=$(tmux list-sessions -F "#{session_name}" | \
fzf-tmux --query="$1" --select-1 --exit-0) &&
tmux switch-client -t "$session"
}
# =============================================================================
# GHQ (Git util)
# =============================================================================
ghq () {
# https://fotoallerlei.com/post/2019-09-29-ghq/#change-the-ghq-root-directory
if [ "$1" = look -a -n "$2" ]; then
local repos=($(command ghq list -p "$2"))
echo "repos: $repos"
case ${#repos[@]} in
0)
echo 'No repo found.'
return 1
;;
1)
cd "${repos[0]}"
return
;;
*)
local PS3="Select repo: "
select reponame in ${repos[@]}; do
cd "${reponame}"
return
done
esac
elif [ "$1" = get -a -n "$2" ]; then
command ghq "$@"
cd $(command ghq list -e -p "$2")
return
fi
command ghq "$@"
}
alias gsa='git submodule add'
# =============================================================================
# WGET
# =============================================================================
crwl() {
#wget --tries=inf --timestamping --recursive --level=inf --convert-links --page-requisites --no-parent --html-extension --reject-regex '\?C=' "$@"
wget --tries=inf --compression auto --timestamping --recursive --level=inf --convert-links --page-requisites --no-parent --html-extension --show-progress --no-check-certificate --trust-server-names -4 -q --reject-regex '\?C=' "$@"
}
alias mrsort="gawk -v RS=\"\" '{ gsub(\"\n\", \"###\"); print }' .mrconfig | sort -f | gawk -v ORS=\"\n\n\" '{ gsub(\"###\", \"\n\"); print }' > .mrconfig.tmp && mv .mrconfig.tmp .mrconfig"
#alias make='grc --colour=auto $HOMEBREW_PREFIX/opt/make/libexec/gnubin/make '
alias make="$HOMEBREW_PREFIX/opt/make/libexec/gnubin/make "
# make() {}
# grc --colour=auto /usr/bin/make $*
fixaudio () {
sudo rm /Library/Preferences/Audio/com.apple.audio.DeviceSettings.plist
sudo rm /Library/Preferences/Audio/com.apple.audio.SystemSettings.plist
sudo killall coreaudiod
}