Download .cdb, put it into $HOME, put
if [ -f ~/.cdb ]; then . ~/.cdb; fi into ~/.bashrc, you're good!
cdb ([-c|-d] <bookmark>|<bookmark>[/dir[/...]]|-l|-h)
c: create
d: delete
just bookmark: go to that bookmark
l: list
h: help
| #!/bin/bash | |
| function cdb() { | |
| USAGE="Usage: cdb ([-c|-d] <bookmark>[/dir[/...]]|-l|-h)" ; | |
| if [ ! -e ~/.cd_bookmarks ] ; then | |
| mkdir ~/.cd_bookmarks | |
| fi | |
| case $1 in | |
| # create bookmark | |
| -c) shift | |
| if [ ! -f ~/.cd_bookmarks/$1 ] ; then | |
| echo "`pwd`" > ~/.cd_bookmarks/"$1" ; | |
| else | |
| echo "Try again! Looks like there is already a bookmark '$1'" | |
| fi | |
| ;; | |
| # delete bookmark | |
| -d) shift | |
| if [ -f ~/.cd_bookmarks/$1 ] ; then | |
| rm ~/.cd_bookmarks/"$1" ; | |
| else | |
| echo "Oops, forgot to specify the bookmark" ; | |
| fi | |
| ;; | |
| # list bookmarks | |
| -l) shift | |
| for bookmark in ~/.cd_bookmarks/*; do | |
| echo "$(basename $bookmark): $(< $bookmark)" | |
| done | |
| ;; | |
| -h) shift | |
| echo $USAGE | |
| ;; | |
| # goto bookmark | |
| *) | |
| if [ "$1" == "-g" ] ; then | |
| shift | |
| fi | |
| #if [ -f ~/.cd_bookmarks/$1 ] ; then | |
| dirarr=(${1//"/"/ }) | |
| cd $(< ~/.cd_bookmarks/"${dirarr[0]}") | |
| for dir in "${dirarr[@]:1}"; do | |
| cd $dir | |
| done | |
| #else | |
| # echo "Mmm...looks like your bookmark has spontaneously combusted. What I mean to say is that your bookmark does not exist." ; | |
| #fi | |
| ;; | |
| esac | |
| } |