Skip to content

Instantly share code, notes, and snippets.

@uolter
Last active December 28, 2015 05:29
Show Gist options
  • Save uolter/7450183 to your computer and use it in GitHub Desktop.
Save uolter/7450183 to your computer and use it in GitHub Desktop.
#!/bin/bash
# save this script in your bin directory source it.
# source cdb.sh
# (it would be nice to do that in your bash profile as well.)
# Then you can run the cdb function in every terminal and bookmark any path you like.s
function show_bookmark {
for f in `ls ~/.cd_bookmarks/`
do
echo "$f -> "`cat ~/.cd_bookmarks/$f`
done
}
function cdb() {
USAGE="Usage: cdb [-c|-g|-d|-l] [bookmark]\nOptions:\n -c Create\n -g Go\n -d Delete\n -l List" ;
if [ ! -e ~/.cd_bookmarks ] ; then
mkdir ~/.cd_bookmarks
fi
case $1 in
# create bookmark
-c) shift
if [ $# -ne 1 ] ; then
echo "missed paremeter ";
echo -e "$USAGE" ;
exit 1;
fi
if [ ! -f ~/.cd_bookmarks/$1 ] ; then
echo "cd `pwd`" > ~/.cd_bookmarks/"$1" ;
else
echo "Try again! Looks like there is already a bookmark '$1'"
fi
;;
# goto bookmark
-g) shift
if [ $# -ne 1 ] ; then
echo "missed paremeter ";
echo -e "$USAGE" ;
exit 1;
fi
if [ -f ~/.cd_bookmarks/$1 ] ; then
source $HOME/.cd_bookmarks/$1 ;
else
echo "Mmm...looks like your bookmark has spontaneously combusted. What I mean to say is that your bookmark does not exist." ;
fi
;;
# delete bookmark
-d) shift
if [ $# -ne 1 ] ; then
echo "missed paremeter ";
echo -e "$USAGE" ;
exit 1;
fi
if [ -f ~/.cd_bookmarks/$1 ] ; then
rm ~/.cd_bookmarks/"$1" ;
else
echo "Oops, forgot to specify the bookmark" ;
fi
;;
# list bookmarks
-l) shift
show_bookmark ;
;;
*) echo -e "$USAGE" ;
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment