summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md268
-rwxr-xr-xprompt.bash1
-rwxr-xr-xprompt.zsh2
-rwxr-xr-xradar-base.sh135
-rwxr-xr-xtest1
-rwxr-xr-xtest-colors.sh485
-rwxr-xr-xtest-commits.sh24
7 files changed, 859 insertions, 57 deletions
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.
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/prompt.zsh b/prompt.zsh
index a5ccba5..e996b77 100755
--- a/prompt.zsh
+++ b/prompt.zsh
@@ -6,6 +6,8 @@ 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 d019629..25a4113 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -3,6 +3,69 @@ NO_REMOTE_STATUS='--no-remote-status'
dot_git=""
cwd=""
remote=""
+rcfile_path="$HOME"
+
+prepare_bash_colors() {
+ if [ -f "$rcfile_path/.gitradarrc.bash" ]; then
+ source "$rcfile_path/.gitradarrc.bash"
+ elif [ -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"
+ 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"
+
+ 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() {
+ if [ -f "$rcfile_path/.gitradarrc.zsh" ]; then
+ source "$rcfile_path/.gitradarrc.zsh"
+ elif [ -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]}%}"
+ 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_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]}%}"
+
+ 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() {
local wd="$(pwd)"
@@ -119,7 +182,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
}
@@ -307,16 +370,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_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
@@ -345,16 +402,10 @@ 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_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_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
@@ -379,9 +430,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
@@ -402,9 +453,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="${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
@@ -423,22 +474,21 @@ 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")"
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 "
@@ -448,22 +498,21 @@ 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="%{$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="${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")"
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 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
diff --git a/test-colors.sh b/test-colors.sh
new file mode 100755
index 0000000..59a8704
--- /dev/null
+++ b/test-colors.sh
@@ -0,0 +1,485 @@
+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_bash() {
+ reset_env_vars
+ 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() {
+ reset_env_vars
+ 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%}"
+}
+
+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"
+ 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_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() {
+ 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_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() {
+ 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() {
+ reset_env_vars
+ cd_to_tmp
+
+ rcfile_path="$(pwd)"
+
+ create_rc_file ".bash"
+ 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 "$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
+}
+
+test_with_rcfile_zsh() {
+ reset_env_vars
+ cd_to_tmp
+
+ rcfile_path="$(pwd)"
+
+ create_rc_file ".zsh"
+ 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 "$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
+}
+
+test_with_env_vars_bash() {
+ reset_env_vars
+ set_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 "$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() {
+ reset_env_vars
+ set_env_vars
+ 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 "$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() {
+ reset_env_vars
+ set_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() {
+ reset_env_vars
+ set_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
+}
+
+test_bash_colors_remote() {
+ reset_env_vars
+ set_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 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() {
+ reset_env_vars
+ set_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
+
+ 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
+}
+
+test_bash_colors_changes() {
+ reset_env_vars
+ set_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() {
+ reset_env_vars
+ set_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)"
+ rm_tmp
+}
+
+. ./shunit/shunit2
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