bash directory bookmarks with autocompletion


Just stick this in your ~/.bashrc

declare -A bookmarks
bookmarks["myproject"]="/home/user/projects/folder/myproject"
bookmarks["tmp"]="/tmp"
keys=${!bookmarks[@]}
function bm {
if [ -z $1 ];then return; fi
local directory=${bookmarks[$1]}
if [ -n "$directory" ];then
cd $directory
else
echo "Directory does not exist"
fi
}
complete -W '$keys' bm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: