.bash_aliases 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # Basic .bash_alias file for command line shortcuts
  2. # Save this as ~/.bash_aliases
  3. # On your ~/.bashrc add `. ~/.bash_aliases`
  4. # Reboot or relogin
  5. # To try without reboot (on current bash session), run `touch ~/.bash_aliases`
  6. ## ---- Package Manager based... ---- ##
  7. if [ -x "$(command -v apt)" ]; then
  8. # Debian based
  9. alias update-system='sudo apt update && sudo apt upgrade -y ; sync'
  10. alias install-package='sudo apt install -y '
  11. alias remove='sudo apt autoremove -y '
  12. alias search='apt search '
  13. alias clean-packages='sudo apt clean'
  14. elif [ -x "$(command -v pacman)" ]; then
  15. # Arch linux based
  16. alias update-system='sudo pacman -Syu --noconfirm ; sync'
  17. alias update-mirrors='sudo reflector --verbose --latest 5 \
  18. --sort rate --save /etc/pacman.d/mirrorlist'
  19. alias install-package='sudo pacman --noconfirm -S '
  20. alias remove='sudo pacman --noconfirm -Rs '
  21. alias search='pacman -Ss '
  22. alias clean-packages='sudo pacman -Scc'
  23. alias find-pacs='find /etc -regextype posix-extended \
  24. -regex ".+\.pac(new|save)" 2> /dev/null'
  25. elif [ -x "$(command -v xbps-install)" ]; then
  26. # Void Linux based
  27. alias update-system='sudo xbps-install -Syu ; sync'
  28. alias install-package='sudo xbps-install -y '
  29. alias remove='sudo xbps-remove -Ry '
  30. alias search='xbps-query -Rs '
  31. alias clean-packages='sudo xbps-remove -O'
  32. elif [ -x "$(command -v zypper)" ]; then
  33. # Suse based
  34. alias update-system='sudo zypper refresh && sudo zypper refresh ; sync'
  35. alias install-package='sudo zypper install -y '
  36. alias remove='sudo zypper remove -y '
  37. alias search='zypper search '
  38. alias clean-packages='sudo zypper clean metadata && sudo zypper clean packages'
  39. elif [ -x "$(command -v rpm)" ]; then
  40. # RPM based
  41. alias update-system='sudo yum -y update ; sync'
  42. alias install-package='sudo yum install -y '
  43. alias remove='sudo yum remove -y '
  44. alias search='yum search '
  45. alias clean-packages='sudo yum clean metadata && sudo yum clean packages'
  46. elif [ -x "$(command -v guix)" ]; then
  47. # Guix/GuixSD based
  48. alias update-system='guix pull && guix package -u ; sync'
  49. alias install-package='guix install '
  50. alias remove='guix remove '
  51. alias search='guix search '
  52. elif [ -x "$(command -v pkg)" ]; then
  53. # FreeBSD systems
  54. alias update-system='sudo pkg update && sudo pkg upgrade -y ; sync'
  55. alias install-package='sudo pkg install -y '
  56. alias remove='sudo pkg remove -y '
  57. alias search='pkg search '
  58. alias clean-packages='sudo pkg clean -y'
  59. fi
  60. ## ---- Service Related ---- ##
  61. # usage: handleService start|stop|restart|enable|disable <service name>
  62. handleService() {
  63. if [ -x "$(command -v systemctl)" ]; then # for SystemD
  64. if [ `systemctl list-unit-files -l | grep -q '^${2}.service'` ]; then
  65. sudo systemctl ${1} ${2}
  66. else
  67. echo "$2 service not found"
  68. fi
  69. # The "-f" check should be first for FreeBSD
  70. elif [ -f "/usr/sbin/service" ] || [[ "$(cat /proc/1/comm)" = "init" ]]; then # for SysVinit or "service" binary
  71. sudo service ${2} status # if it fails it will return non-zero value
  72. if [ "$?" = "0" ]; then
  73. sudo service ${2} ${1}
  74. else
  75. echo "$2 service not found"
  76. fi
  77. elif [[ "$(cat /proc/1/comm)" = "runit" ]]; then # for runit
  78. if [ -d "/etc/runit/runsvdir/current/${2}" ]; then
  79. if [ ${1} == 'enable' ]; then
  80. if [ -d '/etc/runit/sv/' ]; then # Artix
  81. sudo ln -s /etc/runit/sv/${2} /etc/runit/runsvdir/current/${2}
  82. else
  83. sudo ln -s /etc/sv/${2} /etc/runit/runsvdir/current/${2}
  84. fi
  85. elif [ ${1} == 'disable' ]; then
  86. sudo rm /etc/runit/runsvdir/current/${2}
  87. else
  88. if [ -d /etc/runit/runsvdir/current/${2} ]; then
  89. sudo sv ${1} ${2}
  90. fi
  91. fi
  92. else
  93. echo "$2 service not found"
  94. fi
  95. fi
  96. }
  97. alias start-service='handleService start'
  98. alias stop-service='handleService stop'
  99. alias restart-service='handleService restart'
  100. alias enable-service='handleService enable'
  101. alias disable-service='handleService disable'
  102. handleServer() {
  103. handleService ${1} apache
  104. handleService ${1} apache2
  105. handleService ${1} httpd
  106. handleService ${1} mariadb
  107. handleService ${1} mysqld
  108. }
  109. alias start-server='handleServer start'
  110. alias stop-server='handleServer stop'
  111. alias restart-server='handleServer restart'
  112. # killall alternative for systems without it
  113. if [ ! -x "$(command -v killall)" ]; then
  114. killall () {
  115. echo `pidof $1` && sudo kill -9 `pidof $1` || echo "$1 not running"
  116. }
  117. fi
  118. ## ---- Git Related ---- ##
  119. git_root_command () {
  120. if [ -d ".git" ]; then
  121. if [ -z "$2" ]; then
  122. eval $1
  123. else
  124. # printf is to escape string/input
  125. eval $1 "$(printf "%q" "$2")"
  126. fi
  127. else
  128. echo "ERROR: Not a git repo root dir"
  129. fi
  130. }
  131. alias gtpull='git pull --ff-only'
  132. alias gtpush='git push'
  133. alias gts='git status'
  134. alias gtd='git diff'
  135. alias gtac='git_root_command "git add . && git commit -m "'
  136. alias gtrevert='git_root_command "git reset && git checkout . && git clean -fdx"'
  137. alias gtcl='git config --list'
  138. alias gtc='git config'
  139. ## ---- Misc ---- ##
  140. alias list='ls -hN --color=auto --group-directories-first'
  141. alias update-grub='sudo grub-mkconfig -o /boot/grub/grub.cfg'
  142. alias download-youtube='youtube-dl --write-auto-sub --embed-subs \
  143. -f "(mp4)[height<480]" '
  144. alias list-groups='cut -d: -f1 /etc/group | sort'
  145. if [ -x "$(command -v nvim)" ]; then
  146. alias v='nvim'
  147. elif [ -x "$(command -v vim)" ]; then
  148. alias v='vim'
  149. elif [ -x "$(command -v vi)" ]; then
  150. alias v='vi'
  151. fi
  152. alias show-metadata='exiftool '
  153. alias strip-metadata='exiftool -all= -overwrite_original'
  154. alias run-qemu="qemu-system-$(uname -m) -m 1024 -net nic -net user \
  155. -soundhw all -machine accel=kvm -cdrom "
  156. alias update-vpns='sudo python3 ~/.scripts/autovpngate.py'
  157. alias ip-info='if [ -x "$(command -v curl)" ]; then curl -s https://ifconfig.co/json|json_pp; else wget -qO- https://ifconfig.co/json|json_pp; fi'
  158. alias cpu-usage="awk '{u=\$2+\$4; t=\$2+\$4+\$5; if (NR==1){u1=u; t1=t;} \
  159. else print (\$2+\$4-u1) * 100 / (t-t1) \"%\"; }' \
  160. <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat)"
  161. internal_battery_usage() { for bn in /sys/class/power_supply/BAT*; do [ -d "${bn}" ] && echo "Battery ${bn:27:1}: $(cat ${bn}/capacity)% ($(cat ${bn}/status))"; done }
  162. alias battery-usage='internal_battery_usage'
  163. # Budgie related
  164. alias restart-budgie='nohup budgie-panel --replace&'
  165. # GNOME related
  166. alias launch-dark='setsid env GTK_THEME=Adwaita:dark '
  167. alias start-gnome-wayland='QT_QPA_PLATFORM=wayland XDG_SESSION_TYPE=wayland dbus-run-session gnome-session'
  168. alias start-gnome-xorg='GDK_BACKEND=x11 gnome-session'