feat(shrink-path): add ability to toggle off path shrinking (#9794)

This commit is contained in:
Marc Cornellà
2021-05-21 21:57:34 +02:00
committed by GitHub
parent d646884add
commit 1bda62dffa
2 changed files with 73 additions and 26 deletions

View File

@ -45,6 +45,7 @@ shrink_path () {
typeset -i length=1
typeset ellipsis=""
typeset -i quote=0
typeset -i expand=0
if zstyle -t ':prompt:shrink_path' fish; then
lastfull=1
@ -60,6 +61,7 @@ shrink_path () {
zstyle -t ':prompt:shrink_path' tilde && tilde=1
zstyle -t ':prompt:shrink_path' glob && ellipsis='*'
zstyle -t ':prompt:shrink_path' quote && quote=1
zstyle -t ':prompt:shrink_path' expand && expand=1
while [[ $1 == -* ]]; do
case $1 in
@ -85,6 +87,8 @@ shrink_path () {
print ' ellipsis character(s) (defaulting to 1).'
print ' -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.'
print ' -q, --quote Quote special characters in the shrunk path'
print ' -x, --expand Print the full path. This takes precedence over the other options'
print ''
print 'The long options can also be set via zstyle, like'
print ' zstyle :prompt:shrink_path fish yes'
return 0
@ -109,6 +113,9 @@ shrink_path () {
-q|--quote)
quote=1
;;
-x|--expand)
expand=1
;;
esac
shift
done
@ -120,6 +127,11 @@ shrink_path () {
[[ -d $dir ]] || return 0
if (( expand )) {
echo "$dir"
return 0
}
if (( named )) {
for part in ${(k)nameddirs}; {
[[ $dir == ${nameddirs[$part]}(/*|) ]] && dir=${dir/#${nameddirs[$part]}/\~$part}