Live data from Hacker News

Quickly navigate your filesystem from the command line

jeroenjanssens.com

11–20 of 148 posts

Re: Quickly navigate your filesystem from the command line

#11
post #9

Or you might just use ZSH (particularly in combination with oh-my-zsh), keep the marks around as zsh vars and skip all the symbolic linkage.

this way they would all be lost at the end of each session, and would not be shared across concurrent sessions, no?

Re: Quickly navigate your filesystem from the command line

#12
I had to modify Jeroen's code to get the `marks` shortcut working under Mac OS 10.8:

    export MARKPATH=$HOME/.marks
    function 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- && echo
    }

Re: Quickly navigate your filesystem from the command line

#15

A handy alias I use: alias ..='cd ..' Moving up the file tree has never been easier!

Put the following in your .bashrc instead:

    shopt -s autocd
If you type a directory in the command-line, it’ll cd into it, e.g.:

    $ ..   # cd ..
    $ ~    # cd ~
    $ foo  # cd foo
I can’t live without this.

Re: Quickly navigate your filesystem from the command line

#16
You can also use ranger [1] to change directories, especially if you want to explore the directory tree quickly when you don't know exactly where to jump to. Install it and add the following to ~/.bashrc:

     function ranger-cd {
       tempfile='/tmp/chosendir'
       /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}"
       test -f "$tempfile" &&
       if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
         cd -- "$(cat "$tempfile")"
       fi
       rm -f -- "$tempfile"
     }

     # This binds Ctrl-O to ranger-cd:
     bind '"\C-o":"ranger-cd\C-m"'
(This script comes from the man page for ranger(1).)

Edit: Modified the above script for use with zsh (and multiple users):

     ranger-cd() {
       tempfile=$(mktemp)
       ranger --choosedir="$tempfile" "${@:-$(pwd)}" 
[1] http://ranger.nongnu.org/.

Re: Quickly navigate your filesystem from the command line

#19
post #15

A handy alias I use: alias ..='cd ..' Moving up the file tree has never been easier!

Put the following in your .bashrc instead: shopt -s autocd If you type a directory in the command-line, it’ll cd into it, e.g.: $ .. # cd .. $ ~ # cd ~ $ foo # cd foo I can’t live without this.

Very cool, thanks! Although:

On OS X: "-bash: shopt: autocd: invalid shell option name"

Apple and their outdated tools... It gets annoying after a while.

Post reply on HN