diff options
| author | Matt Hunter <m@lfurio.us> | 2026-03-07 18:50:52 -0500 |
|---|---|---|
| committer | Matt Hunter <m@lfurio.us> | 2026-03-16 04:36:28 -0400 |
| commit | 08ad67de221f737457cb8efc9bf02707d2aca549 (patch) | |
| tree | 3d1c239efffe4ef6981de7e43823c18890a8e4c3 | |
| parent | 8d429259e3fb9c22bc3a3935bc3d41417dadedf5 (diff) | |
| download | git-sonar-08ad67de221f737457cb8efc9bf02707d2aca549.tar.gz git-sonar-08ad67de221f737457cb8efc9bf02707d2aca549.zip | |
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 <m@lfurio.us>
| -rwxr-xr-x | git-sonar | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -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/" |
