summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hunter <m@lfurio.us>2026-06-01 03:14:27 -0400
committerMatt Hunter <m@lfurio.us>2026-06-01 03:14:27 -0400
commit45f88d69871e1a9385f11c4162ea6cd84f04c6c0 (patch)
tree03e9b106f171e1f17e0c9a8e4831fdda0b7caf9e
parent6915b76442b9a8c350922f4b8cf71075095ccf11 (diff)
downloadgit-sonar-45f88d69871e1a9385f11c4162ea6cd84f04c6c0.tar.gz
git-sonar-45f88d69871e1a9385f11c4162ea6cd84f04c6c0.zip
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 <m@lfurio.us>
-rwxr-xr-xgit-sonar18
1 files 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