From 4a0a4f55981287ec7e69e2c4ff779f88c8a8b3b1 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Thu, 19 Jan 2023 00:28:36 +0100 Subject: Improve shell prompt cwd abbreviation handling --- tw/home/files/prompt.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tw/home/files/prompt.zsh') diff --git a/tw/home/files/prompt.zsh b/tw/home/files/prompt.zsh index 15e2d49b..7cc7342b 100644 --- a/tw/home/files/prompt.zsh +++ b/tw/home/files/prompt.zsh @@ -59,8 +59,11 @@ prompt_fast_preexec () { } prompt_fast_pwd () { - local fast_path="$(print -Pn '%~')" - if (($#fast_path / $COLUMNS.0 * 100 > ${PROMPT_FAST_PATH_PERCENT:-33})); then + local fast_path=$(print -Pn '%~') + local components=${#fast_path//[^\/]} # this counts the initial / + # Only abbreviate as /1/…/2/3 if we have something to cut out between 1 and 2! + # /1/2/3 -> /1/…/2/3 makes no sense. + if ((components > 3 && $#fast_path > ${PROMPT_FAST_PATH_FRACTION:-0.33} * COLUMNS)); then print -Pn '%-1~/…/%2/' else print "$fast_path" -- cgit v1.2.3