I often have a project directory layout like thisproject`-- component-a|   `-- files...`-- component-b|   `-- files...`-- component-c    `-- files...I'll usually be working in one of the component directories, because that's where the files are. When I then return to the shell, I'll often simply need to move to a sibling directory, especially when I need to make a few non-scriptable changes to every component. In those cases, I won't even care what the previous sibling directory is that I'll work on, or the next sibling directory.Can I define a command prev or next that will simply cd me into the previous directory, or next directory (by alphabet or whatever)? Because typing cd ../com<TAB><Arrow keys> all the time is getting a bit old.
How can I cd to the previous/next sibling directory?
shell;command line;directory;cd command
Don't use the commandlinefu solution from the other answer: it's unsafe AND inefficient.  Instead, if you are using bash, just use the following functions.  To make them persistent, put them into your .bashrc.  Note that I use glob order because it's built-in and easy.  Typically glob order is alphabetical in most locales though.  You'll get an error message if there is no next or previous directory to go to.  In particular, you'll see the error if you try to next or prev while in the root directory, /.## bash and zsh only!# functions to cd to the next or previous sibling directory, in glob orderprev () {    # default to current directory if no previous    local prevdir=./    local cwd=${PWD##*/}    if [[ -z $cwd ]]; then        # $PWD must be /        echo 'No previous directory.' >&2        return 1    fi    for x in ../*/; do        if [[ ${x#../} == ${cwd}/ ]]; then            # found cwd            if [[ $prevdir == ./ ]]; then                echo 'No previous directory.' >&2                return 1            fi            cd $prevdir            return        fi        if [[ -d $x ]]; then            prevdir=$x        fi    done    # Should never get here.    echo 'Directory not changed.' >&2    return 1}next () {    local foundcwd=    local cwd=${PWD##*/}    if [[ -z $cwd ]]; then        # $PWD must be /        echo 'No next directory.' >&2        return 1    fi    for x in ../*/; do        if [[ -n $foundcwd ]]; then            if [[ -d $x ]]; then                cd $x                return            fi        elif [[ ${x#../} == ${cwd}/ ]]; then            foundcwd=1        fi    done    echo 'No next directory.' >&2    return 1} It doesn't handle all possible directory names.  Parsing ls output is never safe. cd probably doesn't need to be terribly efficient, but 6 processes is a bit excessive.