diff options
| author | Matt Hunter <m@lfurio.us> | 2026-04-17 15:59:05 -0400 |
|---|---|---|
| committer | Matt Hunter <m@lfurio.us> | 2026-04-22 21:59:29 -0400 |
| commit | 89c100d72f39afff26f07b7c5ef57ce9fc9504b1 (patch) | |
| tree | 60f8ab09ad82de8d5e2f208a232cb3843dbdfcc7 | |
| parent | 034ca9256a06a3b384343f722a96219908d356df (diff) | |
| download | git-sonar-89c100d72f39afff26f07b7c5ef57ce9fc9504b1.tar.gz git-sonar-89c100d72f39afff26f07b7c5ef57ce9fc9504b1.zip | |
Combine special condition and missingups into alert
It is clearer to handle both of these with the same prompt element.
Consider "upstream is missing" as just another special condition, and
use the same icon to indicate either. We use the lightning bolt to
cover both situations with no suffix space.
The '!' character was found in some shells to function as an unintended
metacharacter when used in the PS1 prompt, and so was discarded.
Signed-off-by: Matt Hunter <m@lfurio.us>
| -rwxr-xr-x | git-sonar | 49 |
1 files changed, 16 insertions, 33 deletions
@@ -23,22 +23,20 @@ prepare_colors() { COLOR_CHANGES_CONFLICTED="\001${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-"\\033[1;33m"}\002" COLOR_CHANGES_UNTRACKED="\001${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-"\\033[1;37m"}\002" - COLOR_CONDITION="\001${GIT_RADAR_COLOR_CONDITION:-"\\033[1;33m"}\002" + COLOR_ALERT="\001${GIT_RADAR_COLOR_ALERT:-"\\033[1;33m"}\002" COLOR_STASH="\001${GIT_RADAR_COLOR_STASH:-"\\033[1;33m"}\002" COLOR_BRANCH="\001${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\002" MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-""}" # \\x01\\033[0m\\x02\\xF0\\x9D\\x98\\xAE\\x01\\033[0m\\x02 - PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\001\\033[1;30m\\002git:(\\001\\033[0m\\002%{condition: }%{remote: }%{missingups}%{branch}%{ :local}\\001\\033[1;30m\\002)\\001\\033[0m\\002%{ :stash}%{ :changes}"}" + PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\001\\033[1;30m\\002git:(\\001\\033[0m\\002%{alert}%{remote: }%{branch}%{ :local}\\001\\033[1;30m\\002)\\001\\033[0m\\002%{ :stash}%{ :changes}"}" RESET_COLOR_LOCAL="\001${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\002" RESET_COLOR_REMOTE="\001${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\002" RESET_COLOR_CHANGES="\001${GIT_RADAR_COLOR_CHANGES_RESET:-"\\033[0m"}\002" RESET_COLOR_BRANCH="\001${GIT_RADAR_COLOR_BRANCH_RESET:-"\\033[0m"}\002" RESET_COLOR_STASH="\001${GIT_RADAR_COLOR_STASH_RESET:-"\\033[0m"}\002" - RESET_COLOR_CONDITION="\001${GIT_RADAR_COLOR_CONDITION_RESET:-"\\033[0m"}\002" - } fetch() { @@ -274,16 +272,6 @@ color_local_commits() { printf $PRINT_F_OPTION "$local_commits" } -color_missing_upstream() { - not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE" - - if remote_branch="$(remote_branch_name)"; then - if ! git rev-parse "$remote_branch" -- >/dev/null 2>&1; then - printf "$not_upstream" - fi - fi -} - color_remote_commits() { green_ahead_arrow="${COLOR_REMOTE_AHEAD}↑$RESET_COLOR_REMOTE" # "←" red_behind_arrow="${COLOR_REMOTE_BEHIND}↓$RESET_COLOR_REMOTE" # "→" @@ -306,6 +294,14 @@ color_remote_commits() { printf $PRINT_F_OPTION "$remote" } +color_alert() { + if { remote_branch="$(remote_branch_name)" \ + && ! git rev-parse "$remote_branch" -- >/dev/null 2>&1; } \ + || [ "$precheck_status" -ge 3 ]; then + printf '%b' "${COLOR_ALERT}⚡${RESET_COLOR}" + fi +} + readable_branch_name() { printf $PRINT_F_OPTION "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" } @@ -321,10 +317,6 @@ stash_status() { fi } -repo_special_condition() { - [ "$precheck_status" -lt 3 ] || printf '%b' "$COLOR_CONDITION!$RESET_COLOR" -} - render_prompt() { branch_sed="" remote_sed="" @@ -338,20 +330,12 @@ render_prompt() { sed_pre="%{\(\([^%^{^}]*\)\:\)\{0,1\}" sed_post="\(\:\([^%^{^}]*\)\)\{0,1\}}" - 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/" - else - condition_sed="s/${sed_pre}condition${sed_post}//" - fi - fi - 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/" + if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}alert${if_post}"; then + alert_result="$(color_alert)" + if [ -n "$alert_result" ]; then + alert_sed="s/${sed_pre}alert${sed_post}/\2${alert_result}\4/" else - missingups_sed="s/${sed_pre}missingups${sed_post}//" + alert_sed="s/${sed_pre}alert${sed_post}//" fi fi if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}remote${if_post}"; then @@ -396,8 +380,7 @@ render_prompt() { fi printf '%b' "$PROMPT_FORMAT" | sed \ - -e "$condition_sed" \ - -e "$missingups_sed" \ + -e "$alert_sed" \ -e "$remote_sed" \ -e "$branch_sed" \ -e "$changes_sed" \ |
