Skip to content

Instantly share code, notes, and snippets.

@P7h
Last active December 21, 2015 06:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save P7h/6262128 to your computer and use it in GitHub Desktop.
Save P7h/6262128 to your computer and use it in GitHub Desktop.
For jumping around deeply nested folders.
#!/bin/bash
# Slightly modified code from: http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
# Just add the following in your .bashrc or .zshrc or you can even source it in every session.
# Examples:
# cd ~/some/very/deep/often-used/directory
# $ mark deep
# [when you are in other location] $ jump deep
# $ marks # for listing all the marks
# $ unmark deep
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 $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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment