Skip to content

Instantly share code, notes, and snippets.

@ianhall
Last active May 10, 2018 02:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianhall/11017051 to your computer and use it in GitHub Desktop.
Save ianhall/11017051 to your computer and use it in GitHub Desktop.
Bash profile script to mark and jump to folders
# Adapted for Mac OSX from http://christian.gen.co/macbook-developer-setup/
# and http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
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 | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}'
}
alias j="jump"
alias m="mark"
_completemarks() {
local curw=${COMP_WORDS[COMP_CWORD]}
local wordlist=$(find $MARKPATH -type l | xargs -n1 basename)
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