From 3c7b0841158b23be74f796c84880ec01a91cc5ad Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 13:25:03 +0100 Subject: Make zsh remote commit colors configurable --- radar-base.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index d019629..7d5db56 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -4,6 +4,15 @@ dot_git="" cwd="" remote="" +prepare_zsh_colors() { + ZSH_COLOR_REMOTE_AHEAD="${GIT_RADAR_COLOR_ZSH_REMOTE_AHEAD:-$fg_bold[green]}" + ZSH_COLOR_REMOTE_BEHIND="${GIT_RADAR_COLOR_ZSH_REMOTE_BEHIND:-$fg_bold[red]}" + ZSH_COLOR_REMOTE_DIVERGED="${GIT_RADAR_COLOR_ZSH_REMOTE_DIVERGED:-$fg_bold[yellow]}" + ZSH_COLOR_REMOTE_NOT_UPSTREAM="${GIT_RADAR_COLOR_ZSH_REMOTE_NOT_UPSTREAM:-$fg_bold[red]}" + + ZSH_RESET_COLOR="${GIT_RADAR_COLOR_ZSH_RESET:-$reset_color}" +} + in_current_dir() { local wd="$(pwd)" if [[ "$wd" == $cwd ]]; then @@ -448,11 +457,13 @@ bash_color_remote_commits() { } zsh_color_remote_commits() { + prepare_zsh_colors + local remote_master="$(printf '\xF0\x9D\x98\xAE')" # an italic m to represent master - local green_ahead_arrow="%{$fg_bold[green]%}←%{$reset_color%}" - local red_behind_arrow="%{$fg_bold[red]%}→%{$reset_color%}" - local yellow_diverged_arrow="%{$fg_bold[yellow]%}⇄%{$reset_color%}" - local not_upstream="%{$fg_bold[red]%}⚡%{$reset_color%}" + local green_ahead_arrow="%{$ZSH_COLOR_REMOTE_AHEAD%}←%{$ZSH_RESET_COLOR%}" + local red_behind_arrow="%{$ZSH_COLOR_REMOTE_BEHIND%}→%{$ZSH_RESET_COLOR%}" + local yellow_diverged_arrow="%{$ZSH_COLOR_REMOTE_DIVERGED%}⇄%{$ZSH_RESET_COLOR%}" + local not_upstream="%{$ZSH_COLOR_REMOTE_NOT_UPSTREAM%}⚡%{$ZSH_RESET_COLOR%}" if remote_branch="$(remote_branch_name)"; then remote_ahead="$(remote_ahead_of_master "$remote_branch")" -- cgit v1.2.3 From 0133ca499824f4d41ef9bd9a847934bd66fa32cd Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 13:43:59 +0100 Subject: Rename reset color and move color setup --- prompt.zsh | 2 +- radar-base.sh | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/prompt.zsh b/prompt.zsh index a5ccba5..80c6f12 100755 --- a/prompt.zsh +++ b/prompt.zsh @@ -5,7 +5,7 @@ args=$@ source "$dot/radar-base.sh" if is_repo; then - autoload colors && colors + prepare_zsh_colors printf '%s' "%{$fg_bold[black]%} git:(%{$reset_color%}" if show_remote_status $args; then zsh_color_remote_commits diff --git a/radar-base.sh b/radar-base.sh index 7d5db56..ee45300 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -5,12 +5,14 @@ cwd="" remote="" prepare_zsh_colors() { + autoload colors && colors + ZSH_COLOR_REMOTE_AHEAD="${GIT_RADAR_COLOR_ZSH_REMOTE_AHEAD:-$fg_bold[green]}" ZSH_COLOR_REMOTE_BEHIND="${GIT_RADAR_COLOR_ZSH_REMOTE_BEHIND:-$fg_bold[red]}" ZSH_COLOR_REMOTE_DIVERGED="${GIT_RADAR_COLOR_ZSH_REMOTE_DIVERGED:-$fg_bold[yellow]}" ZSH_COLOR_REMOTE_NOT_UPSTREAM="${GIT_RADAR_COLOR_ZSH_REMOTE_NOT_UPSTREAM:-$fg_bold[red]}" - ZSH_RESET_COLOR="${GIT_RADAR_COLOR_ZSH_RESET:-$reset_color}" + ZSH_RESET_COLOR_REMOTE="${GIT_RADAR_COLOR_ZSH_REMOTE_RESET:-$reset_color}" } in_current_dir() { @@ -457,13 +459,11 @@ bash_color_remote_commits() { } zsh_color_remote_commits() { - prepare_zsh_colors - local remote_master="$(printf '\xF0\x9D\x98\xAE')" # an italic m to represent master - local green_ahead_arrow="%{$ZSH_COLOR_REMOTE_AHEAD%}←%{$ZSH_RESET_COLOR%}" - local red_behind_arrow="%{$ZSH_COLOR_REMOTE_BEHIND%}→%{$ZSH_RESET_COLOR%}" - local yellow_diverged_arrow="%{$ZSH_COLOR_REMOTE_DIVERGED%}⇄%{$ZSH_RESET_COLOR%}" - local not_upstream="%{$ZSH_COLOR_REMOTE_NOT_UPSTREAM%}⚡%{$ZSH_RESET_COLOR%}" + local green_ahead_arrow="%{$ZSH_COLOR_REMOTE_AHEAD%}←%{$ZSH_RESET_COLOR_REMOTE%}" + local red_behind_arrow="%{$ZSH_COLOR_REMOTE_BEHIND%}→%{$ZSH_RESET_COLOR_REMOTE%}" + local yellow_diverged_arrow="%{$ZSH_COLOR_REMOTE_DIVERGED%}⇄%{$ZSH_RESET_COLOR_REMOTE%}" + local not_upstream="%{$ZSH_COLOR_REMOTE_NOT_UPSTREAM%}⚡%{$ZSH_RESET_COLOR_REMOTE%}" if remote_branch="$(remote_branch_name)"; then remote_ahead="$(remote_ahead_of_master "$remote_branch")" -- cgit v1.2.3 From d3955bde0d873edbd70c8902954c9d3761a3b935 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 13:44:36 +0100 Subject: Make zsh local commit colors configurable --- radar-base.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index ee45300..99e8a23 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -12,7 +12,13 @@ prepare_zsh_colors() { ZSH_COLOR_REMOTE_DIVERGED="${GIT_RADAR_COLOR_ZSH_REMOTE_DIVERGED:-$fg_bold[yellow]}" ZSH_COLOR_REMOTE_NOT_UPSTREAM="${GIT_RADAR_COLOR_ZSH_REMOTE_NOT_UPSTREAM:-$fg_bold[red]}" + ZSH_COLOR_LOCAL_AHEAD="${GIT_RADAR_COLOR_ZSH_LOCAL_AHEAD:-$fg_bold[green]}" + ZSH_COLOR_LOCAL_BEHIND="${GIT_RADAR_COLOR_ZSH_LOCAL_BEHIND:-$fg_bold[red]}" + ZSH_COLOR_LOCAL_DIVERGED="${GIT_RADAR_COLOR_ZSH_LOCAL_DIVERGED:-$fg_bold[yellow]}" + + ZSH_RESET_COLOR_LOCAL="${GIT_RADAR_COLOR_ZSH_LOCAL_RESET:-$reset_color}" ZSH_RESET_COLOR_REMOTE="${GIT_RADAR_COLOR_ZSH_REMOTE_RESET:-$reset_color}" + ZSH_RESET_COLOR_CHANGES="${GIT_RADAR_COLOR_ZSH_CHANGES_RESET:-$reset_color}" } in_current_dir() { @@ -413,9 +419,9 @@ bash_color_local_commits() { zsh_color_local_commits() { local separator="${1:- }" - local ahead_arrow="%{$fg_bold[green]%}↑%{$reset_color%}" - local behind_arrow="%{$fg_bold[red]%}↓%{$reset_color%}" - local diverged_arrow="%{$fg_bold[yellow]%}⇵%{$reset_color%}" + local ahead_arrow="%{$ZSH_COLOR_LOCAL_AHEAD%}↑%{$ZSH_RESET_COLOR_LOCAL%}" + local behind_arrow="%{$ZSH_COLOR_LOCAL_BEHIND%}↓%{$ZSH_RESET_COLOR_LOCAL%}" + local diverged_arrow="%{$ZSH_COLOR_LOCAL_DIVERGED%}⇵%{$ZSH_RESET_COLOR_LOCAL%}" local local_commits="" if remote_branch="$(remote_branch_name)"; then -- cgit v1.2.3 From f7bb14861a4ab034345d6830f82420433a6dab17 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 13:55:22 +0100 Subject: Make zsh changes colors configurable --- radar-base.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 99e8a23..798c6e1 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -16,6 +16,11 @@ prepare_zsh_colors() { ZSH_COLOR_LOCAL_BEHIND="${GIT_RADAR_COLOR_ZSH_LOCAL_BEHIND:-$fg_bold[red]}" ZSH_COLOR_LOCAL_DIVERGED="${GIT_RADAR_COLOR_ZSH_LOCAL_DIVERGED:-$fg_bold[yellow]}" + ZSH_COLOR_CHANGES_STAGED="${GIT_RADAR_COLOR_ZSH_CHANGES_STAGED:-$fg_bold[green]}" + ZSH_COLOR_CHANGES_UNSTAGED="${GIT_RADAR_COLOR_ZSH_CHANGES_UNSTAGED:-$fg_bold[red]}" + ZSH_COLOR_CHANGES_CONFLICTED="${GIT_RADAR_COLOR_ZSH_CHANGES_CONFLICTED:-$fg_bold[yellow]}" + ZSH_COLOR_CHANGES_UNTRACKED="${GIT_RADAR_COLOR_ZSH_CHANGES_UNTRACKED:-$fg_bold[white]}" + ZSH_RESET_COLOR_LOCAL="${GIT_RADAR_COLOR_ZSH_LOCAL_RESET:-$reset_color}" ZSH_RESET_COLOR_REMOTE="${GIT_RADAR_COLOR_ZSH_REMOTE_RESET:-$reset_color}" ZSH_RESET_COLOR_CHANGES="${GIT_RADAR_COLOR_ZSH_CHANGES_RESET:-$reset_color}" @@ -362,11 +367,11 @@ zsh_color_changes_status() { local changes="" if [[ -n "$porcelain" ]]; then - local staged_prefix="%{$fg_bold[green]%}" - local unstaged_prefix="%{$fg_bold[red]%}" - local conflicted_prefix="%{$fg_bold[yellow]%}" - local untracked_prefix="%{$fg_bold[white]%}" - local suffix="%{$reset_color%}" + local staged_prefix="%{$ZSH_COLOR_CHANGES_STAGED%}" + local unstaged_prefix="%{$ZSH_COLOR_CHANGES_UNSTAGED%}" + local conflicted_prefix="%{$ZSH_COLOR_CHANGES_CONFLICTED%}" + local untracked_prefix="%{$ZSH_COLOR_CHANGES_UNTRACKED%}" + local suffix="%{$ZSH_RESET_COLOR_CHANGES%}" local staged_changes="$(staged_status "$porcelain" "$staged_prefix" "$suffix")" local unstaged_changes="$(unstaged_status "$porcelain" "$unstaged_prefix" "$suffix")" -- cgit v1.2.3 From 026ae4fdb3253946707a66448f65d4297c652414 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 14:10:16 +0100 Subject: No need for separate color vars --- radar-base.sh | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 798c6e1..2702b8e 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -7,23 +7,23 @@ remote="" prepare_zsh_colors() { autoload colors && colors - ZSH_COLOR_REMOTE_AHEAD="${GIT_RADAR_COLOR_ZSH_REMOTE_AHEAD:-$fg_bold[green]}" - ZSH_COLOR_REMOTE_BEHIND="${GIT_RADAR_COLOR_ZSH_REMOTE_BEHIND:-$fg_bold[red]}" - ZSH_COLOR_REMOTE_DIVERGED="${GIT_RADAR_COLOR_ZSH_REMOTE_DIVERGED:-$fg_bold[yellow]}" - ZSH_COLOR_REMOTE_NOT_UPSTREAM="${GIT_RADAR_COLOR_ZSH_REMOTE_NOT_UPSTREAM:-$fg_bold[red]}" + COLOR_REMOTE_AHEAD="${GIT_RADAR_COLOR_REMOTE_AHEAD:-$fg_bold[green]}" + COLOR_REMOTE_BEHIND="${GIT_RADAR_COLOR_REMOTE_BEHIND:-$fg_bold[red]}" + COLOR_REMOTE_DIVERGED="${GIT_RADAR_COLOR_REMOTE_DIVERGED:-$fg_bold[yellow]}" + COLOR_REMOTE_NOT_UPSTREAM="${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-$fg_bold[red]}" - ZSH_COLOR_LOCAL_AHEAD="${GIT_RADAR_COLOR_ZSH_LOCAL_AHEAD:-$fg_bold[green]}" - ZSH_COLOR_LOCAL_BEHIND="${GIT_RADAR_COLOR_ZSH_LOCAL_BEHIND:-$fg_bold[red]}" - ZSH_COLOR_LOCAL_DIVERGED="${GIT_RADAR_COLOR_ZSH_LOCAL_DIVERGED:-$fg_bold[yellow]}" + COLOR_LOCAL_AHEAD="${GIT_RADAR_COLOR_LOCAL_AHEAD:-$fg_bold[green]}" + COLOR_LOCAL_BEHIND="${GIT_RADAR_COLOR_LOCAL_BEHIND:-$fg_bold[red]}" + COLOR_LOCAL_DIVERGED="${GIT_RADAR_COLOR_LOCAL_DIVERGED:-$fg_bold[yellow]}" - ZSH_COLOR_CHANGES_STAGED="${GIT_RADAR_COLOR_ZSH_CHANGES_STAGED:-$fg_bold[green]}" - ZSH_COLOR_CHANGES_UNSTAGED="${GIT_RADAR_COLOR_ZSH_CHANGES_UNSTAGED:-$fg_bold[red]}" - ZSH_COLOR_CHANGES_CONFLICTED="${GIT_RADAR_COLOR_ZSH_CHANGES_CONFLICTED:-$fg_bold[yellow]}" - ZSH_COLOR_CHANGES_UNTRACKED="${GIT_RADAR_COLOR_ZSH_CHANGES_UNTRACKED:-$fg_bold[white]}" + COLOR_CHANGES_STAGED="${GIT_RADAR_COLOR_CHANGES_STAGED:-$fg_bold[green]}" + COLOR_CHANGES_UNSTAGED="${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-$fg_bold[red]}" + COLOR_CHANGES_CONFLICTED="${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-$fg_bold[yellow]}" + COLOR_CHANGES_UNTRACKED="${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-$fg_bold[white]}" - ZSH_RESET_COLOR_LOCAL="${GIT_RADAR_COLOR_ZSH_LOCAL_RESET:-$reset_color}" - ZSH_RESET_COLOR_REMOTE="${GIT_RADAR_COLOR_ZSH_REMOTE_RESET:-$reset_color}" - ZSH_RESET_COLOR_CHANGES="${GIT_RADAR_COLOR_ZSH_CHANGES_RESET:-$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}" } in_current_dir() { @@ -367,11 +367,11 @@ zsh_color_changes_status() { local changes="" if [[ -n "$porcelain" ]]; then - local staged_prefix="%{$ZSH_COLOR_CHANGES_STAGED%}" - local unstaged_prefix="%{$ZSH_COLOR_CHANGES_UNSTAGED%}" - local conflicted_prefix="%{$ZSH_COLOR_CHANGES_CONFLICTED%}" - local untracked_prefix="%{$ZSH_COLOR_CHANGES_UNTRACKED%}" - local suffix="%{$ZSH_RESET_COLOR_CHANGES%}" + local staged_prefix="%{$COLOR_CHANGES_STAGED%}" + local unstaged_prefix="%{$COLOR_CHANGES_UNSTAGED%}" + local conflicted_prefix="%{$COLOR_CHANGES_CONFLICTED%}" + local untracked_prefix="%{$COLOR_CHANGES_UNTRACKED%}" + local suffix="%{$RESET_COLOR_CHANGES%}" local staged_changes="$(staged_status "$porcelain" "$staged_prefix" "$suffix")" local unstaged_changes="$(unstaged_status "$porcelain" "$unstaged_prefix" "$suffix")" @@ -424,9 +424,9 @@ bash_color_local_commits() { zsh_color_local_commits() { local separator="${1:- }" - local ahead_arrow="%{$ZSH_COLOR_LOCAL_AHEAD%}↑%{$ZSH_RESET_COLOR_LOCAL%}" - local behind_arrow="%{$ZSH_COLOR_LOCAL_BEHIND%}↓%{$ZSH_RESET_COLOR_LOCAL%}" - local diverged_arrow="%{$ZSH_COLOR_LOCAL_DIVERGED%}⇵%{$ZSH_RESET_COLOR_LOCAL%}" + local ahead_arrow="%{$COLOR_LOCAL_AHEAD%}↑%{$RESET_COLOR_LOCAL%}" + local behind_arrow="%{$COLOR_LOCAL_BEHIND%}↓%{$RESET_COLOR_LOCAL%}" + local diverged_arrow="%{$COLOR_LOCAL_DIVERGED%}⇵%{$RESET_COLOR_LOCAL%}" local local_commits="" if remote_branch="$(remote_branch_name)"; then @@ -471,10 +471,10 @@ 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="%{$ZSH_COLOR_REMOTE_AHEAD%}←%{$ZSH_RESET_COLOR_REMOTE%}" - local red_behind_arrow="%{$ZSH_COLOR_REMOTE_BEHIND%}→%{$ZSH_RESET_COLOR_REMOTE%}" - local yellow_diverged_arrow="%{$ZSH_COLOR_REMOTE_DIVERGED%}⇄%{$ZSH_RESET_COLOR_REMOTE%}" - local not_upstream="%{$ZSH_COLOR_REMOTE_NOT_UPSTREAM%}⚡%{$ZSH_RESET_COLOR_REMOTE%}" + 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%}" + local not_upstream="%{$COLOR_REMOTE_NOT_UPSTREAM%}⚡%{$RESET_COLOR_REMOTE%}" if remote_branch="$(remote_branch_name)"; then remote_ahead="$(remote_ahead_of_master "$remote_branch")" -- cgit v1.2.3 From 8b132d8922ab7aec4446842b630299dfd7f6e8e3 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 14:28:27 +0100 Subject: Small refactor to move zero length escaping characters into one location --- radar-base.sh | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 2702b8e..8951b43 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -7,23 +7,23 @@ remote="" prepare_zsh_colors() { autoload colors && colors - COLOR_REMOTE_AHEAD="${GIT_RADAR_COLOR_REMOTE_AHEAD:-$fg_bold[green]}" - COLOR_REMOTE_BEHIND="${GIT_RADAR_COLOR_REMOTE_BEHIND:-$fg_bold[red]}" - COLOR_REMOTE_DIVERGED="${GIT_RADAR_COLOR_REMOTE_DIVERGED:-$fg_bold[yellow]}" - COLOR_REMOTE_NOT_UPSTREAM="${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-$fg_bold[red]}" + COLOR_REMOTE_AHEAD="%{${GIT_RADAR_COLOR_REMOTE_AHEAD:-$fg_bold[green]}%}" + COLOR_REMOTE_BEHIND="%{${GIT_RADAR_COLOR_REMOTE_BEHIND:-$fg_bold[red]}%}" + COLOR_REMOTE_DIVERGED="%{${GIT_RADAR_COLOR_REMOTE_DIVERGED:-$fg_bold[yellow]}%}" + COLOR_REMOTE_NOT_UPSTREAM="%{${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-$fg_bold[red]}%}" - COLOR_LOCAL_AHEAD="${GIT_RADAR_COLOR_LOCAL_AHEAD:-$fg_bold[green]}" - COLOR_LOCAL_BEHIND="${GIT_RADAR_COLOR_LOCAL_BEHIND:-$fg_bold[red]}" - COLOR_LOCAL_DIVERGED="${GIT_RADAR_COLOR_LOCAL_DIVERGED:-$fg_bold[yellow]}" + COLOR_LOCAL_AHEAD="%{${GIT_RADAR_COLOR_LOCAL_AHEAD:-$fg_bold[green]}%}" + COLOR_LOCAL_BEHIND="%{${GIT_RADAR_COLOR_LOCAL_BEHIND:-$fg_bold[red]}%}" + COLOR_LOCAL_DIVERGED="%{${GIT_RADAR_COLOR_LOCAL_DIVERGED:-$fg_bold[yellow]}%}" - COLOR_CHANGES_STAGED="${GIT_RADAR_COLOR_CHANGES_STAGED:-$fg_bold[green]}" - COLOR_CHANGES_UNSTAGED="${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-$fg_bold[red]}" - COLOR_CHANGES_CONFLICTED="${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-$fg_bold[yellow]}" - COLOR_CHANGES_UNTRACKED="${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-$fg_bold[white]}" + COLOR_CHANGES_STAGED="%{${GIT_RADAR_COLOR_CHANGES_STAGED:-$fg_bold[green]}%}" + COLOR_CHANGES_UNSTAGED="%{${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-$fg_bold[red]}%}" + COLOR_CHANGES_CONFLICTED="%{${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-$fg_bold[yellow]}%}" + COLOR_CHANGES_UNTRACKED="%{${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-$fg_bold[white]}%}" - 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_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}%}" } in_current_dir() { @@ -367,11 +367,11 @@ zsh_color_changes_status() { local changes="" if [[ -n "$porcelain" ]]; then - local staged_prefix="%{$COLOR_CHANGES_STAGED%}" - local unstaged_prefix="%{$COLOR_CHANGES_UNSTAGED%}" - local conflicted_prefix="%{$COLOR_CHANGES_CONFLICTED%}" - local untracked_prefix="%{$COLOR_CHANGES_UNTRACKED%}" - local suffix="%{$RESET_COLOR_CHANGES%}" + local staged_prefix="$COLOR_CHANGES_STAGED" + local unstaged_prefix="$COLOR_CHANGES_UNSTAGED" + local conflicted_prefix="$COLOR_CHANGES_CONFLICTED" + local untracked_prefix="$COLOR_CHANGES_UNTRACKED" + local suffix="$RESET_COLOR_CHANGES" local staged_changes="$(staged_status "$porcelain" "$staged_prefix" "$suffix")" local unstaged_changes="$(unstaged_status "$porcelain" "$unstaged_prefix" "$suffix")" @@ -424,9 +424,9 @@ bash_color_local_commits() { zsh_color_local_commits() { local separator="${1:- }" - local ahead_arrow="%{$COLOR_LOCAL_AHEAD%}↑%{$RESET_COLOR_LOCAL%}" - local behind_arrow="%{$COLOR_LOCAL_BEHIND%}↓%{$RESET_COLOR_LOCAL%}" - local diverged_arrow="%{$COLOR_LOCAL_DIVERGED%}⇵%{$RESET_COLOR_LOCAL%}" + local ahead_arrow="$COLOR_LOCAL_AHEAD↑$RESET_COLOR_LOCAL" + local behind_arrow="$COLOR_LOCAL_BEHIND↓$RESET_COLOR_LOCAL" + local diverged_arrow="$COLOR_LOCAL_DIVERGED⇵$RESET_COLOR_LOCAL" local local_commits="" if remote_branch="$(remote_branch_name)"; then @@ -471,10 +471,10 @@ 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%}" - local not_upstream="%{$COLOR_REMOTE_NOT_UPSTREAM%}⚡%{$RESET_COLOR_REMOTE%}" + 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" + local not_upstream="$COLOR_REMOTE_NOT_UPSTREAM⚡$RESET_COLOR_REMOTE" if remote_branch="$(remote_branch_name)"; then remote_ahead="$(remote_ahead_of_master "$remote_branch")" -- cgit v1.2.3 From 18a19fc516400f2f8db8925b599b70037ac04403 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 14:58:52 +0100 Subject: Duplicate Zsh color config for bash --- prompt.bash | 1 + radar-base.sh | 62 +++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/prompt.bash b/prompt.bash index 429c88d..604d8e1 100755 --- a/prompt.bash +++ b/prompt.bash @@ -5,6 +5,7 @@ args=$@ source "$dot/radar-base.sh" if is_repo; then + prepare_bash_colors printf " \x01\033[1;30m\x02git:(\x01\033[0m\x02" if show_remote_status $args; then bash_color_remote_commits diff --git a/radar-base.sh b/radar-base.sh index 8951b43..cb1d4b6 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -4,6 +4,26 @@ dot_git="" cwd="" remote="" +prepare_bash_colors() { + COLOR_REMOTE_AHEAD="\x01${GIT_RADAR_COLOR_REMOTE_AHEAD:-"\\033[1;32m"}\x02" + COLOR_REMOTE_BEHIND="\x01${GIT_RADAR_COLOR_REMOTE_BEHIND:-"\\033[1;31m"}\x02" + COLOR_REMOTE_DIVERGED="\x01${GIT_RADAR_COLOR_REMOTE_DIVERGED:-"\\033[1;33m"}\x02" + COLOR_REMOTE_NOT_UPSTREAM="\x01${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-"\\033[1;31m"}\x02" + + COLOR_LOCAL_AHEAD="\x01${GIT_RADAR_COLOR_LOCAL_AHEAD:-"\\033[1;32m"}\x02" + COLOR_LOCAL_BEHIND="\x01${GIT_RADAR_COLOR_LOCAL_BEHIND:-"\\033[1;31m"}\x02" + COLOR_LOCAL_DIVERGED="\x01${GIT_RADAR_COLOR_LOCAL_DIVERGED:-"\\033[1;33m"}\x02" + + COLOR_CHANGES_STAGED="\x01${GIT_RADAR_COLOR_CHANGES_STAGED:-"\\033[1;32m"}\x02" + COLOR_CHANGES_UNSTAGED="\x01${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-"\\033[1;31m"}\x02" + 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" + + 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" +} + prepare_zsh_colors() { autoload colors && colors @@ -329,16 +349,10 @@ bash_color_changes_status() { local changes="" if [[ -n "$porcelain" ]]; then - local green_staged_prefix="\x01\033[1;32m\x02" - local red_unstaged_prefix="\x01\033[1;31m\x02" - local yellow_conflicted_prefix="\x01\033[1;33m\x02" - local grey_untracked_prefix="\x01\033[1;37m\x02" - local reset_suffix="\x01\033[0m\x02" - - local staged_changes="$(staged_status "$porcelain" "$green_staged_prefix" "$reset_suffix")" - local unstaged_changes="$(unstaged_status "$porcelain" "$red_unstaged_prefix" "$reset_suffix")" - local untracked_changes="$(untracked_status "$porcelain" "$grey_untracked_prefix" "$reset_suffix")" - local conflicted_changes="$(conflicted_status "$porcelain" "$yellow_conflicted_prefix" "$reset_suffix")" + local staged_changes="$(staged_status "$porcelain" "$COLOR_CHANGES_STAGED" "$RESET_COLOR_CHANGES")" + local unstaged_changes="$(unstaged_status "$porcelain" "$COLOR_CHANGES_UNSTAGED" "$RESET_COLOR_CHANGES")" + local untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_CONFLICTED" "$RESET_COLOR_CHANGES")" + local conflicted_changes="$(conflicted_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")" if [[ -n "$staged_changes" ]]; then staged_changes="$separator$staged_changes" fi @@ -367,16 +381,10 @@ zsh_color_changes_status() { local changes="" if [[ -n "$porcelain" ]]; then - local staged_prefix="$COLOR_CHANGES_STAGED" - local unstaged_prefix="$COLOR_CHANGES_UNSTAGED" - local conflicted_prefix="$COLOR_CHANGES_CONFLICTED" - local untracked_prefix="$COLOR_CHANGES_UNTRACKED" - local suffix="$RESET_COLOR_CHANGES" - - local staged_changes="$(staged_status "$porcelain" "$staged_prefix" "$suffix")" - local unstaged_changes="$(unstaged_status "$porcelain" "$unstaged_prefix" "$suffix")" - local untracked_changes="$(untracked_status "$porcelain" "$untracked_prefix" "$suffix")" - local conflicted_changes="$(conflicted_status "$porcelain" "$conflicted_prefix" "$suffix")" + local staged_changes="$(staged_status "$porcelain" "$COLOR_CHANGES_STAGED" "$RESET_COLOR_CHANGES")" + local unstaged_changes="$(unstaged_status "$porcelain" "$COLOR_CHANGES_UNSTAGED" "$RESET_COLOR_CHANGES")" + local untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_CONFLICTED" "$RESET_COLOR_CHANGES")" + local conflicted_changes="$(conflicted_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")" if [[ -n "$staged_changes" ]]; then staged_changes="$separator$staged_changes" fi @@ -401,9 +409,9 @@ zsh_color_changes_status() { bash_color_local_commits() { local separator="${1:- }" - local green_ahead_arrow="\x01\033[1;32m\x02↑\x01\033[0m\x02" - local red_behind_arrow="\x01\033[1;31m\x02↓\x01\033[0m\x02" - local yellow_diverged_arrow="\x01\033[1;33m\x02⇵\x01\033[0m\x02" + local green_ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL" + local red_behind_arrow="${COLOR_LOCAL_BEHIND}↓$RESET_COLOR_LOCAL" + local yellow_diverged_arrow="${COLOR_LOCAL_DIVERGED}⇵$RESET_COLOR_LOCAL" local local_commits="" if remote_branch="$(remote_branch_name)"; then @@ -446,10 +454,10 @@ 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="\x01\033[1;32m\x02←\x01\033[0m\x02" - local red_behind_arrow="\x01\033[1;31m\x02→\x01\033[0m\x02" - local yellow_diverged_arrow="\x01\033[1;33m\x02⇄\x01\033[0m\x02" - local not_upstream="\x01\033[1;31m\x02⚡\x01\033[0m\x02" + 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" + local not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE" if remote_branch="$(remote_branch_name)"; then remote_ahead="$(remote_ahead_of_master "$remote_branch")" -- cgit v1.2.3 From 5b5c784e6caf83652d92532f426f3f8d40836b21 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 16:36:48 +0100 Subject: Fix mistaken colour assignment --- radar-base.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index cb1d4b6..700ec22 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -351,8 +351,8 @@ bash_color_changes_status() { if [[ -n "$porcelain" ]]; then local staged_changes="$(staged_status "$porcelain" "$COLOR_CHANGES_STAGED" "$RESET_COLOR_CHANGES")" local unstaged_changes="$(unstaged_status "$porcelain" "$COLOR_CHANGES_UNSTAGED" "$RESET_COLOR_CHANGES")" - local untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_CONFLICTED" "$RESET_COLOR_CHANGES")" - local conflicted_changes="$(conflicted_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")" + local untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")" + local conflicted_changes="$(conflicted_status "$porcelain" "$COLOR_CHANGES_CONFLICTED" "$RESET_COLOR_CHANGES")" if [[ -n "$staged_changes" ]]; then staged_changes="$separator$staged_changes" fi @@ -383,8 +383,8 @@ zsh_color_changes_status() { if [[ -n "$porcelain" ]]; then local staged_changes="$(staged_status "$porcelain" "$COLOR_CHANGES_STAGED" "$RESET_COLOR_CHANGES")" local unstaged_changes="$(unstaged_status "$porcelain" "$COLOR_CHANGES_UNSTAGED" "$RESET_COLOR_CHANGES")" - local untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_CONFLICTED" "$RESET_COLOR_CHANGES")" - local conflicted_changes="$(conflicted_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")" + local untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")" + local conflicted_changes="$(conflicted_status "$porcelain" "$COLOR_CHANGES_CONFLICTED" "$RESET_COLOR_CHANGES")" if [[ -n "$staged_changes" ]]; then staged_changes="$separator$staged_changes" fi -- cgit v1.2.3 From 0a471db63edcb0ba1fcfb6792e51b791de3fcb81 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 16:46:28 +0100 Subject: Move autoload back to prompt.zsh to make testing easier --- prompt.zsh | 2 ++ radar-base.sh | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/prompt.zsh b/prompt.zsh index 80c6f12..e996b77 100755 --- a/prompt.zsh +++ b/prompt.zsh @@ -5,6 +5,8 @@ args=$@ source "$dot/radar-base.sh" if is_repo; then + autoload colors && colors + prepare_zsh_colors printf '%s' "%{$fg_bold[black]%} git:(%{$reset_color%}" if show_remote_status $args; then diff --git a/radar-base.sh b/radar-base.sh index 700ec22..b2ecd38 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -25,8 +25,6 @@ prepare_bash_colors() { } prepare_zsh_colors() { - autoload colors && colors - COLOR_REMOTE_AHEAD="%{${GIT_RADAR_COLOR_REMOTE_AHEAD:-$fg_bold[green]}%}" COLOR_REMOTE_BEHIND="%{${GIT_RADAR_COLOR_REMOTE_BEHIND:-$fg_bold[red]}%}" COLOR_REMOTE_DIVERGED="%{${GIT_RADAR_COLOR_REMOTE_DIVERGED:-$fg_bold[yellow]}%}" -- cgit v1.2.3 From 4cc2298359b8e2ac4fb0c3a4f061737551e5bb1e Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 16:59:21 +0100 Subject: Test zsh ability to override colors --- test-colors.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 test-colors.sh diff --git a/test-colors.sh b/test-colors.sh new file mode 100755 index 0000000..712dad5 --- /dev/null +++ b/test-colors.sh @@ -0,0 +1,89 @@ +scriptDir="$(cd "$(dirname "$0")"; pwd)" + +source "$scriptDir/radar-base.sh" + +cd_to_tmp() { + tmpfile="/tmp/git-prompt-tests-$(time_now)$1" + mkdir -p "$tmpfile" + cd "$tmpfile" +} + +rm_tmp() { + cd $scriptDir + rm -rf /tmp/git-prompt-tests* +} + +mock_zsh_colors() { + fg_bold[green]=1 + fg_bold[red]=2 + fg_bold[yellow]=3 + fg_bold[white]=4 + + reset_color=0 +} + +test_no_rcfile_zsh() { + mock_zsh_colors + prepare_zsh_colors + + assertEquals "$COLOR_REMOTE_AHEAD" "%{$fg_bold[green]%}" + assertEquals "$COLOR_REMOTE_BEHIND" "%{$fg_bold[red]%}" + assertEquals "$COLOR_REMOTE_DIVERGED" "%{$fg_bold[yellow]%}" + assertEquals "$COLOR_REMOTE_NOT_UPSTREAM" "%{$fg_bold[red]%}" + + assertEquals "$COLOR_LOCAL_AHEAD" "%{$fg_bold[green]%}" + assertEquals "$COLOR_LOCAL_BEHIND" "%{$fg_bold[red]%}" + assertEquals "$COLOR_LOCAL_DIVERGED" "%{$fg_bold[yellow]%}" + + assertEquals "$COLOR_CHANGES_STAGED" "%{$fg_bold[green]%}" + assertEquals "$COLOR_CHANGES_UNSTAGED" "%{$fg_bold[red]%}" + assertEquals "$COLOR_CHANGES_CONFLICTED" "%{$fg_bold[yellow]%}" + assertEquals "$COLOR_CHANGES_UNTRACKED" "%{$fg_bold[white]%}" + + assertEquals "$RESET_COLOR_LOCAL" "%{$reset_color%}" + assertEquals "$RESET_COLOR_REMOTE" "%{$reset_color%}" + assertEquals "$RESET_COLOR_CHANGES" "%{$reset_color%}" +} + +test_with_env_vars_zsh() { + export GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead" + export GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind" + export GIT_RADAR_COLOR_REMOTE_DIVERGED="remote-diverged" + export GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM="not-upstream" + + export GIT_RADAR_COLOR_LOCAL_AHEAD="local-ahead" + export GIT_RADAR_COLOR_LOCAL_BEHIND="local-behind" + export GIT_RADAR_COLOR_LOCAL_DIVERGED="local-diverged" + + export GIT_RADAR_COLOR_CHANGES_STAGED="changes-staged" + export GIT_RADAR_COLOR_CHANGES_UNSTAGED="changes-unstaged" + export GIT_RADAR_COLOR_CHANGES_CONFLICTED="changes-conflicted" + export GIT_RADAR_COLOR_CHANGES_UNTRACKED="changes-untracked" + + export GIT_RADAR_COLOR_LOCAL_RESET="local-reset" + export GIT_RADAR_COLOR_REMOTE_RESET="remote-reset" + export GIT_RADAR_COLOR_CHANGES_RESET="change-reset" + + mock_zsh_colors + prepare_zsh_colors + + assertEquals "$COLOR_REMOTE_AHEAD" "%{remote-ahead%}" + assertEquals "$COLOR_REMOTE_BEHIND" "%{remote-behind%}" + assertEquals "$COLOR_REMOTE_DIVERGED" "%{remote-diverged%}" + assertEquals "$COLOR_REMOTE_NOT_UPSTREAM" "%{not-upstream%}" + + assertEquals "$COLOR_LOCAL_AHEAD" "%{local-ahead%}" + assertEquals "$COLOR_LOCAL_BEHIND" "%{local-behind%}" + assertEquals "$COLOR_LOCAL_DIVERGED" "%{local-diverged%}" + + assertEquals "$COLOR_CHANGES_STAGED" "%{changes-staged%}" + assertEquals "$COLOR_CHANGES_UNSTAGED" "%{changes-unstaged%}" + assertEquals "$COLOR_CHANGES_CONFLICTED" "%{changes-conflicted%}" + assertEquals "$COLOR_CHANGES_UNTRACKED" "%{changes-untracked%}" + + assertEquals "$RESET_COLOR_LOCAL" "%{local-reset%}" + assertEquals "$RESET_COLOR_REMOTE" "%{remote-reset%}" + assertEquals "$RESET_COLOR_CHANGES" "%{change-reset%}" +} + +. ./shunit/shunit2 -- cgit v1.2.3 From c2dbe6f579bac9b40482970287e6a58783994257 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 19:22:13 +0100 Subject: Test zsh local commit colors --- radar-base.sh | 6 +++--- test-colors.sh | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index b2ecd38..63a18c9 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -430,9 +430,9 @@ bash_color_local_commits() { zsh_color_local_commits() { local separator="${1:- }" - local ahead_arrow="$COLOR_LOCAL_AHEAD↑$RESET_COLOR_LOCAL" - local behind_arrow="$COLOR_LOCAL_BEHIND↓$RESET_COLOR_LOCAL" - local diverged_arrow="$COLOR_LOCAL_DIVERGED⇵$RESET_COLOR_LOCAL" + local ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL" + local behind_arrow="${COLOR_LOCAL_BEHIND}↓$RESET_COLOR_LOCAL" + local diverged_arrow="${COLOR_LOCAL_DIVERGED}⇵$RESET_COLOR_LOCAL" local local_commits="" if remote_branch="$(remote_branch_name)"; then diff --git a/test-colors.sh b/test-colors.sh index 712dad5..efcdea9 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -45,7 +45,7 @@ test_no_rcfile_zsh() { assertEquals "$RESET_COLOR_CHANGES" "%{$reset_color%}" } -test_with_env_vars_zsh() { +set_zsh_env_vars() { export GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead" export GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind" export GIT_RADAR_COLOR_REMOTE_DIVERGED="remote-diverged" @@ -63,7 +63,10 @@ test_with_env_vars_zsh() { export GIT_RADAR_COLOR_LOCAL_RESET="local-reset" export GIT_RADAR_COLOR_REMOTE_RESET="remote-reset" export GIT_RADAR_COLOR_CHANGES_RESET="change-reset" +} +test_with_env_vars_zsh() { + set_zsh_env_vars mock_zsh_colors prepare_zsh_colors @@ -86,4 +89,42 @@ test_with_env_vars_zsh() { assertEquals "$RESET_COLOR_CHANGES" "%{change-reset%}" } +test_zsh_colors_local() { + set_zsh_env_vars + prepare_zsh_colors + + cd_to_tmp "remote" + git init --bare --quiet + remoteLocation="$(pwd)" + + cd_to_tmp "repo" + git init --quiet + git remote add origin $remoteLocation + git fetch origin --quiet + git checkout -b master --quiet + touch README + git add README + git commit -m "initial commit" --quiet + git push --quiet -u origin master >/dev/null + repoLocation="$(pwd)" + + echo "foo" > foo + git add . + git commit -m "test commit" --quiet + + assertEquals " 1%{local-ahead%}↑%{local-reset%}" "$(zsh_color_local_commits)" + + git push --quiet >/dev/null + git reset --hard head^ --quiet >/dev/null + + assertEquals " 1%{local-behind%}↓%{local-reset%}" "$(zsh_color_local_commits)" + + echo "foo" > foo + git add . + git commit -m "new commit" --quiet + + assertEquals " 1%{local-diverged%}⇵%{local-reset%}1" "$(zsh_color_local_commits)" + + rm_tmp +} . ./shunit/shunit2 -- cgit v1.2.3 From e388db84ee99641a0260767ccdd4c889b7ca4f7d Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 19:22:50 +0100 Subject: Test zsh remote commit colors --- radar-base.sh | 8 ++++---- test-colors.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 63a18c9..541b5e7 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -477,10 +477,10 @@ 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" - local not_upstream="$COLOR_REMOTE_NOT_UPSTREAM⚡$RESET_COLOR_REMOTE" + 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" + local not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE" if remote_branch="$(remote_branch_name)"; then remote_ahead="$(remote_ahead_of_master "$remote_branch")" diff --git a/test-colors.sh b/test-colors.sh index efcdea9..6b8a797 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -127,4 +127,50 @@ test_zsh_colors_local() { rm_tmp } + +test_zsh_colors_remote() { + set_zsh_env_vars + prepare_zsh_colors + + cd_to_tmp "remote" + git init --bare --quiet + remoteLocation="$(pwd)" + + cd_to_tmp "repo" + git init --quiet + git remote add origin $remoteLocation + git fetch origin --quiet + git checkout -b master --quiet + touch README + git add README + git commit -m "initial commit" --quiet + echo "foo" > foo + git add . + git commit -m "test commit" --quiet + git push --quiet -u origin master >/dev/null + repoLocation="$(pwd)" + + git reset --hard head^ --quiet >/dev/null + 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)" + + 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)" + + git pull origin master --quiet >/dev/null + git push --quiet >/dev/null + + assertEquals "$m %{remote-ahead%}←%{remote-reset%} 2 " "$(zsh_color_remote_commits)" + + rm_tmp +} + . ./shunit/shunit2 -- cgit v1.2.3 From 8f62ad94da6058ac8f66a37caac518b643ccafe3 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 19:54:40 +0100 Subject: Test the zsh color changes configuration --- test-colors.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test-colors.sh b/test-colors.sh index 6b8a797..73aac53 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -173,4 +173,22 @@ test_zsh_colors_remote() { rm_tmp } +test_zsh_colors_changes() { + set_zsh_env_vars + prepare_zsh_colors + + cd_to_tmp + git init --quiet + + touch foo + touch bar + git add bar + echo "bar" > bar + untracked="1%{changes-untracked%}A%{change-reset%}" + unstaged="1%{changes-unstaged%}M%{change-reset%}" + staged="1%{changes-staged%}A%{change-reset%}" + + assertEquals " $staged $unstaged $untracked" "$(zsh_color_changes_status)" +} + . ./shunit/shunit2 -- cgit v1.2.3 From 8377275b42a3a3f72a18fbb2cc67dc6979a13557 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 20:02:04 +0100 Subject: Remove color tests from test-commits as test-colors covers it --- test-commits.sh | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/test-commits.sh b/test-commits.sh index 95addf9..8aa2da2 100755 --- a/test-commits.sh +++ b/test-commits.sh @@ -369,14 +369,10 @@ test_quiet_if_no_remote_master() { rm_tmp } -test_zsh_and_bash_local_commits() { - local zsh_up="%{[green]%}↑%{%}" - local zsh_both="%{[yellow]%}⇵%{%}" - local zsh_down="%{[red]%}↓%{%}" - - printf -v bash_up "\x01\033[1;32m\x02↑\x01\033[0m\x02" - printf -v bash_both "\x01\033[1;33m\x02⇵\x01\033[0m\x02" - printf -v bash_down "\x01\033[1;31m\x02↓\x01\033[0m\x02" +test_local_commits() { + local up="↑" + local both="⇵" + local down="↓" cd_to_tmp "remote" @@ -404,8 +400,8 @@ test_zsh_and_bash_local_commits() { git add . git commit -m "test commit" --quiet - assertEquals " 1$zsh_up" "$(zsh_color_local_commits)" - assertEquals " 1$bash_up" "$(bash_color_local_commits)" + assertEquals " 1$up" "$(zsh_color_local_commits)" + assertEquals " 1$up" "$(bash_color_local_commits)" cd "$remote" echo "foo" > foo @@ -415,13 +411,13 @@ test_zsh_and_bash_local_commits() { cd "$repo" git fetch origin --quiet - assertEquals " 1${zsh_both}1" "$(zsh_color_local_commits)" - assertEquals " 1${bash_both}1" "$(bash_color_local_commits)" + assertEquals " 1${both}1" "$(zsh_color_local_commits)" + assertEquals " 1${both}1" "$(bash_color_local_commits)" git reset --hard HEAD^ --quiet - assertEquals " 1$zsh_down" "$(zsh_color_local_commits)" - assertEquals " 1$bash_down" "$(bash_color_local_commits)" + assertEquals " 1$down" "$(zsh_color_local_commits)" + assertEquals " 1$down" "$(bash_color_local_commits)" } . ./shunit/shunit2 -- cgit v1.2.3 From 0eab061edb10ab35438ca9a2ac0bc8c7aca85474 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 20:02:55 +0100 Subject: Add the new color tests in to the test run --- test | 1 + 1 file changed, 1 insertion(+) diff --git a/test b/test index 831e039..4efeafd 100755 --- a/test +++ b/test @@ -6,3 +6,4 @@ ./test-branches.sh ./test-files.sh ./test-status.sh +./test-colors.sh -- cgit v1.2.3 From 5241c9fa41efbc96f333a6e220d3dc0d1c6fa676 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Mon, 31 Aug 2015 00:12:39 +0100 Subject: Duplicate color tests for bash --- test-colors.sh | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) diff --git a/test-colors.sh b/test-colors.sh index 73aac53..d602c61 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -22,6 +22,28 @@ mock_zsh_colors() { reset_color=0 } +test_no_rcfile_bash() { + prepare_bash_colors + + assertEquals "$COLOR_REMOTE_AHEAD" "\x01\033[1;32m\x02" + assertEquals "$COLOR_REMOTE_BEHIND" "\x01\033[1;31m\x02" + assertEquals "$COLOR_REMOTE_DIVERGED" "\x01\033[1;33m\x02" + assertEquals "$COLOR_REMOTE_NOT_UPSTREAM" "\x01\033[1;31m\x02" + + assertEquals "$COLOR_LOCAL_AHEAD" "\x01\033[1;32m\x02" + assertEquals "$COLOR_LOCAL_BEHIND" "\x01\033[1;31m\x02" + assertEquals "$COLOR_LOCAL_DIVERGED" "\x01\033[1;33m\x02" + + assertEquals "$COLOR_CHANGES_STAGED" "\x01\033[1;32m\x02" + assertEquals "$COLOR_CHANGES_UNSTAGED" "\x01\033[1;31m\x02" + assertEquals "$COLOR_CHANGES_CONFLICTED" "\x01\033[1;33m\x02" + assertEquals "$COLOR_CHANGES_UNTRACKED" "\x01\033[1;37m\x02" + + assertEquals "$RESET_COLOR_LOCAL" "\x01\033[0m\x02" + assertEquals "$RESET_COLOR_REMOTE" "\x01\033[0m\x02" + assertEquals "$RESET_COLOR_CHANGES" "\x01\033[0m\x02" +} + test_no_rcfile_zsh() { mock_zsh_colors prepare_zsh_colors @@ -45,6 +67,26 @@ test_no_rcfile_zsh() { assertEquals "$RESET_COLOR_CHANGES" "%{$reset_color%}" } +set_bash_env_vars() { + export GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead" + export GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind" + export GIT_RADAR_COLOR_REMOTE_DIVERGED="remote-diverged" + export GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM="not-upstream" + + export GIT_RADAR_COLOR_LOCAL_AHEAD="local-ahead" + export GIT_RADAR_COLOR_LOCAL_BEHIND="local-behind" + export GIT_RADAR_COLOR_LOCAL_DIVERGED="local-diverged" + + export GIT_RADAR_COLOR_CHANGES_STAGED="changes-staged" + export GIT_RADAR_COLOR_CHANGES_UNSTAGED="changes-unstaged" + export GIT_RADAR_COLOR_CHANGES_CONFLICTED="changes-conflicted" + export GIT_RADAR_COLOR_CHANGES_UNTRACKED="changes-untracked" + + export GIT_RADAR_COLOR_LOCAL_RESET="local-reset" + export GIT_RADAR_COLOR_REMOTE_RESET="remote-reset" + export GIT_RADAR_COLOR_CHANGES_RESET="change-reset" +} + set_zsh_env_vars() { export GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead" export GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind" @@ -65,6 +107,29 @@ set_zsh_env_vars() { export GIT_RADAR_COLOR_CHANGES_RESET="change-reset" } +test_with_env_vars_bash() { + set_bash_env_vars + prepare_bash_colors + + assertEquals "$COLOR_REMOTE_AHEAD" "\x01remote-ahead\x02" + assertEquals "$COLOR_REMOTE_BEHIND" "\x01remote-behind\x02" + assertEquals "$COLOR_REMOTE_DIVERGED" "\x01remote-diverged\x02" + assertEquals "$COLOR_REMOTE_NOT_UPSTREAM" "\x01not-upstream\x02" + + assertEquals "$COLOR_LOCAL_AHEAD" "\x01local-ahead\x02" + assertEquals "$COLOR_LOCAL_BEHIND" "\x01local-behind\x02" + assertEquals "$COLOR_LOCAL_DIVERGED" "\x01local-diverged\x02" + + assertEquals "$COLOR_CHANGES_STAGED" "\x01changes-staged\x02" + assertEquals "$COLOR_CHANGES_UNSTAGED" "\x01changes-unstaged\x02" + assertEquals "$COLOR_CHANGES_CONFLICTED" "\x01changes-conflicted\x02" + assertEquals "$COLOR_CHANGES_UNTRACKED" "\x01changes-untracked\x02" + + assertEquals "$RESET_COLOR_LOCAL" "\x01local-reset\x02" + assertEquals "$RESET_COLOR_REMOTE" "\x01remote-reset\x02" + assertEquals "$RESET_COLOR_CHANGES" "\x01change-reset\x02" +} + test_with_env_vars_zsh() { set_zsh_env_vars mock_zsh_colors @@ -89,6 +154,48 @@ test_with_env_vars_zsh() { assertEquals "$RESET_COLOR_CHANGES" "%{change-reset%}" } +test_bash_colors_local() { + set_bash_env_vars + prepare_bash_colors + + cd_to_tmp "remote" + git init --bare --quiet + remoteLocation="$(pwd)" + + cd_to_tmp "repo" + git init --quiet + git remote add origin $remoteLocation + git fetch origin --quiet + git checkout -b master --quiet + touch README + git add README + git commit -m "initial commit" --quiet + git push --quiet -u origin master >/dev/null + repoLocation="$(pwd)" + + echo "foo" > foo + git add . + git commit -m "test commit" --quiet + + printf -v expected " 1\x01local-ahead\x02↑\x01local-reset\x02" + assertEquals "$expected" "$(bash_color_local_commits)" + + git push --quiet >/dev/null + git reset --hard head^ --quiet >/dev/null + + printf -v expected " 1\x01local-behind\x02↓\x01local-reset\x02" + assertEquals "$expected" "$(bash_color_local_commits)" + + echo "foo" > foo + git add . + git commit -m "new commit" --quiet + + printf -v expected " 1\x01local-diverged\x02⇵\x01local-reset\x021" + assertEquals "$expected" "$(bash_color_local_commits)" + + rm_tmp +} + test_zsh_colors_local() { set_zsh_env_vars prepare_zsh_colors @@ -128,6 +235,54 @@ test_zsh_colors_local() { rm_tmp } +test_bash_colors_remote() { + set_bash_env_vars + prepare_bash_colors + + cd_to_tmp "remote" + git init --bare --quiet + remoteLocation="$(pwd)" + + cd_to_tmp "repo" + git init --quiet + git remote add origin $remoteLocation + git fetch origin --quiet + git checkout -b master --quiet + touch README + git add README + git commit -m "initial commit" --quiet + echo "foo" > foo + git add . + git commit -m "test commit" --quiet + git push --quiet -u origin master >/dev/null + repoLocation="$(pwd)" + + git reset --hard head^ --quiet >/dev/null + 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 " + assertEquals "$expected" "$(bash_color_remote_commits)" + + echo "bar" > bar + git add . + git commit -m "new commit" --quiet + git push --quiet >/dev/null + + 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 " + assertEquals "$expected" "$(bash_color_remote_commits)" + + rm_tmp +} + test_zsh_colors_remote() { set_zsh_env_vars prepare_zsh_colors @@ -173,6 +328,26 @@ test_zsh_colors_remote() { rm_tmp } +test_bash_colors_changes() { + set_bash_env_vars + prepare_bash_colors + + cd_to_tmp + git init --quiet + + touch foo + touch bar + git add bar + echo "bar" > bar + untracked="1\x01changes-untracked\x02A\x01change-reset\x02" + unstaged="1\x01changes-unstaged\x02M\x01change-reset\x02" + staged="1\x01changes-staged\x02A\x01change-reset\x02" + + printf -v expected " $staged $unstaged $untracked" + assertEquals "$expected" "$(bash_color_changes_status)" + rm_tmp +} + test_zsh_colors_changes() { set_zsh_env_vars prepare_zsh_colors @@ -189,6 +364,7 @@ test_zsh_colors_changes() { staged="1%{changes-staged%}A%{change-reset%}" assertEquals " $staged $unstaged $untracked" "$(zsh_color_changes_status)" + rm_tmp } . ./shunit/shunit2 -- cgit v1.2.3 From 3c500ca9fe517710d75d6d09084fa7038dea39db Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Mon, 31 Aug 2015 00:46:29 +0100 Subject: Provide a way to set a .gitradarrc file --- radar-base.sh | 9 +++++ test-colors.sh | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/radar-base.sh b/radar-base.sh index 541b5e7..f707587 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -3,8 +3,13 @@ NO_REMOTE_STATUS='--no-remote-status' dot_git="" cwd="" remote="" +rcfile_path="$HOME" prepare_bash_colors() { + if [ -f "$rcfile_path/.gitradarrc" ]; then + source "$rcfile_path/.gitradarrc" + fi + COLOR_REMOTE_AHEAD="\x01${GIT_RADAR_COLOR_REMOTE_AHEAD:-"\\033[1;32m"}\x02" COLOR_REMOTE_BEHIND="\x01${GIT_RADAR_COLOR_REMOTE_BEHIND:-"\\033[1;31m"}\x02" COLOR_REMOTE_DIVERGED="\x01${GIT_RADAR_COLOR_REMOTE_DIVERGED:-"\\033[1;33m"}\x02" @@ -25,6 +30,10 @@ prepare_bash_colors() { } prepare_zsh_colors() { + if [ -f "$rcfile_path/.gitradarrc" ]; then + source "$rcfile_path/.gitradarrc" + fi + COLOR_REMOTE_AHEAD="%{${GIT_RADAR_COLOR_REMOTE_AHEAD:-$fg_bold[green]}%}" COLOR_REMOTE_BEHIND="%{${GIT_RADAR_COLOR_REMOTE_BEHIND:-$fg_bold[red]}%}" COLOR_REMOTE_DIVERGED="%{${GIT_RADAR_COLOR_REMOTE_DIVERGED:-$fg_bold[yellow]}%}" diff --git a/test-colors.sh b/test-colors.sh index d602c61..824e748 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -23,6 +23,7 @@ mock_zsh_colors() { } test_no_rcfile_bash() { + reset_env_vars prepare_bash_colors assertEquals "$COLOR_REMOTE_AHEAD" "\x01\033[1;32m\x02" @@ -45,6 +46,7 @@ test_no_rcfile_bash() { } test_no_rcfile_zsh() { + reset_env_vars mock_zsh_colors prepare_zsh_colors @@ -87,6 +89,26 @@ set_bash_env_vars() { export GIT_RADAR_COLOR_CHANGES_RESET="change-reset" } +reset_env_vars() { + export GIT_RADAR_COLOR_REMOTE_AHEAD="" + export GIT_RADAR_COLOR_REMOTE_BEHIND="" + export GIT_RADAR_COLOR_REMOTE_DIVERGED="" + export GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM="" + + export GIT_RADAR_COLOR_LOCAL_AHEAD="" + export GIT_RADAR_COLOR_LOCAL_BEHIND="" + export GIT_RADAR_COLOR_LOCAL_DIVERGED="" + + export GIT_RADAR_COLOR_CHANGES_STAGED="" + export GIT_RADAR_COLOR_CHANGES_UNSTAGED="" + export GIT_RADAR_COLOR_CHANGES_CONFLICTED="" + export GIT_RADAR_COLOR_CHANGES_UNTRACKED="" + + export GIT_RADAR_COLOR_LOCAL_RESET="" + export GIT_RADAR_COLOR_REMOTE_RESET="" + export GIT_RADAR_COLOR_CHANGES_RESET="" +} + set_zsh_env_vars() { export GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead" export GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind" @@ -107,7 +129,89 @@ set_zsh_env_vars() { export GIT_RADAR_COLOR_CHANGES_RESET="change-reset" } +create_rc_file() { + echo 'GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_REMOTE_DIVERGED="remote-diverged"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM="not-upstream"' >> .gitradarrc + + echo 'GIT_RADAR_COLOR_LOCAL_AHEAD="local-ahead"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_LOCAL_BEHIND="local-behind"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_LOCAL_DIVERGED="local-diverged"' >> .gitradarrc + + echo 'GIT_RADAR_COLOR_CHANGES_STAGED="changes-staged"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_CHANGES_UNSTAGED="changes-unstaged"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_CHANGES_CONFLICTED="changes-conflicted"' >> .gitradarrc + echo 'GIT_RADAR_COLOR_CHANGES_UNTRACKED="changes-untracked"' >> .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 +} + +test_with_rcfile_bash() { + reset_env_vars + cd_to_tmp + + rcfile_path="$(pwd)" + + create_rc_file + prepare_bash_colors + + assertEquals "$COLOR_REMOTE_AHEAD" "\x01remote-ahead\x02" + assertEquals "$COLOR_REMOTE_BEHIND" "\x01remote-behind\x02" + assertEquals "$COLOR_REMOTE_DIVERGED" "\x01remote-diverged\x02" + assertEquals "$COLOR_REMOTE_NOT_UPSTREAM" "\x01not-upstream\x02" + + assertEquals "$COLOR_LOCAL_AHEAD" "\x01local-ahead\x02" + assertEquals "$COLOR_LOCAL_BEHIND" "\x01local-behind\x02" + assertEquals "$COLOR_LOCAL_DIVERGED" "\x01local-diverged\x02" + + assertEquals "$COLOR_CHANGES_STAGED" "\x01changes-staged\x02" + assertEquals "$COLOR_CHANGES_UNSTAGED" "\x01changes-unstaged\x02" + assertEquals "$COLOR_CHANGES_CONFLICTED" "\x01changes-conflicted\x02" + assertEquals "$COLOR_CHANGES_UNTRACKED" "\x01changes-untracked\x02" + + assertEquals "$RESET_COLOR_LOCAL" "\x01local-reset\x02" + assertEquals "$RESET_COLOR_REMOTE" "\x01remote-reset\x02" + assertEquals "$RESET_COLOR_CHANGES" "\x01change-reset\x02" + + rm_tmp +} + +test_with_rcfile_zsh() { + reset_env_vars + cd_to_tmp + + rcfile_path="$(pwd)" + + create_rc_file + mock_zsh_colors + prepare_zsh_colors + + assertEquals "$COLOR_REMOTE_AHEAD" "%{remote-ahead%}" + assertEquals "$COLOR_REMOTE_BEHIND" "%{remote-behind%}" + assertEquals "$COLOR_REMOTE_DIVERGED" "%{remote-diverged%}" + assertEquals "$COLOR_REMOTE_NOT_UPSTREAM" "%{not-upstream%}" + + assertEquals "$COLOR_LOCAL_AHEAD" "%{local-ahead%}" + assertEquals "$COLOR_LOCAL_BEHIND" "%{local-behind%}" + assertEquals "$COLOR_LOCAL_DIVERGED" "%{local-diverged%}" + + assertEquals "$COLOR_CHANGES_STAGED" "%{changes-staged%}" + assertEquals "$COLOR_CHANGES_UNSTAGED" "%{changes-unstaged%}" + assertEquals "$COLOR_CHANGES_CONFLICTED" "%{changes-conflicted%}" + assertEquals "$COLOR_CHANGES_UNTRACKED" "%{changes-untracked%}" + + assertEquals "$RESET_COLOR_LOCAL" "%{local-reset%}" + assertEquals "$RESET_COLOR_REMOTE" "%{remote-reset%}" + assertEquals "$RESET_COLOR_CHANGES" "%{change-reset%}" + + rm_tmp +} + test_with_env_vars_bash() { + reset_env_vars set_bash_env_vars prepare_bash_colors @@ -131,6 +235,7 @@ test_with_env_vars_bash() { } test_with_env_vars_zsh() { + reset_env_vars set_zsh_env_vars mock_zsh_colors prepare_zsh_colors @@ -155,6 +260,7 @@ test_with_env_vars_zsh() { } test_bash_colors_local() { + reset_env_vars set_bash_env_vars prepare_bash_colors @@ -197,6 +303,7 @@ test_bash_colors_local() { } test_zsh_colors_local() { + reset_env_vars set_zsh_env_vars prepare_zsh_colors @@ -236,6 +343,7 @@ test_zsh_colors_local() { } test_bash_colors_remote() { + reset_env_vars set_bash_env_vars prepare_bash_colors @@ -284,6 +392,7 @@ test_bash_colors_remote() { } test_zsh_colors_remote() { + reset_env_vars set_zsh_env_vars prepare_zsh_colors @@ -329,6 +438,7 @@ test_zsh_colors_remote() { } test_bash_colors_changes() { + reset_env_vars set_bash_env_vars prepare_bash_colors @@ -349,6 +459,7 @@ test_bash_colors_changes() { } test_zsh_colors_changes() { + reset_env_vars set_zsh_env_vars prepare_zsh_colors -- cgit v1.2.3 From 3a0ae9dbded9ebf1366f2580f1cbff6de1fc2340 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Mon, 31 Aug 2015 00:56:53 +0100 Subject: Remove unneeded zsh specific env var setup --- test-colors.sh | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/test-colors.sh b/test-colors.sh index 824e748..0506145 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -69,7 +69,7 @@ test_no_rcfile_zsh() { assertEquals "$RESET_COLOR_CHANGES" "%{$reset_color%}" } -set_bash_env_vars() { +set_env_vars() { export GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead" export GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind" export GIT_RADAR_COLOR_REMOTE_DIVERGED="remote-diverged" @@ -109,26 +109,6 @@ reset_env_vars() { export GIT_RADAR_COLOR_CHANGES_RESET="" } -set_zsh_env_vars() { - export GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead" - export GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind" - export GIT_RADAR_COLOR_REMOTE_DIVERGED="remote-diverged" - export GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM="not-upstream" - - export GIT_RADAR_COLOR_LOCAL_AHEAD="local-ahead" - export GIT_RADAR_COLOR_LOCAL_BEHIND="local-behind" - export GIT_RADAR_COLOR_LOCAL_DIVERGED="local-diverged" - - export GIT_RADAR_COLOR_CHANGES_STAGED="changes-staged" - export GIT_RADAR_COLOR_CHANGES_UNSTAGED="changes-unstaged" - export GIT_RADAR_COLOR_CHANGES_CONFLICTED="changes-conflicted" - export GIT_RADAR_COLOR_CHANGES_UNTRACKED="changes-untracked" - - export GIT_RADAR_COLOR_LOCAL_RESET="local-reset" - export GIT_RADAR_COLOR_REMOTE_RESET="remote-reset" - export GIT_RADAR_COLOR_CHANGES_RESET="change-reset" -} - create_rc_file() { echo 'GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead"' >> .gitradarrc echo 'GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind"' >> .gitradarrc @@ -212,7 +192,7 @@ test_with_rcfile_zsh() { test_with_env_vars_bash() { reset_env_vars - set_bash_env_vars + set_env_vars prepare_bash_colors assertEquals "$COLOR_REMOTE_AHEAD" "\x01remote-ahead\x02" @@ -236,7 +216,7 @@ test_with_env_vars_bash() { test_with_env_vars_zsh() { reset_env_vars - set_zsh_env_vars + set_env_vars mock_zsh_colors prepare_zsh_colors @@ -261,7 +241,7 @@ test_with_env_vars_zsh() { test_bash_colors_local() { reset_env_vars - set_bash_env_vars + set_env_vars prepare_bash_colors cd_to_tmp "remote" @@ -304,7 +284,7 @@ test_bash_colors_local() { test_zsh_colors_local() { reset_env_vars - set_zsh_env_vars + set_env_vars prepare_zsh_colors cd_to_tmp "remote" @@ -344,7 +324,7 @@ test_zsh_colors_local() { test_bash_colors_remote() { reset_env_vars - set_bash_env_vars + set_env_vars prepare_bash_colors cd_to_tmp "remote" @@ -393,7 +373,7 @@ test_bash_colors_remote() { test_zsh_colors_remote() { reset_env_vars - set_zsh_env_vars + set_env_vars prepare_zsh_colors cd_to_tmp "remote" @@ -439,7 +419,7 @@ test_zsh_colors_remote() { test_bash_colors_changes() { reset_env_vars - set_bash_env_vars + set_env_vars prepare_bash_colors cd_to_tmp @@ -460,7 +440,7 @@ test_bash_colors_changes() { test_zsh_colors_changes() { reset_env_vars - set_zsh_env_vars + set_env_vars prepare_zsh_colors cd_to_tmp -- cgit v1.2.3 From 1342bd1e5fbef270db72f302bd6c380a7fec29ac Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Tue, 1 Sep 2015 13:40:03 +0100 Subject: Make branch color and master symbol configurable --- radar-base.sh | 26 +++++++++++++++++--------- 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 } -- cgit v1.2.3 From 393013fba5bc7ec3402de4c1b2faf47dd7493c59 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 2 Sep 2015 17:42:17 +0100 Subject: Allow for shell specific rc files --- radar-base.sh | 8 ++++++-- test-colors.sh | 46 +++++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 5672e07..25a4113 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -6,7 +6,9 @@ remote="" rcfile_path="$HOME" prepare_bash_colors() { - if [ -f "$rcfile_path/.gitradarrc" ]; then + if [ -f "$rcfile_path/.gitradarrc.bash" ]; then + source "$rcfile_path/.gitradarrc.bash" + elif [ -f "$rcfile_path/.gitradarrc" ]; then source "$rcfile_path/.gitradarrc" fi @@ -34,7 +36,9 @@ prepare_bash_colors() { } prepare_zsh_colors() { - if [ -f "$rcfile_path/.gitradarrc" ]; then + if [ -f "$rcfile_path/.gitradarrc.zsh" ]; then + source "$rcfile_path/.gitradarrc.zsh" + elif [ -f "$rcfile_path/.gitradarrc" ]; then source "$rcfile_path/.gitradarrc" fi diff --git a/test-colors.sh b/test-colors.sh index 196b60b..59a8704 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -118,27 +118,27 @@ reset_env_vars() { } create_rc_file() { - echo 'GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead"' >> .gitradarrc - echo 'GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind"' >> .gitradarrc - echo 'GIT_RADAR_COLOR_REMOTE_DIVERGED="remote-diverged"' >> .gitradarrc - echo 'GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM="not-upstream"' >> .gitradarrc - - echo 'GIT_RADAR_COLOR_LOCAL_AHEAD="local-ahead"' >> .gitradarrc - echo 'GIT_RADAR_COLOR_LOCAL_BEHIND="local-behind"' >> .gitradarrc - echo 'GIT_RADAR_COLOR_LOCAL_DIVERGED="local-diverged"' >> .gitradarrc - - echo 'GIT_RADAR_COLOR_CHANGES_STAGED="changes-staged"' >> .gitradarrc - echo 'GIT_RADAR_COLOR_CHANGES_UNSTAGED="changes-unstaged"' >> .gitradarrc - 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 + echo 'GIT_RADAR_COLOR_REMOTE_AHEAD="remote-ahead"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_REMOTE_BEHIND="remote-behind"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_REMOTE_DIVERGED="remote-diverged"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM="not-upstream"' >> .gitradarrc$1 + + echo 'GIT_RADAR_COLOR_LOCAL_AHEAD="local-ahead"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_LOCAL_BEHIND="local-behind"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_LOCAL_DIVERGED="local-diverged"' >> .gitradarrc$1 + + echo 'GIT_RADAR_COLOR_CHANGES_STAGED="changes-staged"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_CHANGES_UNSTAGED="changes-unstaged"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_CHANGES_CONFLICTED="changes-conflicted"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_CHANGES_UNTRACKED="changes-untracked"' >> .gitradarrc$1 + + echo 'export GIT_RADAR_COLOR_BRANCH="branch-color"' >> .gitradarrc$1 + echo 'export GIT_RADAR_MASTER_SYMBOL="m"' >> .gitradarrc$1 + + echo 'GIT_RADAR_COLOR_LOCAL_RESET="local-reset"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_REMOTE_RESET="remote-reset"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_CHANGES_RESET="change-reset"' >> .gitradarrc$1 + echo 'GIT_RADAR_COLOR_BRANCH_RESET="branch-reset"' >> .gitradarrc$1 } test_with_rcfile_bash() { @@ -147,7 +147,7 @@ test_with_rcfile_bash() { rcfile_path="$(pwd)" - create_rc_file + create_rc_file ".bash" prepare_bash_colors assertEquals "$COLOR_REMOTE_AHEAD" "\x01remote-ahead\x02" @@ -181,7 +181,7 @@ test_with_rcfile_zsh() { rcfile_path="$(pwd)" - create_rc_file + create_rc_file ".zsh" mock_zsh_colors prepare_zsh_colors -- cgit v1.2.3 From 243f66edda3816576b52f9193083f59bd7c65331 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 4 Sep 2015 12:29:18 +0100 Subject: Readme to describe the colour config --- README.md | 268 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) diff --git a/README.md b/README.md index 145f02b..60dbad0 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,19 @@ Git-radar is a tool you can add to your prompt to provide at-a-glance information on your git repo. It's a labour of love I've been dogfooding for the last few years. Maybe it can help you too. +**Table of Contents** + +- [Installation](#installation) +- [Usage](#usage) +- [Features](#features) + - [Files status](#files-status) + - [Local commits status](#local-commits-status) + - [Remote commits status](#remote-commits-status) + - [(Optional) Auto-fetch repos](#optional-auto-fetch-repos) +- [Support](#support) + - [Ensuring prompt execution](#ensuring-prompt-execution) +- [License](#license) + ## Installation Install from brew: @@ -174,6 +187,261 @@ export PROMPT="\$(git-radar --zsh)" export PS1="\$(git-radar --bash)" ``` +### Configuring colours + +You can configure the colour scheme in two ways: export +[Environment Variables](#exporting-environment-variables) +or use an [rc file](#setting-an-rc-file). + +#### Exporting Environment Variables + +To configure the prompt this way just add to your `~/.bashrc` or `~/.zshrc` an +export directive with the value you want to change. + +**Example: Change the branch colour in Zsh** + +In `~/.zshrc`: +```zsh +export GIT_RADAR_COLOR_BRANCH='$fg[yellow]' +``` + +**Example: Change the branch colour in Bash** + +In `~/.bashrc`: +```zsh +export GIT_RADAR_COLOR_BRANCH='\\033[0;33m' +``` + +#### Setting an RC file + +Git radar supports multiple rc files. One of these will be sourced when the +prompt renders. + +**Example: Change the branch colour in Zsh** + +In `~/.gitradarrc`: +```zsh +GIT_RADAR_COLOR_BRANCH='$fg[yellow]' +``` + +**Basic RC file** + +Create a file at `~/.gitradarrc` which sets the Environment variables listed in +[Configuration values](#configuration-values) using colour codes listed in +either [Zsh Colour Codes](#zsh-colour-codes) or +[Bash Colour Codes](#Bash-Colour-Codes) depending on your shell. + +**Shell specific RC file** + +If you use both Bash and Zsh you can set RC files that are specific for those +shells. + +For Bash: Create a file at `~/.gitradarrc.bash` + +For Zsh: Create a file at `~/.gitradarrc.zsh` + + +#### Bash Colour Codes + +Bash colour codes make use of the colours your terminal app claims to be `red` +or `green`. Using one of these codes will only produce the colour your terminal +claims, so you should customise your colour scheme on your terminal as well as +customising git-radar. + +Note the "Bright" colours can be shown as bold instead, it depends on your +terminal. By default, for example, the Mac OSX Terminal.app uses the "Bright" +colours to provide 8 new lighter colours but some terminals only support 8 and +will show the text as bold instead. + +Colour | Code for Text | Code for Background +--------------|----------------|-------------------- +Black | `\\033[0;30m` | `\\033[0;40m` +Red | `\\033[0;31m` | `\\033[0;41m` +Green | `\\033[0;32m` | `\\033[0;42m` +Yellow | `\\033[0;33m` | `\\033[0;43m` +Blue | `\\033[0;34m` | `\\033[0;44m` +Magenta | `\\033[0;35m` | `\\033[0;45m` +Cyan | `\\033[0;36m` | `\\033[0;46m` +White | `\\033[0;37m` | `\\033[0;47m` +Bright Black | `\\033[1;30m` | `\\033[1;40m` +Bright Red | `\\033[1;31m` | `\\033[1;41m` +Bright Green | `\\033[1;32m` | `\\033[1;42m` +Bright Yellow | `\\033[1;33m` | `\\033[1;43m` +Bright Blue | `\\033[1;34m` | `\\033[1;44m` +Bright Magenta| `\\033[1;35m` | `\\033[1;45m` +Bright Cyan | `\\033[1;36m` | `\\033[1;46m` +Bright White | `\\033[1;37m` | `\\033[1;47m` +Reset | `\\033[0m` | `\\033[0m` + +Note the Reset will set back to what your terminal claims as standard text and +background. + +#### Zsh Colour Codes + +Zsh also provides a way to access the colours that your terminal claims as `red` +or `green`, etc. + +Note the "Bright" colours can be shown as bold instead, it depends on your +terminal. By default, for example, the Mac OSX Terminal.app uses the "Bright" +colours to provide 8 new lighter colours but some terminals only support 8 and +will show the text as bold instead. + +Colour | Code for Text | Code for Background +--------------|--------------------|-------------------- +Black | `$fg[black]` | `$bg[black]` +Red | `$fg[red]` | `$bg[red]` +Green | `$fg[green]` | `$bg[green]` +Yellow | `$fg[yellow]` | `$bg[yellow]` +Blue | `$fg[blue]` | `$bg[blue]` +Magenta | `$fg[magenta]` | `$bg[magenta]` +Cyan | `$fg[cyan]` | `$bg[cyan]` +White | `$fg[white]` | `$bg[white]` +Bright Black | `$fg_bold[black]` | `$bg_bold[black]` +Bright Red | `$fg_bold[red]` | `$bg_bold[red]` +Bright Green | `$fg_bold[green]` | `$bg_bold[green]` +Bright Yellow | `$fg_bold[yellow]` | `$bg_bold[yellow]` +Bright Blue | `$fg_bold[blue]` | `$bg_bold[blue]` +Bright Magenta| `$fg_bold[magenta]`| `$bg_bold[magenta]` +Bright Cyan | `$fg_bold[cyan]` | `$bg_bold[cyan]` +Bright White | `$fg_bold[white]` | `$bg_bold[white]` +Reset | `$reset_color` | `$reset_color` + +#### Configuration values + +All these values should be set using a the correct colour code for your +terminal. You should also choose the colour code based on what shell you are +using. There is a way to support [colouring multiple shells using rc files](#setting-an-rc-file). + +**GIT_RADAR_COLOR_BRANCH='[colour code]'** +``` +git:(my-branch) + ^^^^^^^^^ +``` +The colour to use for the Branch or git reference. + +It is unset by +`GIT_RADAR_COLOR_BRANCH_RESET` which you can set if you want a different +background colour to return to. + +**GIT_RADAR_COLOR_LOCAL_AHEAD='[colour code]'** +``` +git:(my-branch 1↑) + ^ +``` +The colour to use for the arrow that indicates how many commits you have to push +up. + +It is unset by `GIT_RADAR_COLOR_LOCAL_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_LOCAL_BEHIND='[colour code]'** +``` +git:(my-branch 1↓) + ^ +``` +The colour to use for the arrow that indicates how many commits you have to pull +down. + +It is unset by `GIT_RADAR_COLOR_LOCAL_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_LOCAL_DIVERGED='[colour code]'** +``` +git:(my-branch 1⇵1) + ^ +``` +The colour to use for the arrow that indicates how many commits your branch has diverged by. + +It is unset by `GIT_RADAR_COLOR_LOCAL_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_REMOTE_AHEAD='[colour code]'** +``` +git:(m ← 1 my-branch) + ^ +``` +The colour to use for the arrow that indicates how many commits your branch has to merge on to master. + +It is unset by `GIT_RADAR_COLOR_REMOTE_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_REMOTE_BEHIND='[colour code]'** +``` +git:(m 1 → my-branch) + ^ +``` +The colour to use for the arrow that indicates how many commits your branch is +behind master. + +It is unset by `GIT_RADAR_COLOR_REMOTE_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_REMOTE_DIVERGED='[colour code]'** +``` +git:(m 1 ⇄ 1 my-branch) + ^ +``` +The colour to use for the arrow that indicates how many commits your branch has +diverged from master. + +It is unset by `GIT_RADAR_COLOR_REMOTE_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM='[colour code]'** +``` +git:(upstream ⚡ my-branch) + ^ +``` +The colour to use for the lightning bolt which indicates that your branch is not +tracking an upstream branch. + +It is unset by `GIT_RADAR_COLOR_REMOTE_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_CHANGES_STAGED='[colour code]'** +``` +git:(my-branch) 1M + ^ +``` +The colour to use for the letters that indicate changes that have been staged to +commit. + +It is unset by `GIT_RADAR_COLOR_CHANGES_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_CHANGES_UNSTAGED='[colour code]'** +``` +git:(my-branch) 1M + ^ +``` +The colour to use for the letters that indicate changes that have not yet been +staged to commit. + +It is unset by `GIT_RADAR_COLOR_CHANGES_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_CHANGES_CONFLICTED='[colour code]'** +``` +git:(my-branch) 1B + ^ +``` +The colour to use for the letters that indicate changes that have conflicts that +need resolved. + +It is unset by `GIT_RADAR_COLOR_CHANGES_RESET` which you can set if you want +a different background colour to return to. + +**GIT_RADAR_COLOR_CHANGES_UNTRACKED='[colour code]'** +``` +git:(my-branch) 1A + ^ +``` +The colour to use for the letters that indicate files that are currently not +tracked by git. + +It is unset by `GIT_RADAR_COLOR_CHANGES_RESET` which you can set if you want +a different background colour to return to. + ## License Git Radar is licensed under the MIT license. -- cgit v1.2.3