ano.malo.us pretty typical actually..

Directory Bookmarks

After typing cd /Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/site-packages/ for the hundredth time, I decided there had to be a better way. Even with tab completion, it’s a pain to access deeply-nested directories. I know about cdargs but it’s not very flexible and doesn’t work with regular bash commands like cd, cp, mv, etc..

I wrote up a couple of bash functions that save directory bookmarks to a file and make them available as environment variables. To install, download dirmarks.sh and source it from .bashrc or .bash_profile.

Once installed, use mark bookmark_name to save a bookmark for the current directory and use lsmarks search_term to see/grep the list of saved bookmarks. You can then use the bookmark like any other environment variable: cd $bookmark or cat $bookmark/file.txt. The bookmarks are saved in ~/.dirmarks.

The following example usage should clarify what my words have confused:

# lsmarks with any arguments
$ lsmarks
bubble  "/Users/shahad/projects/tg_apps/bubble"
docs    "/Users/shahad/projects/docs"
pebl    "/Users/shahad/projects/pebl"
py      "/Library/Frameworks/Python.framework/Versions/Current"
pybin   "/Library/Frameworks/Python.framework/Versions/Current/bin"
pylibs  "/Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/site-packages"
 
# lsmarks with search term
$ lsmarks py
py      "/Library/Frameworks/Python.framework/Versions/Current"
pybin   "/Library/Frameworks/Python.framework/Versions/Current/bin"
pylibs  "/Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/site-packages"
 
# using a directory bookmark
$ cd $bubble
$ pwd
/Users/shahad/projects/tg_apps/bubble
 
# adding a directory bookmark
$ cd bubble/static/images
$ mark bubble_img
Adding bookmark bubble_img --> "/Users/shahad/projects/tg_apps/bubble/bubble/static/images"
 
# look ma, the new bookmark has been added!
$ lsmarks bubble
bubble      "/Users/shahad/projects/tg_apps/bubble"
bubble_img  "/Users/shahad/projects/tg_apps/bubble/bubble/static/images"
 
# directories with spaces in the name
$ cd /Users/shahad/Library/Application\ Support/
$ mark appsu
Adding bookmark appsu --> "/Users/shahad/Library/Application Support"
 
# trying to use bookmark as normal.. fails :(
$ cd ~
$ cd $appsu
-bash: cd: /Users/shahad/Library/Application: Not a directory
 
# we have to enclose the dir bookmark in quotes.
$ cd "$appsu"
$ pwd 
/Users/shahad/Library/Application Support

Note that if a directory has spaces in its name, you have to enclose the bookmark name in quotes. I can’t find a way around this requirement that works on my mac. If anyone has suggestions, I would appreciate them.


10 Comments

Posted by
Anon
Dec 15, 2007 @ 9pm

dude. symlinks.

mkdir bookmarks
cd bookmarks
ln -s /crazy/dir/path kittens
# now you can
cd ~/bookmarks/kittens

# you can even make su directories to organise them.

overengineer much? :-)


Posted by
Logan Capaldo
Dec 15, 2007 @ 9pm

function cdm {
varname=”$1″;
dollar=’$';
var=”$dollar$varname”;
eval cd “\”$var\”";
}

cdm appsu


Posted by
Mackenzie
Dec 16, 2007 @ 2am

Anon, that’s not the point. Symlinks just connect wherever you are now to somewhere. This would work regardless of what directory you’re moving there from.


Posted by
burke
Dec 16, 2007 @ 2am

I agree with Anon. Just make a directory ~/b/, then you can go ‘cd ~/b/bookmarknamehere’ or ‘ln -s /file/to/link/to ~/b/linkname’


Posted by
Alan
Dec 16, 2007 @ 3am

Or you could just do something like …
echo “export py=/Library/Frameworks/Python.framework/Versions/Current” >> ~/.profile

I know that won’t list out your bookmarks the way you have it currently (amongst a couple other things), but it works nicely for simpler needs.


Posted by
translated
Dec 16, 2007 @ 3am

Not sure if that’s what your trying to archive, but wouldn’t a bunch of aliases do the trick? Put a line line this in your .bashrc file:

alias bubble=’cd /what/a/long/path/to/bubble’

and then:

~$ bubble
~$ pwd
/what/a/long/path/to/bubble

You can do the same for all the “bookmarks” you need and that’s it.

And if you don’t want to overload your bashrc with too many aliases, popd and pushd help lot when it comes to navigating between directories.


Posted by
njharman
Dec 16, 2007 @ 6am

also see environment var CDPATH and commands pushd popd


Posted by
Push'n'Pop
Dec 16, 2007 @ 7am

I second the suggestion to look at ‘pushd’, ‘popd’ and ‘dirs’.

To have a dynamically updated list of unique “bookmarks” take a look at this page http://www.thrysoee.dk/pushd/


Posted by
Scott
Dec 17, 2007 @ 12pm

I added a ‘go’ function as a convenience so I don’t have to type the dollar sign in front of the bookmark name:

function go() {
if [ $# -gt 0 ]; then
eval cd \${$1}
else
echo “Usage: go bookmark-name”
fi
}

So I can do:

go mydir

instead of:

cd $mydir


Posted by
lileomyclein
May 19, 2010 @ 6am

www wapos ru знакомства кавказский чат знакомств секс знакомства волгодонск знакомства для секса югорск клубы знакомств в санкт-петербурге
[url=http://seks.vip-devky.info/shluhi-v-ivanteevke.html]шлюхи в ивантеевке[/url]


Leave a Comment

Bayesian Networks in the Cloud India, Baby!