The following is taken from a ZSH (not bash or sh) book:
You can use a hash to give a particular directory an alias. This is particularly convenient for your workspace:
% echo $GOPATH
/Users/gfestari/workspace/go
I don't want to type /Users/gfestari/workspace/go
each time I want to reach the src folder in my $GOPATH
directory. So how about putting hash to a good use?
% hash -d gosrc=$HOME/go/src
And now we can get there as quick as typing cd ~gosrc
(pay attention to the leading ~
character).
Here's another example, this time using the /var/www directory
:
% hash -d www=/var/www
% cd ~www
/var/www
You can go ahead and hash your most frequently visited directories. Just remember to add the required entries to your .zshrc
, so you don't have to type the same thing over and over again.
For bonus points, set the AUTO_CD
option, so you only need to input the directory's name whenever you want to change the working directories:
% setopt autocd
% ~www
/var/www