From 0149e7ec00f08486c672e357ac409dbef0858c13 Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Sat, 16 May 2026 18:00:17 -0400 Subject: Allow custom branch color for detached HEAD Add an additional config variable 'GIT_SONAR_DETACHED_COLOR', which is used to color the %{branch} element when on a detached HEAD. Both "branch color" and "detached color" default to uncolored, but may now be configured independently. Signed-off-by: Matt Hunter --- git-sonar | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/git-sonar b/git-sonar index 6d21831..9aa2233 100755 --- a/git-sonar +++ b/git-sonar @@ -83,6 +83,7 @@ FETCH_TIME="${GIT_SONAR_FETCH_TIME:-"300"}" ALERT_ICON="${GIT_SONAR_ALERT_ICON:-"${COLOR_YELLOW}⚡"}" STASH_ICON="${GIT_SONAR_STASH_ICON:-"${COLOR_YELLOW}≡"}" BRANCH_COLOR="${GIT_SONAR_BRANCH_COLOR:-"$COLOR_DEF"}" +DETACHED_COLOR="${GIT_SONAR_DETACHED_COLOR:-"$COLOR_DEF"}" STATUS_SEP="${GIT_SONAR_STATUS_SEPARATOR:-" "}" AHEAD_ICON="${GIT_SONAR_AHEAD_ICON:-"${COLOR_GREEN}↑"}" # "←" @@ -140,8 +141,11 @@ element_alert() { } element_branch() { - [ -n "$branch_name" ] && branch="$branch_name" || branch="detached@${commit_hash}" - printf '%b%s%b' "$BRANCH_COLOR" "$branch" "$COLOR_DEF" + if [ -n "$branch_name" ]; then + printf '%b%s%b' "$BRANCH_COLOR" "$branch_name" "$COLOR_DEF" + else + printf '%bdetached@%s%b' "$DETACHED_COLOR" "$commit_hash" "$COLOR_DEF" + fi } element_remote() { -- cgit v1.2.3