-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliases
2078 lines (1674 loc) · 52.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
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
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# shellcheck disable=SC2148,SC2089,SC2154
# -*- shell-script -*-
# vim:set ft=sh textwidth=0 wrapmargin=0:
set +x
# Aliases and custom functions
source "$HOME"/dotfiles/colors.sh
source "$HOME"/dotfiles/utils.sh
source "$HOME"/dotfiles/image_utils.sh
if [[ "$UNAME_OUTPUT" == 'Darwin' ]]; then
# macOS-specific
alias copy_to_clipboard='pbcopy'
alias setmiddlevolume='sudo osascript -e "set Volume 5"'
alias eclipseclean='/Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse -clean'
alias topcoder='javaws ~/Developer/Topcoder/ContestAppletProd.jnlp'
alias mysql_client='open -a TablePlus'
alias sc2_hotkeys_edit='vim ~/Library/Application\ Support/Blizzard/StarCraft\ II/Accounts/491096383/Hotkeys/Rapid\ fire\ test.SC2Hotkeys'
# alias vim='mvim -v'
alias ls='ls --human-readable -lFG'
function brew_uninstall_all() {
brew remove --force "$(brew list --formula)"
brew remove --cask --force "$(brew list)"
}
alias analyze_disk_usage='/Applications/OmniDiskSweeper.app/Contents/MacOS/OmniDiskSweeper'
alias lsblk='diskutil list'
alias change_main_screen='~/scripts/hmscreens -setMainID `~/scripts/hmscreens -info | \grep "Screen ID:" | head -2 | tail -1 | sed "s/[^0-9]*//g"`'
alias reset_wifi='sudo networksetup -setnetworkserviceenabled Wi-Fi off && sleep 2 && sudo networksetup -setnetworkserviceenabled Wi-Fi on'
function battery_recharge_cycles_count() {
system_profiler SPPowerDataType | \grep "Cycle Count" | awk '{print $3}'
}
alias software_version='system_profiler SPSoftwareDataType'
alias dwg2pdf='/Applications/QCAD.app/Contents/Resources/dwg2pdf -no-dock-icon'
alias fix_disk="/Applications/Disk\ Drill.app"
function ios_simulator_screenshot() {
xcrun simctl io booted screenshot
}
function ios_simulator_screencast() {
xcrun simctl io booted recordVideo ios_simluator_recording.mp4
}
alias date='gdate'
# Toggle "Do not disturb" mode on macOS (via: https://github.com/sindresorhus/do-not-disturb-cli)
alias dnd-toggle='dnd toggle'
elif test -f /proc/sys/kernel/osrelease && grep -q microsoft /proc/sys/kernel/osrelease; then
# Windows (WSL)
alias copy_to_clipboard='clip.exe'
alias powershell='powershell.exe -NoLogo'
alias xclip='clip.exe'
# See: https://github.com/microsoft/winget-cli/issues/688#issuecomment-788391878
alias winget='powershell.exe -NoLogo /c winget.exe'
function edit_idea_settings() {
vim "/mnt/c/Users/""$WINDOWS_USERNAME""/AppData/Roaming/JetBrains/IntelliJIdea2021.3/idea64.exe.vmoptions"
}
function open_autostart_folder() {
local -r autostart_path=$(printf "C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" "$WINDOWS_USERNAME")
cmd.exe /c explorer.exe "$autostart_path"
open /mnt/c/ProgramData/Microsoft/Windows/Start\ Menu/Programs/StartUp
}
function open() {
local local_path=$1
explorer.exe "$(wslpath -w "$local_path")"
}
function browse() {
sensible-browser "$@"
}
function github_diff_last_commit() {
local -r url=$(gh browse --commit --no-browser | sed --expression 's/tree/commit/g')
browse "$url"
}
alias wmic='WMIC.exe'
# Launches Windows uninstall program (GUI-based)
alias uninstall='cmd.exe /c appwiz.cpl'
# shellcheck disable=2154
alias empty_trash_bin='cmd.exe /c "rd /s /q %systemdrive%\$Recycle.bin" 2&> /dev/null'
alias analyze_disk_usage='ncdu --color=dark'
# Alternatives:
# Note: assumes 'C' is the main drive
# alias analyze_disk_usage='/mnt/c/Program\ Files\ (x86)/WinDirStat/windirstat.exe'
# alias analyze_disk_usage='/mnt/c/Program\ Files/WizTree/WizTree.exe "c:"'
function copy_folder_to_desktop() {
local src_folder="$1"
cp --recursive "$src_folder" "/mnt/c/Users/""$WINDOWS_USERNAME""/Desktop/"
}
elif [[ "$UNAME_OUTPUT" == 'Linux' ]]; then
# Debian/Ubuntu
function listkernels() {
dpkg --list 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
}
alias gdebi='sudo gdebi'
# Linux specific
# alias i='sudo apt-get install --assume-yes'
# Install through apt-get and add installed software to list of used commands
# addcmd() { sudo apt-get install --assume-yes $* && echo $* >> ~/install_apt-get.txt; }
function addcmd() { sudo dnf install --assume-yes "$*" && echo "$*" >>~/install_apt-get.txt; }
alias sound='alsamixer'
# alias open='xdg-open'
alias st='scrot -ub '"'"'%Y:%m:%d:%H:%M:%S.png'"'"' -e '"'"'mv $f ~/Downloads/'"'"
alias catquestions='cat ~/Documents/Q.txt'
alias mountrw='mount -o remount,rw /'
alias vim='vim -o'
alias ls='ls --human-readable --color -lFG'
fi
# General purpose
alias vimb='vim ~/.bashrc'
alias vima='vim ~/.aliases'
alias vimr='vim ~/.remember'
alias vimexecdwm='sudo vim /usr/local/bin/dwm-personalized'
alias vimv='vim ~/.vimrc'
alias vimq='vim ~/Documents/Q.txt'
alias gq='gedit ~/Documents/Q.txt'
alias vimdwmconfig='vim ~/dwm/config.h'
alias cx='chmod +x'
alias dc='cd'
alias m='man'
alias mm='man $(fc -ln -1 | cut -d" " -f 1)'
alias l='ls'
alias v='vim'
alias grep='grep --color -i'
alias rmf='rm --recursive --force'
alias o='rlwrap ocaml'
alias rpm='sudo rpm'
# System commands
alias free='free -h'
alias wgetdir='wget --recursive --no-parent '
function wgetdir2() {
wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains website.org \
--no-parent "$1"
}
# Programming etc.
alias m='make'
alias c99='gcc -std=c99'
alias g++='g++ -g -Wall -O3'
alias mountstudents='sshfs [email protected]: /Users/antoni/students'
alias students='export TERM=vt100 ; ssh students.mimuw.edu.pl -l ar267209 -t tmux a'
alias icm='ssh [email protected]'
alias icmgw='ssh [email protected]'
#alias wget='curl -0'
alias xcode="open *.xcodeproj"
function tarfolder() { tar -czf "$1".tar.gz "$1"/*; }
function zipfolder() { zip --recurse-paths "$1".zip "$1"/*; }
function zipfolder_with_password() { zip --encrypt --recurse-paths "$1".zip "$1"/*; }
# SSH
alias sendstud='~/scripts/sendstud.sh'
alias sendicm='~/scripts/sendicm.sh'
# Android development
alias adbd='adb devices'
alias adbreset='adb kill-server;adb start-server'
# Git
alias g='git'
alias gitpu='git pull'
alias gitpua='git push --all -u'
alias gits='git status --short'
alias gitc='git commit -am'
alias gitca='git commit --amend -m'
alias gitch='git checkout'
alias gitcl='git clean -d --force'
alias gitd='git diff'
alias gd='git diff'
alias gitm='git merge'
alias gitb='git branch'
alias gitk='gitk --all'
alias gitundocommit='git reset --soft HEAD~1'
alias grb='git rebase master'
alias grm='git rebase master'
alias grd='git rebase develop'
alias gri='git rebase integration'
alias gd='git diff'
alias gcw='git commit --message="WIP $(date)"'
alias gcm='git checkout master'
alias gg='git add -A && gcw && git squash 2'
alias gp='git pull'
alias gra='git rebase --abort'
alias grc='git rebase --continue'
alias grs='git rebase --skip'
alias gsa='git stash apply'
alias gpom='git push origin master'
alias gca='git commit --amend'
alias gacw='git add . && gcw'
alias gcb='git checkout -b'
# Set `indent` parameters according to Linux kernel Coding Style
#alias indent='indent -kr -i8'
alias indent='indent -i8 -nbad -bap -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -i4 -ip0 -l75 -lp -npcs -npsl -nsc -nsob'
# Kill all jobs
alias kj='kill -9 $(jobs -p)'
# tmux
alias tm='tmux'
alias tma='tmux attach'
alias tmxa='tmux attach'
alias tmxl='tmux list-window'
# cd directory up
alias ..="cd .."
alias ....="cd ../.."
alias ......="cd ../../.."
# Helper functions
# function gg() { pwd > /tmp/last_path; }
# function hh() { cd $(cat /tmp/last_path); }
alias webserver='python3 -m http.server --bind localhost 8080'
alias s='webserver'
alias gprer='grep --recursive'
alias hgrep='history | grep -i'
# tmux && source ~/.paths'
alias gopath="export GOPATH=\$(pwd)"
alias dbgui='/usr/share/dbeaver/dbeaver'
function singlemonitor() {
primary=$(xrandr | \grep "connected primary" | cut -d' ' -f1)
secondary=$(xrandr | \grep " connected" | \grep -v "primary" | cut -d' ' -f1)
if [[ $secondary ]]; then
xrandr --output "$secondary" --off --output "$primary" --auto
else
xrandr --output "$primary" --off
xrandr --output "$primary" --auto
fi
}
# alias dualmonitor='xrandr --output VGA1 --mode 1920x1200 --right-of LVDS1'
alias dualmonitor='xrandr --output HDMI-1 --mode 1680x1050 --right-of eDP-1'
alias dualmonitor2='xrandr --output VGA1 --mode 1680x1050 --right-of LVDS1'
alias dualmonitor_left='xrandr --output VGA1 --mode 1920x1200 --left-of LVDS1'
alias dualmonitor_ktech='xrandr --output HDMI-1 --mode 2560x1440 --right-of eDP-1'
alias dualmonitor_ktech_pres='xrandr --output HDMI-1 --mode 1920x1080i --right-of eDP-1'
alias dualmonitor_mirror='xrandr --output eDP-1 --rate 60 --mode 1920x1080 --fb 1920x1080 --panning 1920x1080* --output HDMI-1 --mode 1920x1080 --same-as eDP-1'
# Fixing various things on Ubuntu
alias fixaudio='pulseaudio -k'
alias fixaudio2='pavucontrol'
alias fixaudio3='rm -r ~/.config/pulse; pulseaudio -k'
function fixpowerctl() {
for device in /sys/bus/usb/devices/*/power/control; do
echo on >"$device"
done
}
alias fixtouchpad='sudo rmmod psmouse && sudo modprobe psmouse'
alias ubuntu_fix_apt='sudo apt-get install --fix-broken && sudo apt-get autoremove && sudo apt-get update'
# Markdown to PDF
function md2pdf() {
local -r filename=$(filename_without_extension "$1")
pandoc --standalone --variable=papersize:a4 --variable=geometry:margin=1in --from=gfm -o "$filename".pdf "$filename".md
open "$filename".pdf
}
function rst2pdf() {
pandoc --standalone -V papersize:a4 -V geometry:margin=1in --from rst -o "$1".pdf "$1"
open "$1".pdf
}
# Serves github-rendered Markdown file (from .) on localhost:6419
alias md2html='grip'
# LaTeX
alias latexed1='texmaker'
alias latexed2='gummi'
alias gogo='cd ~/go/'
alias l='ls'
function csview() {
local file="$1"
sed -e 's/,,/, ,/g' <"$file" | column -s, -t | less -#5 -N -S
}
# Custom cat: colourised and tabulated for CSV files alias cat='pygmentize -g'
function xcat() {
filename=$(basename "$1")
fileext=${filename##*.}
if [ "$fileext" = "csv" ]; then
csview "$1"
else
pygmentize -g "$1"
fi
}
# Google search
function search() {
args="$*"
searchterm=${args// /%20}
open "http://www.google.com/search?q=$searchterm"
}
# Launch Vim solarized theme depending on the time of the day
function vv() {
echo "$1"
hour=$(date +%H)
theme=dark
if [[ $hour -ge 6 && $hour -le 17 ]]; then
theme=light
fi
terminator -l vim-solarized-$theme -c "vim -c 'set gb=$theme'"
}
# Use less +F instead of tail -f
# function tail() {
# if [ "$1" == '-f' ]; then
# shift
# less +F "$@"
# else
# command tail "$@"
# fi
# }
# Display 20 most frequently used commands in Bash
alias mostfrequent='history | cut -d " " -f 4 | tr -c "[:alnum:]" "[\n*]" | sort | uniq -c | sort -nr | head -20'
# 20 Command Line Tools to Monitor Linux Performance
debug_commands=(ddd kdbg idaq cgdb)
perf_commands=(top vmstat tload stress lsof tcpdump netstat htop atop iotop iostat iptraf iftop monitorix monit arpwatch vnstat dstat nmon collectl dig mpstat pkill powertop pidstat intel_gpu_top glances pstree nload sysstat sysdig)
hex_editors=(jeex okteta hte bless wxHexEditor dhex)
other_commands=(ruptime rwho)
# Networking
networking_commands=(netstat ethtool ping ifconfig arping traceroute iwconfig ifconfig tshark nethogs nmap nbtscan iptables tcpdump iproute2 chargen netcat tc insmod fping nslookup host p0f mtr ipcalc sipcalc iperf)
function whichport() {
netstat -tulpn | grep "$@"
}
# ip a s #List addresses for interfaces
# ip link show#List network interfaces
# ip route show #List routing table
# ip neigh Same#Show neighbors
# ip r add default via $ip0#Set default gateway to $ip
# ethtool eth0#Show status of ethernet interface eth0
# ip link set dev eth0 up/down#Bring interface eth0 up (or down)
# iwlist scan#List wireless networks in range
# fping is handy, sends lots of pings without waiting for responses, so you can rapidly ping a whole address range
# ping6 is to ping IPV6 address.
# Same for networking_commands
# random number (array len) to choose random command
alias ftp='filezilla'
# Python modules
alias pi='sudo pip install'
alias piu='sudo pip-review --interactive'
alias pil='pip list'
# Execute nth line of a file
function execute_nth_line_of_file() {
eval "$(sed "$1"'q;d' "$2")"
}
# Countdown, usage:
# countdown 60
# countdown $((2*60*60))
function countdown() {
date1=$(($(date +%s) + $1))
while [ "$date1" -ne "$(date +%s)" ]; do
echo -ne "$(date --universal --date @$((date1 - $(date +%s))) +%H:%M:%S)\r"
sleep 0.1
done
}
# Stopwach, usage:
# stopwatch
function stopwatch() {
date1=$(date +%s)
while true; do
echo -ne "$(date --universal --date @$(($(date +%s) - date1)) +%H:%M:%S)\r"
sleep 0.1
done
}
function mvd() { mv "$1" ~/Downloads/; }
# Utils
# Print primitive data types sizes
alias typesizes='perl -V | grep size='
alias interrupts1='cat /proc/interrupts' # Get processor interrupts
alias memory1='cat /proc/meminfo'
alias disktest='sudo smartctl -a /dev/sda | less'
alias dmesg='dmesg -T'
alias dmesgerrors="dmesg | egrep 'error|fail|bug|rtl8|r8|wlan'"
alias irc='hexchat'
alias showdirsizes='du -Pshx * 2>/dev/null'
alias resetsound='pulseaudio -k && sudo alsa force-reload'
alias ns='nvidia-smi'
alias idrsa='cat ~/.ssh/id_rsa.pub'
alias iphone='~/scripts/setup_iphone.sh'
alias i='iphone'
alias pdfmerge='pdfunite'
alias desk='cd ~/Desktop'
alias mountstudents='sudo sshfs -o allow_other [email protected]:/home/students/bioinf/a/ar267209 ~/mount/students/'
alias euler='cd ~/Developer/ProjectEuler/'
alias wallpaperchange='gsettings set org.gnome.desktop.background picture-uri "file:///home/antoni/Documents/wallpaper4.jpg"'
alias showtunnels="sudo lsof -i -n | egrep '\\<ssh\\>'" # Show all open SSH tunnels
alias rsync='rsync --progress'
alias wificonn='sudo wifi-menu wlp2s0'
alias install_ycm='~/.vim/bundle/YouCompleteMe/install.sh --clang-completer'
alias cal='gcalcli'
alias dhcp0='sudo dhcpcd -n eth0'
alias top10size="find . -type f -printf '%s %p\n'| sort -nr | head -10"
dl_website() {
wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--no-parent \
"$1"
}
# cd ../../../
function up() {
how_many_levels="$1"
while [ "$how_many_levels" -gt 0 ]; do
cd ..
how_many_levels=$((how_many_levels - 1))
done
}
# JSON pretty print
alias json_pretty_print='python -m json.tool'
alias jsonpp=json_pretty_print
# Git
function gc() {
git commit -am "$*"
}
function gcp() {
gc "$*"
git push
}
alias svim='sudo vim'
alias gv='gvim'
# endiannes:
# echo -n I | od -to2 | head --lines=1 | cut -f2 -d" " | cut -c6
# Show errno errors
alias showerrors="cpp -dM /usr/include/errno.h | grep 'define E' | sort -n -k 3"
alias sourcetmux='tmux source-file ~/.tmux.conf'
alias p='python3'
alias fixandroidstudio='IBUS_ENABLE_SYNC_MODE=1 ibus-daemon -xrd'
function diffcount() {
diff --unified=0 "$1" "$2" | grep -c ^@
}
function dark_background() { export BACKGROUND=dark && source "$HOME"/.common_profile.sh; }
function light_background() { export BACKGROUND=light && source "$HOME"/.common_profile.sh; }
alias rmcmd='sudo apt-get remove'
alias autoremove='sudo apt-get autoremove'
alias redisgui='redis-desktop-manager'
function g++gtest() {
g++ -std=c++11 "$1" -lgtest -lpthread && ./a.out
}
# Links all .o files to make elf_i386 executable
function link() {
# Default value = test
BIN=${1:-test}
ld -m elf_i386 -s -o "$BIN" ./*.o
}
# GCC flags:
# -fverbose-asm -S
function compile() {
nasm -f elf "$1"
}
alias burn_iso='wodim'
# Recursive chmod, usage:
# chmod_rec +rx
function chmod_rec() {
# find . -type d -exec chmod +rx {} \;
find . -type d -exec chmod "$1" {} \;
}
alias make='make -j 4'
alias gitresettoremote='git fetch origin ; git reset --hard origin/master'
alias rmp='rm ~/Pictures/Screenshot*'
alias i3wmreset='i3-msg "reload"'
# Check if port is open:
alias checkopenports='netstat -ano|grep 443|grep LISTEN'
alias classdiagram='staruml'
alias tmuxhelp='cat ~/dotfiles/tmux.cheat | less'
# Linux
alias show_available_entropy='cat /proc/sys/kernel/random/entropy_avail'
alias dns_list_all='dig +nocmd yourdomain.com any +multiline +noall +answer'
alias install_ycm='~/.vim/bundle/YouCompleteMe/install.py --clang-completer --gocode-completer'
alias switchm="xrandr --output VGA1 --left-of DP2" # switches monitors (left-right)
alias di='sudo dnf install --assumeyes'
alias ds='dnf search -C'
alias dr='sudo dnf remove'
function rdp() { rdesktop "$@" -rsound:remote -5 -K -r clipboard:CLIPBOARD; }
function swap() {
local TMPFILE=tmp.$$
mv "$1" $TMPFILE
mv "$2" "$1"
mv $TMPFILE "$2"
}
# Copies SSH RSA key to X clipboard
alias copy_ssh_public_key_to_clipboard='cat ~/.ssh/id_rsa.pub | copy_to_clipboard'
function dnfs() {
arg_count="$#"
if [ $arg_count -eq 2 ]; then
dnf search "$1" | grep "$2"
elif [ $arg_count -eq 1 ]; then
dnf search "$1"
fi
}
alias cups='lpstat' # -p -d
alias zsh_debug='zsh -i -x -c exit'
function fix_zsh_history() {
cd "$HOME" >/dev/null || exit
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad >.zsh_history
fc -R .zsh_history
}
function fix_permissions() {
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
}
function get_ip() {
host "$1" | awk '/has address/ { print $4 }' | head --lines=1
}
# Query Linux man page for certain flag
# Example: manf iptables -t
function manf() {
man "$1" | less -p "^ +\-${2}"
}
alias dmidecode='sudo dmidecode'
alias ipconfig='ifconfig'
alias remove_all_docker_images='docker rm -vf $(docker ps -aq)'
# Delete all containers & all images
function docker_remove_all() {
~/scripts/docker_remove_all.sh
}
function list_installed() {
dnf list installed | awk --field-separator. -v ORS="\0" '{print $1" "}' | sort -zu && echo ""
}
# $1 - name of the folder to zip
function zip_and_move() {
zip --recurse-paths ~/Downloads/"$1".zip "$1"/* "$1"/.*
}
# Download .gitignore
# Usage: gitignore language
function gitignore() {
local -r language_name="$1"
curl -L -s "https://www.gitignore.io/api/""$language_name" | awk 'NR>2 {print last} {last=$0}' | tee .gitignore
}
# Helper for watch_dir
function watch_dir_action() {
while read -r path action file; do
printf "[${colors[Green]}%s${colors[White]}]\t${colors[Red]}%s${colors[Reset_Color]}\tin\t%s\n" \
"$action" "$file" "$path"
done
}
# $1 - dir to be watched for CREATE or MOVED_TO events
function watch_dir() {
inotifywait -m "$1" -e create -e moved_to | watch_dir_action
}
HTML_TIDY_TMP_FILE="/tmp/tidy_log.txt"
# Reformats JS/JSON/HTML code
# Usage:
# ./reformat filename
function reformat() {
tmpf=/tmp/in_place_change_tmp
filename=$(basename "$1")
ext="${filename##*.}"
echo "File extension: ""$ext"
case $ext in
"md")
# Reformat against Github's Markdown styleguide
pandoc --write=markdown --to=markdown_github "$1" >"$tmpf"
;;
"js")
eslint --fix "$1" >"$tmpf"
;;
"jsx")
prettier --write "$1"
;;
"json")
jq -M '.' >"$tmpf" <"$1"
;;
"py")
autopep8 --in-place "$1"
;;
"html")
tidy -indent -wrap 80 -utf8 -clean -file $HTML_TIDY_TMP_FILE "$1" >"$tmpf"
;;
esac
mv -f "$tmpf" "$1" 2>/dev/null
}
# Toggles VPN connection
function vpn() {
vpn_conn="VPN"
vpn_cmd="up"
if nmcli connection show --active | grep -q VPN; then
vpn_cmd="down"
fi
nmcli connection $vpn_cmd id $vpn_conn | tr ' ' '\n' | \grep --color activated
}
function redshift_loc() {
redshift-gtk -v -l "$DEFAULT_COORDS"
}
function weather() {
curl --silent wttr.in/"${1:-$DEFAULT_CITY}" | head --lines=7
}
# Prints aggregated %MEM for a process ($1)
function total_mem() {
top -b -n1 | \grep "$1" | awk '{ SUM += $10} END { print SUM }'
}
# Edit last gnome-screenshot taken
function nomacslast() {
files=(~/Pictures/*)
nomacs "${files[-1]}"
}
# encrypt (filename -> filename.enc)
# $1 - input file
# $2 - password
function encrypt() {
openssl enc -aes-256-cbc -in "$1" -out "$1".enc -k "$2"
}
# decrypt (filename.enc -> filename)
# $1 - input file
# $2 - password
function decrypt() {
openssl enc -aes-256-cbc -d -in "$1".enc -out "$1" -k "$2"
}
# SSH and attach to tmux
function sshtmux() {
ssh "$1" -t tmux a
}
function pip_list() {
pip3 list --format=columns | awk '!/Package|---/{ print $1}'
pip list --format=columns | awk '!/Package|---/{ print $1}'
}
function reinstall_pip_packages() {
DISPLAY="" pip3 list --outdated | awk '{print $1}' | tail -n +3 |
DISPLAY="" xargs --I % sh -c 'pip3 install --upgrade --force-reinstall %'
}
function reinstall_python() {
sudo apt-get remove --assume-yes python python3 python3-pip
sudo apt-get install --assume-yes python python3 python3-pip
}
function merge_and_push_branch() {
"$HOME"/scripts/merge_and_push_branch.sh "$1"
}
function response_time() {
FORMAT_PATH=$(realpath ~/scripts/curl-format.txt)
curl -w "@""$FORMAT_PATH" -o /dev/null -s "$1"
}
# Example
# how_in bash get length of array
function how_in() {
where="$1"
shift
IFS=+ curl "https://cht.sh/$where/ $*"
}
# TESTIT
# Add changes to a selected commit.
# Usage:
# * modify file
# * git-amend-to $old_sha
git-amend-to() (
# Stash, apply to past commit, and rebase the current branch on to of the result.
current_branch="$(git rev-parse --abbrev-ref HEAD)"
apply_to="$1"
git stash
git checkout "$apply_to"
git stash apply
git add -u
git commit --amend --no-edit
new_sha="$(git log --format="%H" -n 1)"
git checkout "$current_branch"
git rebase --onto "$new_sha" "$apply_to"
)
alias pr='~/scripts/pull_request.sh'
alias pr_merge='~/scripts/pull_request_merge.sh'
alias bci='brew cask install'
# Usage openssl_website google.com:80
alias openssl_website='openssl s_client -connect -crlf'
function json_compare() {
diff <(jq -S . "$2") <(jq -S . "$2")
}
function pdf_compress() {
local input_file=$1
local output_file=${2:-$1_output.pdf}
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$output_file" "$input_file"
}
# function diff {
# colordiff --unified "$@" | less --RAW-CONTROL-CHARS --quit-if-one-screen
# }
alias sizes='du -sh * | sort -hr'
alias speedtest='curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -'
function android_update() {
android update sdk --no-ui
}
function last_modified_directory() {
# shellcheck disable=2012
\ls -t | head --lines=1
}
# Does a subsitution in filenames in all files in the current directory
# See lowercase_first_letter for example use case
function convert_all_files() {
local substitution="$1"
# shellcheck disable=SC2016
$BASH -c 'for filename in *;do mv "$filename" ${filename'"$substitution"'};done'
}
# Spaces to underscores
function spaces_to_underscores() {
convert_all_files "// /_"
}
# Lowercase the first letter
function lowercase_first_letter() {
convert_all_files ","
}
# Uppercase first letter
function uppercase_first_letter() {
convert_all_files "^"
}
# Lowercase all letters
function lowercase_all_letters() {
convert_all_files "m,"
}
# Uppercase all letters
function uppercase_all_letters() {
convert_all_files "^^"
}
alias buildlib='cd ~/components-library ; npm run build && firebase deploy && npm run clean'
alias mac_serial_number="system_profiler SPHardwareDataType | \grep ' Serial Number' | cut -d' ' -f 10 | pbcopy"
# Updates scripts repo with current date in the message
# of the (possibly empty) commit
function update_scripts_repo() {
pushd ~/scripts || exit
git add .
git commit --allow-empty --message "Update ""$(date +%d-%m-%Y)"
git push origin
popd || exit
}
alias nrs='npm run start'
alias ys='yarn start'
alias yi='yarn install'
alias yt='yarn test'
alias yc='yarn run clean'
alias yrc='yarn run clean'
function mcd() {
mkdir "$1" && cd "$1" || exit
}
alias npmu='npm install -g npm'
alias yarnnoproxy='yarn --no-default-rc'
alias rmrf='rm --recursive --force'
alias tmux2x2='tmux new-session \; split-window -v \; split-window -h \; select-pane -t 0 \; split-window -h\; select-pane -t 0;'
alias removevpn='brew cask remove nordvpn || brew cask install nordvpn'
alias nvm_default='nvm alias default node'
alias nvm_current='nvm install node --reinstall-packages-from=$(nvm current)'
function mov2mp4() {
local -r filename=$(filename_without_extension "$1")
ffmpeg -i "$filename".mov -vcodec h264 -acodec mp2 "$filename".mp4
}
# Rename part of filename in each file in a directory
# Usage:
# rename_filename_part " " "_"
function rename_filename_part() {
for filename in *; do
mv "$filename" "${filename/$1/$2}" || return
done
}
# Remove part of filename in each file in a directory
function remove_filename_part() {
for filename in *; do
[ -f "$filename" ] || continue
mv "$filename" "${filename//$1/}"
done
}
function add_prefix_to_filename() {
local prefix=$1
for filename in *; do
[ -f "$filename" ] || continue
mv "$filename" "$prefix$filename"
done
}
function add_suffix_to_filename() {
local suffix=$1
for filename in *; do
[ -f "$filename" ] || continue
name=$(filename_without_extension "$filename")
extension=$(filename_extension "$filename")
mv "$filename" "$name$suffix.$extension"
done
}
# Prints the lsof entry of the process that listens on a given port
# Usage:
# listening firefox
# listening 8080
function listening() {
if [ $# -eq 0 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P
elif [ $# -eq 1 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color "$1"
else
echo "Usage: listening [pattern]"
fi
}
function get_cookies() {
local url=$1
cgurl --silent --output /dev/null --cookie-jar - "$url"
}
# Ubuntu
function toggle_wifi() {
wifi="$(nmcli r wifi | awk 'FNR = 2 {print $1}')"
if [ "$wifi" == "enabled" ]; then
nmcli r wifi off
else
nmcli r wifi on
fi
}
# One-liner to generate Self-Signed SSL Certificate+Key without any annoying prompts or CSRs
function generate_self_signed_certificate() {
openssl req -new -newkey rsa:4096 -days $((5 * 3650)) -nodes -x509 -subj "/C=<Country Code>/ST=<State>/L=<City>/O=<Organization>/CN=<Common Name>" -keyout certificate.key -out certificate.crt
}
function sync_branch_with_master() {
git reset --hard origin/master && git fp
}
function resize_to_icon() {
local input_file=$1
local output_file=$2
convert "$input_file" -thumbnail '1024x1024>' -gravity center -background transparent -extent 1024x1024 "$output_file"
}
function reinstall_cocoapods() {
sudo gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoapods
}
function force_remove_brew_cask() {
local cask_name=$1
rm --recursive --force "$(brew --prefix)/Caskroom/$cask_name"
}
alias killfsck='sudo pkill -f fsck'
alias prettify="yarn prettier:fix && gc \"chore: Run Prettier on the entire project\""
function copy_as_base64() {
local file_path=$1
openssl base64 <"$file_path" | tr -d '\n' | copy_to_clipboard
}
function display_notification() {
local title=$1
local message=$2
osascript -e "display notification \"$message\" with title \"$title\""
# Growl alternative
# growlnotify -n "$title" -m "$message"