Let’s be honest, the command line is amazing and often saves a TON of time. If you’ve been working in a command line for any amount of time, you’ve likely mentally tucked away several commands that you use frequently. But how can we further optimize the process? Enter Aliases.
An alias is a shell function that allows you to assign existing commands to a an alias to be invoked at a later time. You can use aliases to string together several commands that you often use together or to store a longer or more complex command that takes a significant amount of time to type. Aliases also help reduce errors when typing out longer, more complex commands. In short, aliases can be extremely powerful and save you a ton of time.
It’s easier to show than tell. Below is a simple example of using an alias to navigate to your downloads folder by just typing
alias dl = cd ~/Downloads
Here is a more complex example of using an alias to update the develop and master branches of a git repository with any changes from origin by simply typing
gitup from within the repo:
alias gitup = git fetch && git checkout master && git pull && git checkout develop && git pull
You can quickly begin to see how this can simplify your workflow. You can create an alias for just about anything and once you start implementing them, you'll wonder how you ever lived without them.
Set up is simple. To use aliases, you'll need to add them to your shell configuration file (e.g.
.zshrc, etc). This is most likely located in your home directory. Once added you must apply the changes via
source ~/.zshrc (replace
~/.zshrc with the direct path to your config file) to use your newly added aliases, or you can just restart the terminal.
Here are some aliases I use every day to get you started, but again, you can do pretty much anything with aliases so get creative!
alias ..="cd .." alias dl="cd ~/Downloads" alias phplog="tail -f /Applications/MAMP/logs/php_error.log" alias mysql="/Applications/MAMP/Library/bin/mysql -u root -p" alias gitup="git fetch && git checkout master && git pull && git checkout develop && git pull" alias storm="open . -a PhpStorm" alias tree="open . -a SourceTree"
What are some aliases you use in your daily workflow? Let me know in the comments below!