diff options
| -rwxr-xr-x | git-sonar | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -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" \ |
