# # ~/.bashrc.d/10_common_aliases.sh -- Collection of common bash aliases and functions # # Shortcut aliases alias sorth='sort -hr' alias ps-grep='ps -ef | grep' alias dmesg='sudo dmesg' # Alias expansion for sudo # https://unix.stackexchange.com/questions/148545/why-does-sudo-ignore-aliases/148548#148548 alias sudo='sudo ' # sudo shortcuts for getting root shell or editing files alias sui='sudo -i' alias suvim='sudo -e' # Stop Ctrl-S from doing terminally things in vim/vimdiff vim() { local STTYOPTS="$(stty --save)" stty stop '' -ixoff command vim "$@" stty "$STTYOPTS" } vimdiff() { local STTYOPTS="$(stty --save)" stty stop '' -ixoff command vimdiff "$@" stty "$STTYOPTS" } # yay without parameters does "pacman -Syu" but I don't want it to do this yay() { [[ $# -gt 0 ]] || { echo "error: no operation specified (use -h for help)"; return 1; } command yay "$@" } # Create and cd to temporary directory ~/tmp/tmp.YYYYMMDD.XXXXXX or ~/tmp/tmp.$1.XXXXXX if an argument is given function cdtmp() { cd $(mktemp -d -p ~/tmp tmp.${1:-$(date +%Y%m%d)}.XXXXXX) } # Make dir and cd into it (from Mara) function mkcd() { mkdir -p "$1" cd "$1" } # cd into dir + ll (ls -la) function cdll() { cd "$1" ls -la } # Show content of something, `ls` for dirs (and special files), `cat` for files function lscat() { [[ $# -eq 0 ]] && ls -la && return printnewline="" for f in "$@"; do [[ $printnewline ]] && echo printnewline=1 if [[ -f $f ]]; then [[ $# -gt 1 ]] && echo "-- cat \"$f\"" cat "$f" else [[ $# -gt 1 ]] && echo "-- ls \"$f\"" ls -la "$f" fi done } function calc() { echo "$@" | bc } # termbin.com: terminal pastebin alias termbin='nc termbin.com 9999' # Dump arguments with newlines and quotes function dumpargs() { for a in "$@"; do echo "\"$a\"" done } # Loop sudo to avoid entering password again function sudoloop() { # Run once in foreground to enter password sudo -v || return 1 # Run loop in background { while true; do sudo -v || return 1 sleep 60 done } & } # Shortcuts to encode/decode strings with base64 function b64enc() { echo -n "$1" | base64 -w 0 echo } function b64dec() { echo -n "$1" | base64 -d echo } # Shortcuts for dig with less output alias digs='dig +short' alias digrr='dig +noall +answer'