Created
May 25, 2012 09:11
-
-
Save hfs/2786858 to your computer and use it in GitHub Desktop.
Shell directory bookmarks
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
# 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