|
|
|
|
|
by jsweojtj
3029 days ago
|
|
I have had this snippet in my `.bashrc` for years. No idea who to give credit to: # eg. save mc
# cd mc # 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
}
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
What this does is, whenever you're in a directory that you'd like to "bookmark" as you'd call it. Just type `save whatevername`. Then, when you navigate somewhere else you can type `cd whatevername` and it'll change you back there. It's simply adding to this ~/.dirs file and so overwriting is taken care of by just saving the same name in a new (or the same) directory. It just appends a line.Also, you can just type `show` and any point and it'll tell you what you've saved and where. The nicest thing is that this persists with new logins (the only drawback is that other shells that are running don't get the update automatically). |
|