Skip to content

Instantly share code, notes, and snippets.

@mnemnion
Created August 18, 2013 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnemnion/6259297 to your computer and use it in GitHub Desktop.
Save mnemnion/6259297 to your computer and use it in GitHub Desktop.
A fancy little jumper script for bash. Easy keystroke access to frequent directories. jump/jp: go to a directory mark: make an alias unmark: delete an alias
# Fancy jump script
export MARKPATH=$HOME/.marks
function jump {
cd -P $MARKPATH/$1 2> /dev/null || echo "No such mark: $1"
}
function jp {
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}'
}
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
@niklasberglund
Copy link

Heavily inspired by http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html ?
Would be nice if you give credit.

Instead of copy-pasting the jump function's code to jp, it could call jump like so:

function jp {
    jump $1
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment