Live data from Hacker News

Quickly navigate your filesystem from the command line

jeroenjanssens.com

61–70 of 148 posts

Re: Quickly navigate your filesystem from the command line

#62
post #53

Here is a fully functional (albeit minimal) Windows version: http://appleseedhq.net/stuff/marks-v1.zip . Tested on Windows 7 (does not require PowerShell). GitHub: https://github.com/dictoon/marks Edit: to install, unzip anywhere and add to your path. Then: C:\Windows> mark win C:\Windows> marks win => C:\Windows C:\Windows> cd .. C:\> jump win C:\Windows> Marks will be stored in a marks\ subdirectory (relatively to…

Thanks alot. Works on WIn8

Re: Quickly navigate your filesystem from the command line

#63
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 -d' ' -f9- | sed 's/ -/\t-/g' && echo
  }

  _completemarks() {
      local curw=${COMP_WORDS[COMP_CWORD]}
      local wordlist=$(find $MARKPATH -type l -printf "%f\n")
      COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
      return 0
  }

  complete -F _completemarks jump unmark

Re: Quickly navigate your filesystem from the command line

#64

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 r…

Good idea, but you shouldn't overwrite ctrl-O, which is a wildly useful function in bash: run current command in history and retrieve the next. If you want to re-run a sequence of several history commands, you can find the first in history (such as via ctrl-R reverse-isearch), then repeatedly hit ctrl-O to run it and retrieve the next command from history.

Re: Quickly navigate your filesystem from the command line

#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

Re: Quickly navigate your filesystem from the command line

#66
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

Re: Quickly navigate your filesystem from the command line

#67

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 r…

i'm using fasd a lot but this is absolutely awesome, thank you!

Re: Quickly navigate your filesystem from the command line

#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.
Post reply on HN