Last active
June 5, 2024 17:52
-
-
Save pbatey/c383630405d192ee2a2bfa801f1035d3 to your computer and use it in GitHub Desktop.
mark and jump commands for faster navigation
This file contains 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
# 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