Live data from Hacker News

Quickly navigate your filesystem from the command line

jeroenjanssens.com

141–148 of 148 posts

Re: Quickly navigate your filesystem from the command line

#143

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 }

Here is another version of 'marks' for Mac OS that aligns the arrows. It also works when 'ls' is aliased. function marks { \ls -l $MARKPATH | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}' }

One more fix... if you have group names with spaces this will throw the field number off and you'll see the modification time preceding the mark name.

Adding '-n' to the ls command works around this by causing the group id to be printed instead of the group name and all works, i.e.: \ls -ln "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}'

Re: Quickly navigate your filesystem from the command line

#144
post #112

Earlier quoted context omitted.

What many people don't seem to know is that the location bar in Explorer (at least on Windows 8) can act as a run dialog, and it supplies the launched program with the current folder as a parameter. So simply hit Ctrl+L and type "cmd" or "powershell" or whatever command from your PATH and hit enter.

Thanks for the tip! Neither Ctrl+L nor Alt+D work for me (Win7 Ultimate, 64bit), but even with clicking manually this is extremely useful for me.

I have been using F6 in my browsers, and it does seem to focus the address bar in File Explorer too. You need to press Enter first to be able to type commands though.

Re: Quickly navigate your filesystem from the command line

#145
post #70

For Windows users I have a closely related shameless plug: cdhere navigates your cmd.exe to wherever the current topmost Explorer window is pointed at. It's not the same as the OP's trick, of course, but since you're voluntarily using Windows, I'm going to assume you "live" on the command line less than the average UNIX user, and more on GUI tools such as good old Explorer. https://github.com/eteeselink/cdhere

You could install cygwin and use the OP technique, though.

unfortunately cygwin takes a lot longer to start than cmd, so I use it only occasionally. are there any fixes for that maybe? :)

Re: Quickly navigate your filesystem from the command line

#146
I don't understand the advantage of using handwritten function instead of the shell builtins. The `mark` function could be replaced by `alias -g`, `jump` could be replaced by `cd` and `unmark` could be replaced by `unalias` :

    % cd ~/Dev/W3/m-r-r.github.io
    % alias -g :blog="$PWD"
    % jekyll build -d /tmp/out/ && cd /tmp/out
    % ./index.html
    % cd :blog
    % pwd
    /home/m-r-r/Dev/W3/m-r-r.github.io
    % alias -g
    :blog='/home/m-r-r/Dev/W3/m-r-r.github.io'
    :dev='/home/m-r-r/Dev'
    :c='/home/m-r-r/Dev/C'
    :python='/home/m-r-r/Dev/Python'
    :vim='/home/m-r-r/.vim'
In addition, this method works with any shell command:

    % pwd
    /tmp/out
    % make -C :blog publish
    % git clone git://git.complang.org/ragel.git `echo :c`/ragel
    % vim `echo :vim`/templates/\*.rl
On the other side, the aliases are not saved at exit unless you write a function to do it:

    % tail -n 15 ~/.zshrc
    function aliases {
        (
            alias -L -r
            alias -L -g
            alias -L -s
        ) | uniq
    } 

    function save-aliases {
        aliases > ~/.zsh_aliases
    }

    if [ -f ~/.zsh_aliases ]; then 
        . ~/.zsh_aliases
    fi

Re: Quickly navigate your filesystem from the command line

#147
post #65

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 }

And here's a completion code that works for Mac OS: function _jump { local cur=${COMP_WORDS[COMP_CWORD]} local marks=$(find $MARKPATH -type l | awk -F '/' '{print $NF}') COMPREPLY=($(compgen -W '${marks[@]}' -- "$cur")) return 0 } complete -o default -o nospace -F _jump jump

Shouldn't this be

  complete -o default -o nospace -F _jump jump unmark
and then it simply replaces the existing _completemarks(), instead of needing both?

Re: Quickly navigate your filesystem from the command line

#148

I set my version up with a -f on the unmark rm so that I don't need to be prompted to remove it. Also added some basic completion for both jump and unmark 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 -if $MARKPATH/$1 } function marks { ls -l $MARKPATH | sed 's/ / /g' | cut -…

Nice job! I had to modify _completemarks() function though to work on OSX.

  _completemarks() {
    local curw=${COMP_WORDS[COMP_CWORD]}
    local wordlist=$(find $MARKPATH -type l -exec basename {} \;)
    COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
    return 0
  }
Post reply on HN