I just made this little cd function that is a drop-in replacement for the builtin bash cd command. The idea was to make it really easy and productive to navigate around to commonly used directories in bash without forcing someone to learn new habits like in the case of pushd, popd, and a bunch of other stuff like cdargs and gotodir.
cd () { if [ "$*" = "" -o "$*" = "-" ]; then builtin cd $*; return; fi; realpath=$(realpath $*); if [ -z "$realpath" -o ! -d "$realpath" ]; then realpath=$(realpath ~/recent_dirs/$* 2> /dev/null); fi; if builtin cd $realpath; then if [ "$*" = "" -o "$*" = "-" ]; then return; fi; ln -s $realpath ~/recent_dirs 2>/dev/null; else :; fi }
Your solution is the nicest I’ve seen for the problem of directory bookmarks. However, I think the notion of history needs to be per-shell, not global across all shells. For directories, a $DIRSTACK-style working set is probably more useful than a strict browser-style history, so I extended your solution by adding:
Hmm, some kind of markup system is in effect here, but WordPress doesn’t offer preview or convenient compose help. Marc can see the code in ~holtz/.bash_function; others may be out of luck. 🙂
I did a little bit of cleanup in your comment to get around some of the automatic WordPress formatting, but I think it’s still getting a bit screwed up. Maybe I can just upload a copy as a plain text file to my site.
Nice… how about some directions on using it? For example, when I try to cd into a dir now, I get “bash: realpath: command not found” — are there dependencies you might want to tell the rest of us how to fulfill?
Thanks!
-jq