Useful Shell Functions/Aliases

These are some shell (specifically zsh) functions and aliases I use pretty often that I’ve put in ~/.zshrc. I’ve put them here since they could be helpful for someone else. Some are much, much simpler than others, but I’ve put them here anyway. It’ll be updated as time passes.

alias cat='bat' # requires bat (https://github.com/sharkdp/bat)
alias realcat='/bin/cat' # if i ever need to go back to good old cat
alias rm='trash' # requires trash (https://github.com/sindresorhus/trash)
alias reloadrc='exec zsh' # meta
# NOTE: Does not work with the Warp terminal, unfortunately; use source .zshrc instead
# obviously, requires neovim to be installed (https://neovim.io/)
vim() { # self-explanatory
  nvim $@
}
mkcd() { # saves me a few keystrokes
  mkdir $1
  cd $1
}
# requires coreutils to be installed (https://www.gnu.org/software/coreutils/), can be done with brew install coreutils on macOS
gzipped() { # see how much you'd save using gzip (pass the path to the file and a level 1-9, e.g. gzipped /path/to/file 9
  echo Compressed: $(gzip -$2 -c $1 | wc -c | numfmt --to=iec-i --suffix=B --padding=10)
  echo Original: $(cat $1 | wc -c | numfmt --to=iec-i --suffix=B --padding=10)
}
timeshell() { # time your shell startup (taken from https://blog.mattclemente.com/2020/06/26/oh-my-zsh-slow-to-load/)
  shell=${1-$SHELL}
  for i in $(seq 1 10); do /usr/bin/time $shell -i -c exit; done
}

Leave a Reply

Your email address will not be published. Required fields are marked *