How to create smart aliases that work on any Unix systems

I love shortcuts and like to do thing quickly. When I have to switch between two unix machines (Mac and my Lenovo Linux), I like to use the same shortcuts (or aliases) regardless of where I am.

One way to a chieve this is to write the alias/script that determine the type of environment it is currently running on.

Why do I need this?

Whenever I plug in the USB external drive into either OSX or Ubuntu, the drive will be mounted in the following location depends on the OS I am on.


So I have the following aliases in my ~/.zshrc (or ~/.bashrc) that allow me to quickly navigate to the same directory using the same shortcut thus remove the need to remember the path for different OS.

# inside your ~/.zshrc or ~/.bashrc
if [[ $platform == 'Linux' ]]; then
  alias g-codes='cd /media/$USER/USB_LABEL/codes'
  # more aliases that work with Linux
elif [[ $platform == 'Darwin' ]]; then
  alias g-codes='cd /Volumes/USB_LABEL/codes'
  # more aliases that work with OSX

Hopefully, this will speed up your workflow and make your day more productive.

Happy Hacking.

comments powered by Disqus