Skip to content

Instantly share code, notes, and snippets.

@copitux
Created January 23, 2012 13:17
Show Gist options
  • Save copitux/1663070 to your computer and use it in GitHub Desktop.
Save copitux/1663070 to your computer and use it in GitHub Desktop.
Bookmarks in bash shell
# Source: http://hints.macworld.com/article.php?story=20020716005123797
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

Usage

[/home/user]$ cd some/path
[/home/user/project/omg]$ save omg
[/home/user/project/omg]$ cd
[/home/user]$ cd omg
[/home/user]$ cp file $omg

[/home/user]$ show
omg="/home/user/project/omg"
[/home/user]$ $EDITOR ~/.dirs

Sample install

$ curl https://raw.github.com/gist/97b1806058ed33cc2612/3b98af2ba3ceaa596139311337a5750686c8a6cc/bookmarks.bash > ~/.bookmarks.bash
$ echo '. ~/.bookmarks.bash' >> ~/.bashrc
@copitux
Copy link
Author

copitux commented Jan 24, 2012

Awesome!. You've just discovered implicitly the 'error' ;)

We can modify the script like that and each bookmark_dir will be an environment variable so we can use it in Vim

command sed "/!$/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; echo "export $@"=\"`pwd`\" >> ~/.dirs; source ~/.dirs ;

I'm thinking to append some string to bookmark name because I could override some important variable like PATH... or always remember that I have to save bookmarks in lowercase :P

Thanks for your help ;)

PD: Yes, old-school solution is so great too ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment