Skip to content

Instantly share code, notes, and snippets.

@lucacervasio
Last active December 22, 2015 00:59
Show Gist options
  • Save lucacervasio/6393682 to your computer and use it in GitHub Desktop.
Save lucacervasio/6393682 to your computer and use it in GitHub Desktop.
Setting and jumping to marks during shell fs browsing
# I made some small changes to this: http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
# to install: curl https://raw.github.com/gist/6393682 >> ~/.bashrc; mkdir ~/.marks
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 -f "$MARKPATH/$1"
}
# linux
function marks {
ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
}
# osx
#function marks {
# \ls -l "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}'
#}
_completemarks() {
local curw=${COMP_WORDS[COMP_CWORD]}
local wordlist=$(find $MARKPATH -type l -printf "%f\n")
COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
return 0
}
alias j=jump
complete -F _completemarks jump unmark j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment