If you find yourself typing in cd… a lot in MacOS Terminal and you’re running zsh, you can add a shortcut, or alias to your .zshrc resource file. Here’s how:
From a new terminal window, type
nano ~/.zshrc
This will open that resource file in nano and it’s ready for editing.
Scroll all the way to the bottom of the .zshrc file using your down arrow key.
Once at the bottom we’re going to add the alias.
For instance, when I open a Terminal window, I usually want to navigate to my repos on my local machine, which resides in an external drive called “ExternalOne” in a folder called “code”. So my alias would look something like this:
alias repos="cd /Volumes/ExternalOne/code"
So I’m setting up a shortcut to type into Terminal from now on called “repos” that will automatically take me to that code folder on the external drive.
Now once you’ve gotten your alias typed in, you’ll want to type CTRL-X, ‘y’ at the prompt, and then hit enter. Once you’ve successfully saved your changes to the resource file, you’ll want to make sure to reload it so your alias will take effect. Next type in
source ~/.zshrc
If you didn’t mistype your alias line, it should reload the Terminal window using the new changes. Now you can just type in ‘repos’ to take you to that external code folder!