Skip to content

Instantly share code, notes, and snippets.

@hfs
Created May 25, 2012 09:11
Show Gist options
  • Save hfs/2786858 to your computer and use it in GitHub Desktop.
Save hfs/2786858 to your computer and use it in GitHub Desktop.
Shell directory bookmarks
# Add this to your .bashrc, or paste it into your shell for testing
#
# Bookmarks for directories
#
# Usage:
# bm name -- Create a bookmark for the current working directory
# Bookmarks are saved across sessions in ~/.bookmarks
# to name -- cd to the bookmarked directory
# to -- Dump all bookmarks
#
# Bookmarks are saved in shell variables with the same name. This way they can
# be used in other commands as well:
# vi $name/file.txt
#
bm() {
eval $1=$(pwd)
bm_file=~/.bookmarks
touch $bm_file
perl -ni -e "print unless /^$1=/" $bm_file
echo "$1=$(pwd)" >> $bm_file
}
to() {
if [ "$1" ]; then
eval dir=\$$1
cd "$dir"
else
cat ~/.bookmarks
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment