I have a whole repository also including several dotfiles that I maintain for already several years [1].
Following are some snippets from the dotfiles/.alias and dotfiles/.functions files from that repository that probably are the most interesting and which I am using on a regular basis:
# easier navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~"
# Get current public ip address
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
# Alias for summing a column
alias mksum="paste -sd+ - | bc"
# Export pbcopy / pbpaste to linux
if [[ "${OSTYPE}" == "linux"* ]]; then
alias pbcopy="xclip -selection clipboard"
alias pbpaste="xclip -selection clipboard -o"
fi
# create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
}
# plot stuff directly from the command line.
# Example: seq 100 | sed 's/.*/s(&)/' | bc -l | plot linecolor 2
# -> Generate 100 numbers, wrap it in s(<num>) and calc sin(<num>)
function plot() {
{ echo 'plot "-"' "$@"; cat; } | gnuplot -persist;
}
# wrapper for easy extraction of compressed files
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.xz) tar xvJf $1 ;;
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.apk) unzip $1 ;;
*.epub) unzip $1 ;;
*.xpi) unzip $1 ;;
*.zip) unzip $1 ;;
*.war) unzip $1 ;;
*.jar) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
You might enjoy replacing your extract function with atool (https://www.nongnu.org/atool/) which provides aunpack. It works similarly, but has niceties like creating and unpacking into a subdirectory to avoid accidentally spraying files all over the current working directory if the archive has multiple files at its root.
How often do you use that and how often do you get it right? :-)
My cd related aliases are the following. Especially the .<number> is surprisingly useful, although most of the time I only use .2 and .3
alias ..='cd ../'
alias .1='cd ../'
alias .2='cd ../../'
alias .3='cd ../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../../'
# sometimes, the space gets swallowed
alias cd.='cd .'
alias cd..='cd ..'
But that gave me an idea for another useful directory changer: "go to project root".
Project root definition could vary, although nowadays it is probably "go to the first directory upstream with a .git directory"
That extract function seems redundant. GNU tar already auto-detects the compression format of the archive, so `tar xvf archive.tar.xz` will work as expected (the J flag is not needed.) bsdtar does the same, and it supports formats other than tar, so `bsdtar xvf archive.zip` works too. These tools use the content of the file rather than the file extension, so they should be more reliable.