Skip to content

Instantly share code, notes, and snippets.

@ictus4u
Last active July 23, 2021 03:06
Show Gist options
  • Save ictus4u/7d3818654bbb08035ca6f727e6db4e1a to your computer and use it in GitHub Desktop.
Save ictus4u/7d3818654bbb08035ca6f727e6db4e1a to your computer and use it in GitHub Desktop.
# Add bookmarks to bash
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- | 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