From 08ad67de221f737457cb8efc9bf02707d2aca549 Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Sat, 7 Mar 2026 18:50:52 -0500 Subject: Remove shell regex evaluation Tests performed with `[[ ]]` are not supported in POSIX-compliant shell. However, regex evaluation with the `=~` operator is a specific bashism which has no direct counterpart in POSIX, so I wanted to handle these cases in their own patch. We can simply use grep to evaluate these tests instead. The same regex syntax is supported. Signed-off-by: Matt Hunter --- git-sonar | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/git-sonar b/git-sonar index 1f7b7e8..45baf13 100755 --- a/git-sonar +++ b/git-sonar @@ -373,7 +373,7 @@ render_prompt() { sed_pre="%{\(\([^%^{^}]*\)\:\)\{0,1\}" sed_post="\(\:\([^%^{^}]*\)\)\{0,1\}}" - if [[ $PROMPT_FORMAT =~ ${if_pre}condition${if_post} ]]; then + if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}condition${if_post}"; then condition_result="$(repo_special_condition)" if [[ -n "$condition_result" ]]; then condition_sed="s/${sed_pre}condition${sed_post}/\2${condition_result}\4/" @@ -381,7 +381,7 @@ render_prompt() { condition_sed="s/${sed_pre}condition${sed_post}//" fi fi - if [[ $PROMPT_FORMAT =~ ${if_pre}missingups${if_post} ]]; then + if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}missingups${if_post}"; then missingups_result="$(color_missing_upstream)" if [[ -n "$missingups_result" ]]; then missingups_sed="s/${sed_pre}missingups${sed_post}/\2${missingups_result}\4/" @@ -389,7 +389,7 @@ render_prompt() { missingups_sed="s/${sed_pre}missingups${sed_post}//" fi fi - if [[ $PROMPT_FORMAT =~ ${if_pre}remote${if_post} ]]; then + if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}remote${if_post}"; then remote_result="$(color_remote_commits)" if [[ -n "$remote_result" ]]; then remote_sed="s/${sed_pre}remote${sed_post}/\2${remote_result}\4/" @@ -397,7 +397,7 @@ render_prompt() { remote_sed="s/${sed_pre}remote${sed_post}//" fi fi - if [[ $PROMPT_FORMAT =~ ${if_pre}branch${if_post} ]]; then + if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}branch${if_post}"; then branch_result="$(readable_branch_name | sed -e 's/\//\\\//g')" if [[ -n "$branch_result" ]]; then branch_sed="s/${sed_pre}branch${sed_post}/\2${branch_result}\4/" @@ -405,7 +405,7 @@ render_prompt() { branch_sed="s/${sed_pre}branch${sed_post}//" fi fi - if [[ $PROMPT_FORMAT =~ ${if_pre}local${if_post} ]]; then + if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}local${if_post}"; then local_result="$(color_local_commits)" if [[ -n "$local_result" ]]; then local_sed="s/${sed_pre}local${sed_post}/\2$local_result\4/" @@ -413,7 +413,7 @@ render_prompt() { local_sed="s/${sed_pre}local${sed_post}//" fi fi - if [[ $PROMPT_FORMAT =~ ${if_pre}changes${if_post} ]]; then + if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}changes${if_post}"; then changes_result="$(color_changes_status)" if [[ -n "$changes_result" ]]; then changes_sed="s/${sed_pre}changes${sed_post}/\2${changes_result}\4/" @@ -421,7 +421,7 @@ render_prompt() { changes_sed="s/${sed_pre}changes${sed_post}//" fi fi - if [[ $PROMPT_FORMAT =~ ${if_pre}stash${if_post} ]]; then + if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}stash${if_post}"; then stash_result="$(stash_status)" if [[ -n "$stash_result" ]]; then stash_sed="s/${sed_pre}stash${sed_post}/\2${stash_result}\4/" -- cgit v1.2.3