Skip to content

Instantly share code, notes, and snippets.

@pbatey
Last active June 5, 2024 17:52
Show Gist options
  • Save pbatey/c383630405d192ee2a2bfa801f1035d3 to your computer and use it in GitHub Desktop.
Save pbatey/c383630405d192ee2a2bfa801f1035d3 to your computer and use it in GitHub Desktop.
mark and jump commands for faster navigation
# Add `. ~/.zshrc-mark-jump` to ~/.zshrc for faster navigation with mark and jump
export MARKPATH=$HOME/.marks
function jump {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
function mark {
mark=$1
if [ -z "$mark" ]; then marks; return; fi
if [ "$mark" = "." ]; then mark=$(basename "$PWD"); fi
mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$mark"
}
function unmark {
rm -i "$MARKPATH/$1"
}
function marks {
ls -l "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s\n%s\n", $1, $2}' \
| while IFS= read -r f; do
read -r t
if [ -d "$t" ]; then
printf "\033[0;35m$f\033[0m -> \033[0;34m$t\033[0m\n"
else
printf "\033[0;35m$f\033[0m -> \033[0;31m$t\033[0m\n"
fi
done
}
# autocompletion
function _completemarks {
reply=($(ls $MARKPATH))
}
compctl -K _completemarks jump
compctl -K _completemarks unmark
alias m=mark
alias j=jump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment