Hello zsh-workers,
I'm using the adam1 prompt, but didn't quite like how it wrapped to a second line, and how it would only show at most 3 path elements before using "...". The patch below allows users to configure those values, just like the colors, instead of using the hard-coded values of 40 and 3.
The commit message, I hope, explains the logic for the change and the new behavior. I'm not subscribed to this list, so please include me in any replies.
commit 0dc97f6b992cdb15cd8b95346665263a2c032f06Author: Dan Drake <zsh@xxxxxxxxxxxx>Date: Sun Jun 22 08:50:08 2025 -0500make adam1 prompt wrap len, ellipsized path elements configurableThe adam1 prompt will wrap to the next line when the current path to beshown is too long. The logic right now uses a hard-coded value of 40 todecide when to wrap:```if [[ $prompt_length -lt 40 ]]; then# show prompt with no newlineelse# show prompt with a newlinefi```The particular string used to find the length is $base_prompt_etc; thatstring uses a $( ternary _expression_ with ~ for the path; that _expression_uses hard-coded values so that when the path has more than 3 elements,the leading elements are ellipsized, and only the last 3 elements areshown:```base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3~")```Now, the length at which the prompt wraps, as well as the maximum numberof path elements shown before ellipsizing, are configurable, just likethe colors. They default to the previous values of 40 and 3.Users may set those values just like they set the colors: for example,```prompt adam1 gray blue blue 70 7```will only wrap when the length of the prompt string exceeds 80, and willellipsize the path when there are more than 7 elements in the path. As aconcrete example:```user@host /tmp % mkdir -p 2/3/4/5/6/7/8/9/10/11user@host /tmp % cd 2/3/4/5/6/7user@host /tmp/2/3/4/5/6/7 % cd 8user@host ...2/3/4/5/6/7/8 %```And for the wrapping:```dan@strawberry /tmp % mkdir long_name_to_show_adam1_prompt_wrapdan@strawberry /tmp % cd long_name_to_show_adam1_prompt_wrapdan@strawberry /tmp/long_name_to_show_adam1_prompt_wrap % mkdir -p 1/2/3/4/5/6/7/8dan@strawberry /tmp/long_name_to_show_adam1_prompt_wrap % cd 1dan@strawberry /tmp/long_name_to_show_adam1_prompt_wrap/1 % cd 2dan@strawberry /tmp/long_name_to_show_adam1_prompt_wrap/1/2 % cd 3dan@strawberry /tmp/long_name_to_show_adam1_prompt_wrap/1/2/3%```The length calculation does not exactly match the expected value of 70;I suspect the string length is including the color escape sequences, butthis patch does allow users to configure the wrap length and number ofancestor directories shown before using an ellipsis.diff --git a/Functions/Prompts/prompt_adam1_setup b/Functions/Prompts/prompt_adam1_setupindex 27a613ca1..8be92c8f1 100644--- a/Functions/Prompts/prompt_adam1_setup+++ b/Functions/Prompts/prompt_adam1_setup@@ -22,6 +22,8 @@ prompt_adam1_setup () {prompt_adam1_color1=${1:-'blue'}prompt_adam1_color2=${2:-'cyan'}prompt_adam1_color3=${3:-'green'}+ prompt_wrap_length=${4:-40}+ prompt_path_ellipsize_num=${5:-4}base_prompt="%K{$prompt_adam1_color1}%n@%m%k "post_prompt="%b%f%k"@@ -39,10 +41,10 @@ prompt_adam1_precmd () {local prompt_length space_leftbase_prompt_expanded_no_color=$(print -P "$base_prompt_no_color")- base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3~")+ base_prompt_etc=$(print -P "$base_prompt%(${prompt_path_ellipsize_num}~|...|)%$(( $prompt_path_ellipsize_num - 1))~")prompt_length=${#base_prompt_etc}- if [[ $prompt_length -lt 40 ]]; then- path_prompt="%B%F{$prompt_adam1_color2}%(4~|...|)%3~%F{white}"+ if [[ $prompt_length -lt $prompt_wrap_length ]]; then+ path_prompt="%B%F{$prompt_adam1_color2}%(${prompt_path_ellipsize_num}~|...|)%$(( $prompt_path_ellipsize_num - 1))~%F{white}"elsespace_left=$(( $COLUMNS - $#base_prompt_expanded_no_color - 2 ))path_prompt="%B%F{$prompt_adam1_color3}%${space_left}<...<%~$prompt_newline%F{white}"commit 8c5bb95e86ab3427ff9bbed485b1723ffb17b978Author: Dan Drake <dan@xxxxxxxxxxxx>Date: Sun Jun 22 08:50:08 2025 -0500make adam1 prompt wrap len, ellipsized path elements configurableThe adam1 prompt will wrap to the next line when the current path to beshown is too long. The logic right now uses a hard-coded value of 40 todecide when to wrap:```if [[ $prompt_length -lt 40 ]]; then# show prompt with no newlineelse# show prompt with a newlinefi```The particular string used to find the length is $base_prompt_etc; thatstring uses a $( ternary _expression_ with ~ for the path; that _expression_uses hard-coded values so that when the path has more than 3 elements,the leading elements are ellipsized, and only the last 3 elements areshown:```base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3~")```Now, the length at which the prompt wraps, as well as the maximum numberof path elements shown before ellipsizing, are configurable, just likethe colors. They default to the previous values of 40 and 3.Users may set those values just like they set the colors: for example,```prompt adam1 gray blue blue 70 7```will only wrap when the length of the prompt string exceeds 80, and willellipsize the path when there are more than 7 elements in the path. As aconcrete example:```user@host /tmp % mkdir -p 2/3/4/5/6/7/8/9/10/11user@host /tmp % cd 2/3/4/5/6/7user@host /tmp/2/3/4/5/6/7 % cd 8user@host ...2/3/4/5/6/7/8 %```And for the wrapping:```user@host /tmp % mkdir long_name_to_show_adam1_prompt_wrapuser@host /tmp % cd long_name_to_show_adam1_prompt_wrapuser@host /tmp/long_name_to_show_adam1_prompt_wrap % mkdir -p 1/2/3/4/5/6/7/8user@host /tmp/long_name_to_show_adam1_prompt_wrap % cd 1user@host /tmp/long_name_to_show_adam1_prompt_wrap/1 % cd 2user@host /tmp/long_name_to_show_adam1_prompt_wrap/1/2 % cd 3user@host /tmp/long_name_to_show_adam1_prompt_wrap/1/2/3%```The length calculation does not exactly match the expected value of 70;I suspect the string length is including the color escape sequences, butthis patch does allow users to configure the wrap length and number ofancestor directories shown before using an ellipsis.diff --git a/Functions/Prompts/prompt_adam1_setup b/Functions/Prompts/prompt_adam1_setupindex 27a613ca1..b4b91285b 100644--- a/Functions/Prompts/prompt_adam1_setup+++ b/Functions/Prompts/prompt_adam1_setup@@ -22,6 +22,8 @@ prompt_adam1_setup () {prompt_adam1_color1=${1:-'blue'}prompt_adam1_color2=${2:-'cyan'}prompt_adam1_color3=${3:-'green'}+ prompt_wrap_length=${4:-40}+ prompt_path_ellipsize_num=${5:-3}base_prompt="%K{$prompt_adam1_color1}%n@%m%k "post_prompt="%b%f%k"@@ -39,10 +41,10 @@ prompt_adam1_precmd () {local prompt_length space_leftbase_prompt_expanded_no_color=$(print -P "$base_prompt_no_color")- base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3~")+ base_prompt_etc=$(print -P "$base_prompt%($((${prompt_path_ellipsize_num} + 1))~|...|)%${prompt_path_ellipsize_num}~")prompt_length=${#base_prompt_etc}- if [[ $prompt_length -lt 40 ]]; then- path_prompt="%B%F{$prompt_adam1_color2}%(4~|...|)%3~%F{white}"+ if [[ $prompt_length -lt $prompt_wrap_length ]]; then+ path_prompt="%B%F{$prompt_adam1_color2}$base_prompt%($((${prompt_path_ellipsize_num} + 1))~|...|)%${prompt_path_ellipsize_num}~%F{white}"elsespace_left=$(( $COLUMNS - $#base_prompt_expanded_no_color - 2 ))path_prompt="%B%F{$prompt_adam1_color3}%${space_left}<...<%~$prompt_newline%F{white}"--
Ceci n'est pas une .signature.