Created
August 10, 2021 21:18
-
-
Save harel/25569bda00f7260923fdbc38e256f56b to your computer and use it in GitHub Desktop.
Add to your .bashrc to have mark/jump functionality with autocomplete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# mark/jump support + completion | |
# un/mark name : bookmark a directory or remove one (unmark) | |
# jump name : jump to directory | |
# marks : show all bookmarks | |
export MARKPATH=$HOME/bin/.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