summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hunter <m@lfurio.us>2026-02-22 02:56:35 -0500
committerMatt Hunter <m@lfurio.us>2026-02-22 18:22:05 -0500
commit8fc0fa9a8cf84d0d2c7ac5f4e3b4c79fadb99d8c (patch)
treed464e700718f28fc60d43ebdb5147e3a3ff00c1c
parent2477bb20257689d4d680701934cdb659c8f6fb37 (diff)
downloadgit-sonar-8fc0fa9a8cf84d0d2c7ac5f4e3b4c79fadb99d8c.tar.gz
git-sonar-8fc0fa9a8cf84d0d2c7ac5f4e3b4c79fadb99d8c.zip
Add new prompt output element "condition"
Use git-precheck to determine if any ongoing git operation is in progress and if so, mark the repository as being in a special condition. This is made visible via a new feature in the GIT_RADAR_FORMAT prompt string '%{condition}', which renders '!' when active. Like most others, this element comes with its own configurable color. By default, this is yellow, which is used for other 'conflicted' or abnormal states. This patch removes the unimpactful variable $output from render_prompt() and replaces its use with $PROMPT_FORMAT - what it was initialized to. Signed-off-by: Matt Hunter <m@lfurio.us>
-rwxr-xr-xgit-sonar24
1 files changed, 20 insertions, 4 deletions
diff --git a/git-sonar b/git-sonar
index 8917cab..a610d14 100755
--- a/git-sonar
+++ b/git-sonar
@@ -49,18 +49,21 @@ prepare_colors() {
COLOR_CHANGES_CONFLICTED="\x01${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-"\\033[1;33m"}\x02"
COLOR_CHANGES_UNTRACKED="\x01${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-"\\033[1;37m"}\x02"
+ COLOR_CONDITION="\x01${GIT_RADAR_COLOR_CONDITION:-"\\033[1;33m"}\x02"
+
COLOR_STASH="\x01${GIT_RADAR_COLOR_STASH:-"\\033[1;33m"}\x02"
COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\x02"
MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"\\x01\\033[0m\\x02\\xF0\\x9D\\x98\\xAE\\x01\\033[0m\\x02"}"
- PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}"
+ PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{condition}%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}"
RESET_COLOR_LOCAL="\x01${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\x02"
RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02"
RESET_COLOR_CHANGES="\x01${GIT_RADAR_COLOR_CHANGES_RESET:-"\\033[0m"}\x02"
RESET_COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH_RESET:-"\\033[0m"}\x02"
RESET_COLOR_STASH="\x01${GIT_RADAR_COLOR_STASH_RESET:-"\\033[0m"}\x02"
+ RESET_COLOR_CONDITION="\x01${GIT_RADAR_COLOR_CONDITION_RESET:-"\\033[0m"}\x02"
}
@@ -450,8 +453,12 @@ stash_status() {
fi
}
+repo_special_condition() {
+ git-precheck --quiet --ignore-dirty --ignore-untracked \
+ || printf "$COLOR_CONDITION!$RESET_COLOR_CONDITION"
+}
+
render_prompt() {
- output="$PROMPT_FORMAT"
branch_sed=""
remote_sed=""
local_sed=""
@@ -464,7 +471,15 @@ render_prompt() {
sed_pre="%{\(\([^%^{^}]*\)\:\)\{0,1\}"
sed_post="\(\:\([^%^{^}]*\)\)\{0,1\}}"
- if [[ $output =~ ${if_pre}remote${if_post} ]]; then
+ if [[ $PROMPT_FORMAT =~ ${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 [[ $PROMPT_FORMAT =~ ${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/"
@@ -505,7 +520,8 @@ render_prompt() {
fi
fi
- printf '%b' "$output" | sed \
+ printf '%b' "$PROMPT_FORMAT" | sed \
+ -e "$condition_sed" \
-e "$remote_sed" \
-e "$branch_sed" \
-e "$changes_sed" \