Skip to content

Instantly share code, notes, and snippets.

@jeeger
Last active July 31, 2020 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeeger/6020a28625f147e4236d1ff0d08ace34 to your computer and use it in GitHub Desktop.
Save jeeger/6020a28625f147e4236d1ff0d08ace34 to your computer and use it in GitHub Desktop.
ZSH persistent directory aliases
if which sponge &>/dev/null; then
qjc() {
ALIAS="$1"
DIR="$(pwd)"
hash -d "$1"="$DIR"
echo "hash -d \"$1\"=\"$DIR\"" >> ~/.zsh/dirhashes
}
qjd() {
if [[ -z "$1" ]]; then
DIR=$(pwd)
grep -v "hash -d \".*\"=\"$DIR\"" ~/.zsh/dirhashes | sponge ~/.zsh/dirhashes
else
ALIAS="$1"
grep -vF "hash -d \"$ALIAS\"" ~/.zsh/dirhashes | sponge ~/.zsh/dirhashes
fi
hash -rd
source ~/.zsh/dirhashes
}
qjl() {
sed -n '/^hash/ { s/hash -d "\([^"]*\)"="\([^"]*\)"/\1: \2/g p }' < ~/.zsh/dirhashes
}
source ~/.zsh/dirhashes
else
echo "Sponge not found, dirhash functionality not available. Install moreutils."
fi
@jeeger
Copy link
Author

jeeger commented Jul 31, 2020

Added functionality to delete alias for pwd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment