Last active
July 15, 2020 17:49
-
-
Save artem78/74f63a4439b35c8ca04a54d3af378004 to your computer and use it in GitHub Desktop.
Directory bookmarking for Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://stackoverflow.com/q/7374534/4108542 | |
function cdb() { | |
USAGE="Usage: cdb [-c|-g|-d|-l] [bookmark]" ; | |
if [ ! -e ~/.cd_bookmarks ] ; then | |
mkdir ~/.cd_bookmarks | |
fi | |
case $1 in | |
# create bookmark | |
-c) shift | |
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 [ -f ~/.cd_bookmarks/$1 ] ; then | |
source ~/.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 [ -f ~/.cd_bookmarks/$1 ] ; then | |
rm ~/.cd_bookmarks/"$1" ; | |
else | |
echo "Oops, forgot to specify the bookmark" ; | |
fi | |
;; | |
# list bookmarks | |
-l) shift | |
ls -l ~/.cd_bookmarks/ ; | |
;; | |
*) echo "$USAGE" ; | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment