Comments:"Quickly navigate your filesystem from the command-line"
URL:http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
Note: The discussion on Hacker News contains many helpful suggestions for improvement (e.g., tab-completion, usage under MAC OS X) and alternative tools. I will incorporate these into this post as soon as possible. Follow me on Twitter if you want to be notified of any updates.
Like many others, I spend most of my day behind a computer.
In order make the most of it (and to keep my body from complaining too much), I try to maintain an optimized setup.
For example, I code in Vim, browse with Vimperator, and move windows around in i3.
Another common task is filesystem navigation.
I prefer to use the command-line for this, but typing cd ~/some/very/deep/often-used/directory
over and over again does become cumbersome.
Automated tools like autojump and fasd address this problem by offering shortcuts to the directories you often go to. Personally, I prefer a more manual solution, which I would like to share with you. I have noticed quite an increase in efficiency with this, and perhaps you will too.
Under the hood this manual solution comes down to storing symbolic links in a hidden directory (e.g., ~/.marks
).
There are four shell functions jump
, mark
, unmark
, and marks
, and they look like this:
export MARKPATH=$HOME/.marksfunction jump {cd -P $MARKPATH/$1 2>/dev/null ||echo"No such mark: $1"}function mark {
mkdir -p $MARKPATH; ln -s $(pwd)$MARKPATH/$1}function unmark {
rm -i $MARKPATH/$1}function marks {
ls -l $MARKPATH | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g'&&echo}
Put this in your .zshrc
or .bashrc
and you're ready to jump. (I have also turned this into a plugin for oh-my-zsh called jump
, but that's currently in a pull-request.) To add a new bookmark, cd
into the directory and mark
it with a name to your liking:
$ cd ~/some/very/deep/often-used/directory$ mark deep
This adds a symbolic link named deep
to the directory ~/.marks
. To jump
to this directory, type the following from any place in the filesystem:
To remove the bookmark (i.e., the symbolic link), type:
You can view all marks by typing:
$ marks
deep -> /home/johndoe/some/very/deep/often-used/directory
foo -> /usr/bin/foo/bar
That's all there is to it! If you like what I had to say then you may want to follow me on Twitter.