mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-06 02:51:32 +01:00
feat(shrinkpath): enable n lastfull elements
Allow for numerical argument after -l or --last to force the n last elements to print as full names Usage: `shrinkpath -s -l 3` will always show the last 3 elements of path as full `shrinkpath -s -l` will only show the last ellement as full (Standard behavior)
This commit is contained in:
parent
6754b7e67b
commit
4429769fb1
1 changed files with 22 additions and 5 deletions
|
|
@ -56,7 +56,16 @@ shrink_path () {
|
||||||
tilde=1
|
tilde=1
|
||||||
named=1
|
named=1
|
||||||
fi
|
fi
|
||||||
zstyle -t ':prompt:shrink_path' last && lastfull=1
|
|
||||||
|
local last
|
||||||
|
zstyle -s ':prompt:shrink_path' last last
|
||||||
|
case "$last" in
|
||||||
|
(false|no|off|0) lastfull=0 ;;
|
||||||
|
(true|yes|on|1) lastfull=1 ;;
|
||||||
|
(""|*[^0-9]*) lastfull=0 ;;
|
||||||
|
(*) lastfull=$last ;;
|
||||||
|
esac
|
||||||
|
|
||||||
zstyle -t ':prompt:shrink_path' short && short=1
|
zstyle -t ':prompt:shrink_path' short && short=1
|
||||||
zstyle -t ':prompt:shrink_path' tilde && tilde=1
|
zstyle -t ':prompt:shrink_path' tilde && tilde=1
|
||||||
zstyle -t ':prompt:shrink_path' glob && ellipsis='*'
|
zstyle -t ':prompt:shrink_path' glob && ellipsis='*'
|
||||||
|
|
@ -78,7 +87,7 @@ shrink_path () {
|
||||||
print 'Usage: shrink_path [-f -l -s -t] [directory]'
|
print 'Usage: shrink_path [-f -l -s -t] [directory]'
|
||||||
print ' -f, --fish fish-simulation, like -l -s -t'
|
print ' -f, --fish fish-simulation, like -l -s -t'
|
||||||
print ' -g, --glob Add asterisk to allow globbing of shrunk path (equivalent to -e "*")'
|
print ' -g, --glob Add asterisk to allow globbing of shrunk path (equivalent to -e "*")'
|
||||||
print ' -l, --last Print the last directory''s full name'
|
print ' -l, --last [#] Print the last n directory''s full name (default 1).'
|
||||||
print ' -s, --short Truncate directory names to the number of characters given by -#. Without'
|
print ' -s, --short Truncate directory names to the number of characters given by -#. Without'
|
||||||
print ' -s, names are truncated without making them ambiguous.'
|
print ' -s, names are truncated without making them ambiguous.'
|
||||||
print ' -t, --tilde Substitute ~ for the home directory'
|
print ' -t, --tilde Substitute ~ for the home directory'
|
||||||
|
|
@ -93,7 +102,13 @@ shrink_path () {
|
||||||
print ' zstyle :prompt:shrink_path fish yes'
|
print ' zstyle :prompt:shrink_path fish yes'
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
-l|--last) lastfull=1 ;;
|
-l|--last)
|
||||||
|
lastfull=1
|
||||||
|
if [[ -n "$2" && "$2" != *[^0-9]* ]]; then
|
||||||
|
shift
|
||||||
|
lastfull=$1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
-s|--short) short=1 ;;
|
-s|--short) short=1 ;;
|
||||||
-t|--tilde) tilde=1 ;;
|
-t|--tilde) tilde=1 ;;
|
||||||
-T|--nameddirs)
|
-T|--nameddirs)
|
||||||
|
|
@ -127,6 +142,8 @@ shrink_path () {
|
||||||
|
|
||||||
[[ -d $dir ]] || return 0
|
[[ -d $dir ]] || return 0
|
||||||
|
|
||||||
|
function join_by { local IFS="$1"; shift; echo "$*"; }
|
||||||
|
|
||||||
if (( expand )) {
|
if (( expand )) {
|
||||||
echo "$dir"
|
echo "$dir"
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -148,8 +165,8 @@ shrink_path () {
|
||||||
cd -q /
|
cd -q /
|
||||||
}
|
}
|
||||||
for dir in $tree; {
|
for dir in $tree; {
|
||||||
if (( lastfull && $#tree == 1 )) {
|
if (( lastfull && $#tree <= lastfull )) {
|
||||||
result+="/$tree"
|
result+="/${(j:/:)tree[@]}"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
expn=(a b)
|
expn=(a b)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue