diff options
-rwxr-xr-x | radar-base.sh | 26 | ||||
-rwxr-xr-x | test-colors.sh | 44 |
2 files changed, 51 insertions, 19 deletions
diff --git a/radar-base.sh b/radar-base.sh index f707587..5672e07 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -24,9 +24,13 @@ prepare_bash_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_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"}" + 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" } prepare_zsh_colors() { @@ -48,9 +52,15 @@ prepare_zsh_colors() { COLOR_CHANGES_CONFLICTED="%{${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-$fg_bold[yellow]}%}" COLOR_CHANGES_UNTRACKED="%{${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-$fg_bold[white]}%}" + local italic_m="$(printf '\xF0\x9D\x98\xAE')" + + COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH:-$reset_color}%}" + MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"%{$reset_color%}$italic_m%{$reset_color%}"}" + RESET_COLOR_LOCAL="%{${GIT_RADAR_COLOR_LOCAL_RESET:-$reset_color}%}" RESET_COLOR_REMOTE="%{${GIT_RADAR_COLOR_REMOTE_RESET:-$reset_color}%}" RESET_COLOR_CHANGES="%{${GIT_RADAR_COLOR_CHANGES_RESET:-$reset_color}%}" + RESET_COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH_RESET:-$reset_color}%}" } in_current_dir() { @@ -168,7 +178,7 @@ branch_ref() { readable_branch_name() { if is_repo; then - printf '%s' "$(branch_name || printf '%s' "detached@$(commit_short_sha)")" + printf '%s' "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" fi } @@ -460,7 +470,6 @@ zsh_color_local_commits() { } bash_color_remote_commits() { - local remote_master="\xF0\x9D\x98\xAE" # an italic m to represent master local green_ahead_arrow="${COLOR_REMOTE_AHEAD}←$RESET_COLOR_REMOTE" local red_behind_arrow="${COLOR_REMOTE_BEHIND}→$RESET_COLOR_REMOTE" local yellow_diverged_arrow="${COLOR_REMOTE_DIVERGED}⇄$RESET_COLOR_REMOTE" @@ -471,11 +480,11 @@ bash_color_remote_commits() { remote_behind="$(remote_behind_of_master "$remote_branch")" if [[ "$remote_behind" -gt "0" && "$remote_ahead" -gt "0" ]]; then - remote="$remote_master $remote_behind $yellow_diverged_arrow $remote_ahead " + remote="$MASTER_SYMBOL $remote_behind $yellow_diverged_arrow $remote_ahead " elif [[ "$remote_ahead" -gt "0" ]]; then - remote="$remote_master $green_ahead_arrow $remote_ahead " + remote="$MASTER_SYMBOL $green_ahead_arrow $remote_ahead " elif [[ "$remote_behind" -gt "0" ]]; then - remote="$remote_master $remote_behind $red_behind_arrow " + remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow " fi else remote="upstream $not_upstream " @@ -485,7 +494,6 @@ bash_color_remote_commits() { } zsh_color_remote_commits() { - local remote_master="$(printf '\xF0\x9D\x98\xAE')" # an italic m to represent master local green_ahead_arrow="${COLOR_REMOTE_AHEAD}←$RESET_COLOR_REMOTE" local red_behind_arrow="${COLOR_REMOTE_BEHIND}→$RESET_COLOR_REMOTE" local yellow_diverged_arrow="${COLOR_REMOTE_DIVERGED}⇄$RESET_COLOR_REMOTE" @@ -496,11 +504,11 @@ zsh_color_remote_commits() { remote_behind="$(remote_behind_of_master "$remote_branch")" if [[ "$remote_behind" -gt "0" && "$remote_ahead" -gt "0" ]]; then - remote="$remote_master $remote_behind $yellow_diverged_arrow $remote_ahead " + remote="$MASTER_SYMBOL $remote_behind $yellow_diverged_arrow $remote_ahead " elif [[ "$remote_ahead" -gt "0" ]]; then - remote="$remote_master $green_ahead_arrow $remote_ahead " + remote="$MASTER_SYMBOL $green_ahead_arrow $remote_ahead " elif [[ "$remote_behind" -gt "0" ]]; then - remote="$remote_master $remote_behind $red_behind_arrow " + remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow " fi else remote="upstream $not_upstream " diff --git a/test-colors.sh b/test-colors.sh index 0506145..196b60b 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -84,9 +84,13 @@ set_env_vars() { export GIT_RADAR_COLOR_CHANGES_CONFLICTED="changes-conflicted" export GIT_RADAR_COLOR_CHANGES_UNTRACKED="changes-untracked" + export GIT_RADAR_COLOR_BRANCH="branch-color" + export GIT_RADAR_MASTER_SYMBOL="m" + export GIT_RADAR_COLOR_LOCAL_RESET="local-reset" export GIT_RADAR_COLOR_REMOTE_RESET="remote-reset" export GIT_RADAR_COLOR_CHANGES_RESET="change-reset" + export GIT_RADAR_COLOR_BRANCH_RESET="branch-reset" } reset_env_vars() { @@ -104,9 +108,13 @@ reset_env_vars() { export GIT_RADAR_COLOR_CHANGES_CONFLICTED="" export GIT_RADAR_COLOR_CHANGES_UNTRACKED="" + export GIT_RADAR_COLOR_BRANCH="" + export GIT_RADAR_MASTER_SYMBOL="" + export GIT_RADAR_COLOR_LOCAL_RESET="" export GIT_RADAR_COLOR_REMOTE_RESET="" export GIT_RADAR_COLOR_CHANGES_RESET="" + export GIT_RADAR_COLOR_BRANCH_RESET="" } create_rc_file() { @@ -124,9 +132,13 @@ create_rc_file() { echo 'GIT_RADAR_COLOR_CHANGES_CONFLICTED="changes-conflicted"' >> .gitradarrc echo 'GIT_RADAR_COLOR_CHANGES_UNTRACKED="changes-untracked"' >> .gitradarrc + echo 'export GIT_RADAR_COLOR_BRANCH="branch-color"' >> .gitradarrc + echo 'export GIT_RADAR_MASTER_SYMBOL="m"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_LOCAL_RESET="local-reset"' >> .gitradarrc echo 'GIT_RADAR_COLOR_REMOTE_RESET="remote-reset"' >> .gitradarrc echo 'GIT_RADAR_COLOR_CHANGES_RESET="change-reset"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_BRANCH_RESET="branch-reset"' >> .gitradarrc } test_with_rcfile_bash() { @@ -152,9 +164,13 @@ test_with_rcfile_bash() { assertEquals "$COLOR_CHANGES_CONFLICTED" "\x01changes-conflicted\x02" assertEquals "$COLOR_CHANGES_UNTRACKED" "\x01changes-untracked\x02" + assertEquals "$COLOR_BRANCH" "\x01branch-color\x02" + assertEquals "$MASTER_SYMBOL" "m" + assertEquals "$RESET_COLOR_LOCAL" "\x01local-reset\x02" assertEquals "$RESET_COLOR_REMOTE" "\x01remote-reset\x02" assertEquals "$RESET_COLOR_CHANGES" "\x01change-reset\x02" + assertEquals "$RESET_COLOR_BRANCH" "\x01branch-reset\x02" rm_tmp } @@ -183,9 +199,13 @@ test_with_rcfile_zsh() { assertEquals "$COLOR_CHANGES_CONFLICTED" "%{changes-conflicted%}" assertEquals "$COLOR_CHANGES_UNTRACKED" "%{changes-untracked%}" + assertEquals "$COLOR_BRANCH" "%{branch-color%}" + assertEquals "$MASTER_SYMBOL" "m" + assertEquals "$RESET_COLOR_LOCAL" "%{local-reset%}" assertEquals "$RESET_COLOR_REMOTE" "%{remote-reset%}" assertEquals "$RESET_COLOR_CHANGES" "%{change-reset%}" + assertEquals "$RESET_COLOR_BRANCH" "%{branch-reset%}" rm_tmp } @@ -209,9 +229,13 @@ test_with_env_vars_bash() { assertEquals "$COLOR_CHANGES_CONFLICTED" "\x01changes-conflicted\x02" assertEquals "$COLOR_CHANGES_UNTRACKED" "\x01changes-untracked\x02" + assertEquals "$COLOR_BRANCH" "\x01branch-color\x02" + assertEquals "$MASTER_SYMBOL" "m" + assertEquals "$RESET_COLOR_LOCAL" "\x01local-reset\x02" assertEquals "$RESET_COLOR_REMOTE" "\x01remote-reset\x02" assertEquals "$RESET_COLOR_CHANGES" "\x01change-reset\x02" + assertEquals "$RESET_COLOR_BRANCH" "\x01branch-reset\x02" } test_with_env_vars_zsh() { @@ -234,9 +258,13 @@ test_with_env_vars_zsh() { assertEquals "$COLOR_CHANGES_CONFLICTED" "%{changes-conflicted%}" assertEquals "$COLOR_CHANGES_UNTRACKED" "%{changes-untracked%}" + assertEquals "$COLOR_BRANCH" "%{branch-color%}" + assertEquals "$MASTER_SYMBOL" "m" + assertEquals "$RESET_COLOR_LOCAL" "%{local-reset%}" assertEquals "$RESET_COLOR_REMOTE" "%{remote-reset%}" assertEquals "$RESET_COLOR_CHANGES" "%{change-reset%}" + assertEquals "$RESET_COLOR_BRANCH" "%{branch-reset%}" } test_bash_colors_local() { @@ -349,9 +377,7 @@ test_bash_colors_remote() { git checkout -b mybranch --quiet git push --quiet -u origin mybranch >/dev/null - printf -v m '\xF0\x9D\x98\xAE' - - printf -v expected "$m 1 \x01remote-behind\x02→\x01remote-reset\x02 " + printf -v expected "m 1 \x01remote-behind\x02→\x01remote-reset\x02 " assertEquals "$expected" "$(bash_color_remote_commits)" echo "bar" > bar @@ -359,13 +385,13 @@ test_bash_colors_remote() { git commit -m "new commit" --quiet git push --quiet >/dev/null - printf -v expected "$m 1 \x01remote-diverged\x02⇄\x01remote-reset\x02 1 " + printf -v expected "m 1 \x01remote-diverged\x02⇄\x01remote-reset\x02 1 " assertEquals "$expected" "$(bash_color_remote_commits)" git pull origin master --quiet >/dev/null git push --quiet >/dev/null - printf -v expected "$m \x01remote-ahead\x02←\x01remote-reset\x02 2 " + printf -v expected "m \x01remote-ahead\x02←\x01remote-reset\x02 2 " assertEquals "$expected" "$(bash_color_remote_commits)" rm_tmp @@ -398,21 +424,19 @@ test_zsh_colors_remote() { git checkout -b mybranch --quiet git push --quiet -u origin mybranch >/dev/null - printf -v m '\xF0\x9D\x98\xAE' - - assertEquals "$m 1 %{remote-behind%}→%{remote-reset%} " "$(zsh_color_remote_commits)" + assertEquals "m 1 %{remote-behind%}→%{remote-reset%} " "$(zsh_color_remote_commits)" echo "bar" > bar git add . git commit -m "new commit" --quiet git push --quiet >/dev/null - assertEquals "$m 1 %{remote-diverged%}⇄%{remote-reset%} 1 " "$(zsh_color_remote_commits)" + assertEquals "m 1 %{remote-diverged%}⇄%{remote-reset%} 1 " "$(zsh_color_remote_commits)" git pull origin master --quiet >/dev/null git push --quiet >/dev/null - assertEquals "$m %{remote-ahead%}←%{remote-reset%} 2 " "$(zsh_color_remote_commits)" + assertEquals "m %{remote-ahead%}←%{remote-reset%} 2 " "$(zsh_color_remote_commits)" rm_tmp } |