"Bookmarks" for bash

I think you're looking for something like autojump. You have to cd around a bit to develop a set of "key weights" that correlate with the amount of time spent in a given directory. Then, assuming you spent a lot of time in that 'classes' dir, you could jump there directly by typing

j cl

You can view your "key weights" with

jumpstat

As saeedn mentions, aliases are a good mechanism. The bash shell also has a built-in mechanism to jump right to a location: CDPATH. Set it like PATH, but it is used by cd instead of searching for programs.

$ CDPATH=:~/repo/www/public/util
$ cd classes
/home/casebash/repo/www/public/util/classes

From the manpage:

   CDPATH The search path for the cd command.  This is  a  colon-separated
          list  of  directories  in  which the shell looks for destination
          directories specified by the cd  command.   A  sample  value  is
          ".:~:/usr".

Myself, I've combined this with a directory that has symlinks to where I'd want to go:

$ mkdir ~/cdshortcut
$ ln -s ~/repo/www/public/util/classes ~/cdshortcut/classes
$ CDPATH=:~/cdshortcut
/home/casebash/cdshortcut/classes

This has the drawback that the directory doesn't quite appear to be correct, but that can be rectified using cd -P or setting set -P.


I was looking for some shell-bookmarking tool for too long, and I'm not satisfied with any of the solutions I found.

However, eventually I've come across a great, universal tool: command-line fuzzy finder.

It primarily allows you to “fuzzy-find” files (check the rich gif animation by the link above), but it also allows to feed arbitrary text data to it and filter this data. So, the shortcuts idea is simple: all we need is to maintain a file with paths (which are shortcuts), and fuzzy-filter this file. Here's how it looks: we type cdg command (from “cd global”, if you like), get a list of our bookmarks, pick the needed one in just a few keystrokes, and press Enter. Working directory is changed to the picked item:

cdg

It is extremely fast and convenient: usually I just type 3-4 letters of the needed item, and all others are already filtered out. Additionally, of course we can move through list with arrow keys or with Ctrl+j/Ctrl+k.

Detailed article about this shortcuts/bookmarks solution is here: Fuzzy shortcuts for your shell.

Tags:

Shell

Bash