Skip to content

Instantly share code, notes, and snippets.

@zph
Created July 21, 2014 14:50
Show Gist options
  • Select an option

  • Save zph/cd75c06089a25a887428 to your computer and use it in GitHub Desktop.

Select an option

Save zph/cd75c06089a25a887428 to your computer and use it in GitHub Desktop.
readonly MARKDIR="$HOME/.marks"
if [[ ! -d $MARKDIR ]];then
mkdir $MARKDIR
fi
export MARKPATH=$MARKDIR
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"
}
if [[ "$OSTYPE" == darwin* ]];then
function marks {
\ls -l "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}'
}
else
# Linux
function marks {
\ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
}
fi
# completion
function _completemarks {
reply=($(ls $MARKPATH))
}
compctl -K _completemarks jump
compctl -K _completemarks unmark
## Aliases
alias m="mark"
alias ms="marks"
alias j="jump"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment