While I study in the Web Development Immersive course at General Assembly, I regularly visit a particular folder of mine called WDI7. I keep this folder in my Dropbox for safe keeping. However, every time I open a new terminal, I have to navigate down to this folder. This is proving to be a bit of a boring/repetitive task.
So, to fix this problem, I decided to create an alias to effectively shortcut to this folder. Below are instructions showing how to add a shortcut into your terminal so you can cut down on keystrokes. These instructions are for Mac but may work for Linux too.
First up, I navigate to the folder in question and perform a pwd command:
pwd => /Users/my_username/Dropbox/stuff/2016/WDI-7
I copy this or take note for later.
Next up we need to open the
.bash_aliases file which allows users to shortcut commands in terminal. This file may be called
.bashrc in Linux, and is located in the ~ home directory.
Open it in your editor of choice, mine being Atom:
Now we need to create an alias to the command we are constantly undertaking. I have decided to call the alias
wdi because I have no other programs running off that command and it’s unlikely to clash with anything else.
To create the alias, I add this line to the
bash_aliases file, hit save and quit fully out and then restart the terminal app.
alias wdi="cd /Users/my_username/Dropbox/stuff/2016/WDI-7"
Now every time I type in
wdi I get redirected into my WDI-7 folder. Easy!
wdi pwd => /Users/my_username/Dropbox/stuff/2016/WDI-7
However, I like the idea of being shown my directory once I run the command. To do this I normally would run another
pwd. To append this to the alias, all I have to do is modify the code as follows:
alias wdi="cd /Users/my_username/Dropbox/stuff/2016/WDI-7; pwd"
Now each time I run
wdi, I am taken to my directory and I am reminded that I am here! Pretty useful!