From 45f88d69871e1a9385f11c4162ea6cd84f04c6c0 Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Mon, 1 Jun 2026 03:14:27 -0400 Subject: Fix bug with prepare_element rendering on bsd Implementations of printf found in use by the default shells of OpenBSD and FreeBSD interpret the escape characters found in the $SED_PRE and $SED_POST constants differently than the implementations I've been testing against on Linux and Windows. In effect, the commands would noisily complain that each \* sequence seen is an unsupported escape sequence. Of course, this string is intended to be given to sed at the end of the script for the final rendering of the prompt. Address the issue by splitting up the big sed call at the end (with its multiple -e arguments) and bringing it into the prepare_element function. This effectively turns prepare_element into a text stream manipulation function of its own, where each call to it will perform the substitution of a single prompt element. Therefore, the oringinal context simply needs to pipeline all calls to prepare_element together to continue yielding the previous output - printf plumbing no longer necessary. Signed-off-by: Matt Hunter --- git-sonar | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/git-sonar b/git-sonar index 476375b..5a41bbf 100755 --- a/git-sonar +++ b/git-sonar @@ -214,9 +214,9 @@ SED_POST="\(\:\([^%^{^}]*\)\)\{0,1\}}" prepare_element() { result="$($2 | sed 's/\//\\\//g')" if [ -n "$result" ]; then - printf '%b' "s/${SED_PRE}${1}${SED_POST}/\\\\2${result}\\\\4/" + sed "s/${SED_PRE}${1}${SED_POST}/\\2${result}\\4/" else - printf '%b' "s/${SED_PRE}${1}${SED_POST}//" + sed "s/${SED_PRE}${1}${SED_POST}//" fi } @@ -234,10 +234,10 @@ if [ -n "$opt_fetch" ]; then fi # Render prompt elements from format string -printf '%b' "$PROMPT_FORMAT" | sed \ - -e "$(prepare_element alert element_alert)" \ - -e "$(prepare_element branch element_branch)" \ - -e "$(prepare_element remote element_remote)" \ - -e "$(prepare_element local element_local)" \ - -e "$(prepare_element stash element_stash)" \ - -e "$(prepare_element status element_status)" +printf '%b' "$PROMPT_FORMAT" \ + | prepare_element alert element_alert \ + | prepare_element branch element_branch \ + | prepare_element remote element_remote \ + | prepare_element local element_local \ + | prepare_element stash element_stash \ + | prepare_element status element_status -- cgit v1.2.3