Make shortcut for directory in zsh
It is sometimes useful to create a shortcut to frequently used working directories so that I don’t have to type the path every time I open it in the terminal.
Using Aliases
To make an alias persistent, one can add the alias to the zsh configuration file
-
Open configuration file
~/.zshrc -
Create an alias that
cdto the desired directoryalias workdir='cd /path/to/your/directory' # workdir is the name for your shortcut -
Save the file and reload the configuration file
source ~/.zshrc -
Simply type
workdirin the terminal to move to the desired directory
Create variable for the path
This can also be done by creating a variable representing the path for the directory in shell configuration file.
-
Open zsh shell configuration file
~/.zshrc -
Create a variable for the path of the directory you wish to create a shortcut for
workdir="/path/to/your/directory" # workdir is the name for your shortcut -
Save the file and reload the configuration file
source ~/.zshrc -
Use the variable as follows
cd $workdir
Enjoy Reading This Article?
Here are some more articles you might like to read next: