Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Launchy is a great piece of software, I use it on Windows mainly for quickly accessing folders. I love its auto-indexing in the background, and hardly ever browse through folders manually these days, solves me lots of time.

On Linux (Ubuntu 9.10), I usually "live" in the terminal, however. Therefore, Launchy on Linux (or Gnome Do, or its other replacements) are not what I need - as it opens the file manager, and I don't need the file manager.

What I do need is something that indexes my folders and lets me cd into them quickly in the terminal. For example:

mycd python_c

Will cd to:

~/dev/scripts/python_code

I hope my intention is understood :-)

Are you familiar with such tools?

share|improve this question
add comment

3 Answers

Bash has the CDPATH variable.

$ CDPATH="$CDPATH:~/dev/scripts/:/some/other/one/too"
$ cd python_code
/home/username/dev/scripts/python_code
$ pwd
/home/username/dev/scripts/python_code

You could script the maintenance of the value something like this:

In your ~/.bashrc:

cd() {
    while read -r dir
    do
        if [[ ! $CDPATH =~ $dir ]]
        then
            CDPATH="${CDPATH}:${dir}"
        fi
    done < ~/.cdpath
    builtin cd "$@"
}
cd .    # update CDPATH
export CDPATH

In a file called /usr/local/bin/mkcdpath:

#!/bin/bash
# update the stored CDPATH directory list
# run from cron, can be run manually
# requires Bash >= 3.2
cdp=$(<~/.cdpath)
while read -r dir
do
    if [[ ! $cdp =~ $dir ]]
    then
        cdp="${cdp}:${dir}"
    fi
done < <(find /anchored_at_root -maxdepth 1 some_find_args  -type d)
echo "$cdp" > ~/.cdpath

Run that periodically using cron.

Now anytime you use cd, it will update the current shell's CDPATH and perform the directory change according to it (in addition to doing normal cds which are tried first). You could change the function name (and remove the cd command) to make it an update function only and use the regular cd command - it just wouldn't update the value automatically.

share|improve this answer
add comment

You might be interested in some advanced feature of zsh. It add some extra shortcuts to cd.

share|improve this answer
add comment
up vote 0 down vote accepted

Just want to write down that after some looking around I've found z - it learns the directories you CD into and then lets you easily jump into them.

There's also autojump, but z appears to be closer to what I need.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.