dotfiles/.bashrc.d/10_common_aliases.sh

93 lines
1.8 KiB
Bash

#
# ~/.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 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 tmp dir
alias cdtmp='cd $(mktemp -d -p ~/tmp/)'
# Make dir and cd to it (from Mara)
function mkcd() {
mkdir -p "$1"
cd "$1"
}
# cd to 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
}
# Shortcuts to encode/decode strings with base64
function b64enc() {
echo -n "$1" | base64 -w 0
echo
}
function b64dec() {
echo -n "$1" | base64 -d
echo
}