While managing remote servers, I often find myself having to
cd into a large path, constantly having to write a few letters then hit tab for autocomplete. Today, I ran across a nice snippet you can include in your
.bashrc that allows you to save the current directory for easier future access.
The workflow looks like this:
• Copy the snippet below into your .bashrc, log out and in again.
• Go to the path you wish to save (e.g., /home/user/public_html/public/forums/config)
• write:
save cfg where cfg is the shortcut name
• next type you want to cd into the config direction, all you need to do is write
cd cfg
# Navigation -------------------------------------------------------
alias ..='cd ..'
alias ...='cd .. ; cd ..'
# I got the following from, and mod'd it: http://www.macosxhints.com/article.php?story=20020716005123797
# The following aliases (save & show) are for saving frequently used directories
# You can save a directory using an abbreviation of your choosing. Eg. save ms
# You can subsequently move to one of the saved directories by using cd with
# the abbreviation you chose. Eg. cd ms (Note that no '$' is necessary.)
if [ ! -f ~/.dirs ]; then # if doesn't exist, create it
touch ~/.dirs
fi
alias show='cat ~/.dirs'
save (){
command sed "/!$/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; echo "$@"=\"`pwd`\" >> ~/.dirs; source ~/.dirs ;
}
source ~/.dirs # Initialization for the above 'save' facility: source the .sdirs file
shopt -s cdable_vars # set the bash option so that no '$' is required when using the above facility
I got this code from:
https://gist.github.com/117528