I was trying out different shorten strategies for my prompt and thought it would be really useful if anytime I went into a git repo my prompt would shorten to show the git root as the first anchor directory. For example:
~/Documents/projects/git_project/src/api
Would change to
git_project/src/api
Right now I have it set back on truncate_to_unique, but I imagine a case could be created using the list of non-shortened anchor dirs called truncate_to_last_anchor or something along those lines.
Try adding this to your ~/.zshrc.
function zsh_directory_name() {
emulate -L zsh
[[ $1 == d ]] || return
while [[ $2 != / ]]; do
if [[ -e $2/.git ]]; then
typeset -ga reply=(${2:t} $#2)
return
fi
2=${2:h}
done
return 1
}
Is it good enough?
Yes! this is great. Thank you.
Yes! this is great. Thank you.
You are most welcome.
By the way, this isn't p10k-specific. It'll work even with a simple prompt like `PROMPT='%~%# '.
Most helpful comment
Try adding this to your
~/.zshrc.Is it good enough?