How to create aliases for your commands
Table of contents
Imagine reducing the command below:
git fetch && git checkout develop
to a shorter version:
gfc develop
Every time you type a full command when you could have autocompleted, or click when you could have used a shortcut key, you're expending precious limited cognitive power. Keep learning shortcuts for repetitive actions.
In the above command, the command git fetch && git checkout
is replaced with the alias gfc
. This alias could be whatever you wish to term it but make sure to avoid using already defined keywords (e.g npm, cd, touch, git, etc).
To set up an alias on your system. The first thing you need to do is to locate or create the file, .zshrc
or .bashrc
(depending on the shell you are using) in your home directory (~).
Mac - "/Users/your-username/.zshrc"
Linux - "/home/your-username/.zshrc"
Next, open the file with any editor of your choice, in this tutorial, I'll be making use of nano
text editor.
To open the file, launch your terminal, type nano ~/.zshrc
and press enter. Then go to the bottom of the file and add a few aliases with the following syntax:
alias alias_name='command to be replaced'
Done adding these new exciting aliases?๐ You can exit the nano editor by pressing ctrl + x
, then press Y to save changes and then press the enter key.
Restart your terminal and try out these new aliases ๐ฅ.
Happy aliasing!
Subscribe to my newsletter
Read articles from Ugochukwu Ejiogu directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by