From 637b5d5534469ebb15826139e1b3df12a1cc9309 Mon Sep 17 00:00:00 2001 From: Reinaldo Colina Date: Thu, 27 Aug 2015 12:14:13 -0700 Subject: issue-17: Add arguments to make the prompt shorter --- README.md | 28 ++++++++++++++++++++++++++++ git-radar | 5 +++-- prompt.bash | 11 +++++++++-- radar-base.sh | 17 +++++++++++++++++ test | 1 + test-radar-base.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 4 deletions(-) create mode 100755 test-radar-base.sh diff --git a/README.md b/README.md index d4bd3dd..f126a21 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,19 @@ Prompt | Meaning ![git:(m 4 → my-branch)] | There are 4 commits on `origin/master` that aren't on `origin/my-branch` ![git:(m 1 ⇄ 2 my-branch)] | `origin/master` and `origin/my-branch` have diverged, we'll need to rebase or merge +If you don't rely on this status, you can always hide this part of the prompt by calling git-radar with `--no-remote-status`. + +**Bash** +```bash +export PS1="$PS1\$(git-radar --bash --fetch --no-remote-status) " +``` +(note: the `\` escaping the `$` is important) + +**Zsh** +```zsh +export PROMPT="$PROMPT$(git-radar --zsh --fetch --no-remote-status) " +``` + ### (Optional) Auto-fetch repos Ensuring your refs are up to date I found can be a pain. To streamline this @@ -124,6 +137,21 @@ export PS1="$PS1\$(git-radar --bash --fetch)" export PROMPT="$PROMPT$(git-radar --zsh --fetch) " ``` +### (Optional) Minimal mode + +If you wish to keep the length of your prompt shorter, you can call git-radar with `--minimal` which will render the new prompt without the `git:` part + +**Bash** +```bash +export PS1="$PS1\$(git-radar --bash --fetch --minimal) " +``` +(note: the `\` escaping the `$` is important) + +**Zsh** +```zsh +export PROMPT="$PROMPT$(git-radar --zsh --fetch --minimal) " +``` + ## License Git Radar is licensed under the MIT license. diff --git a/git-radar b/git-radar index a5cd3c1..67b8460 100755 --- a/git-radar +++ b/git-radar @@ -11,6 +11,7 @@ else fi dot="$(cd "$(dirname "$([ -L "$0" ] && $READLINK_CMD -f "$0" || echo "$0")")"; pwd)" +args=$@ if [[ -z $@ ]]; then _git="\033[1;30mgit:(\033[0m" @@ -92,9 +93,9 @@ while [[ $# > 0 ]];do nohup $dot/fetch.sh >/dev/null 2>&1 & fi if [[ "$command" == "--zsh" ]]; then - $dot/prompt.zsh + $dot/prompt.zsh $args fi if [[ "$command" == "--bash" || "$command" == "--fish" ]]; then - $dot/prompt.bash + $dot/prompt.bash $args fi done diff --git a/prompt.bash b/prompt.bash index a3fe420..1e79cd9 100755 --- a/prompt.bash +++ b/prompt.bash @@ -1,11 +1,18 @@ #! /usr/bin/env bash dot="$(cd "$(dirname "$0")"; pwd)" +git_label="" +args=$@ source "$dot/radar-base.sh" if is_repo; then - printf " \x01\033[1;30m\x02git:(\x01\033[0m\x02" - bash_color_remote_commits + if show_git_label $args; then + git_label="git:" + fi + printf " \x01\033[1;30m\x02$git_label(\x01\033[0m\x02" + if show_remote_status $args; then + bash_color_remote_commits + fi readable_branch_name bash_color_local_commits printf "\x01\033[1;30m\x02)\x01\033[0m\x02" diff --git a/radar-base.sh b/radar-base.sh index b7074d8..a2f5115 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -1,3 +1,6 @@ +IS_MINIMAL='--minimal' +NO_REMOTE_STATUS='--no-remote-status' + dot_git="" cwd="" remote="" @@ -469,3 +472,17 @@ zsh_color_remote_commits() { printf %s "$remote" } + +show_git_label() { + if [[ $@ == *$IS_MINIMAL* ]]; then + return 1 # don't show the git label + fi + return 0 +} + +show_remote_status() { + if [[ $@ == *$NO_REMOTE_STATUS* ]]; then + return 1 # don't show the git remote status + fi + return 0 +} diff --git a/test b/test index a6a8775..831e039 100755 --- a/test +++ b/test @@ -1,5 +1,6 @@ #!/bin/sh +./test-radar-base.sh ./test-directories.sh ./test-commits.sh ./test-branches.sh diff --git a/test-radar-base.sh b/test-radar-base.sh new file mode 100755 index 0000000..ca95136 --- /dev/null +++ b/test-radar-base.sh @@ -0,0 +1,51 @@ +scriptDir="$(cd "$(dirname "$0")"; pwd)" + +source "$scriptDir/radar-base.sh" + +test_show_git_label() { + show_git_label + assertTrue $? + + show_git_label --bash + assertTrue $? + + show_git_label --bash --fetch + assertTrue $? + + show_git_label --bash --minimal --fetch + assertFalse $? + + show_git_label --bash --fetch --minimal + assertFalse $? + + show_git_label --minimal --bash --fetch + assertFalse $? + + show_git_label --bash --fetch --minimal --no-remote-status + assertFalse $? +} + +test_show_remote_status() { + show_remote_status + assertTrue $? + + show_remote_status --bash + assertTrue $? + + show_remote_status --bash --fetch + assertTrue $? + + show_remote_status --bash --no-remote-status --fetch + assertFalse $? + + show_remote_status --bash --fetch --no-remote-status + assertFalse $? + + show_remote_status --no-remote-status --bash --fetch + assertFalse $? + + show_remote_status --bash --fetch --minimal --no-remote-status + assertFalse $? +} + +. ./shunit/shunit2 \ No newline at end of file -- cgit v1.2.3 From 93dad96832a59d3d7f6ac6580cabf0202b387ffe Mon Sep 17 00:00:00 2001 From: Reinaldo Colina Date: Fri, 28 Aug 2015 13:55:37 -0700 Subject: Removing --minimal arg implementation - Dealing with the git: prefix will be done in a separate pull request - The new --no-remote-status arg remains --- README.md | 15 --------------- prompt.bash | 6 +----- radar-base.sh | 9 --------- test-radar-base.sh | 23 ----------------------- 4 files changed, 1 insertion(+), 52 deletions(-) diff --git a/README.md b/README.md index f126a21..b9268ee 100644 --- a/README.md +++ b/README.md @@ -137,21 +137,6 @@ export PS1="$PS1\$(git-radar --bash --fetch)" export PROMPT="$PROMPT$(git-radar --zsh --fetch) " ``` -### (Optional) Minimal mode - -If you wish to keep the length of your prompt shorter, you can call git-radar with `--minimal` which will render the new prompt without the `git:` part - -**Bash** -```bash -export PS1="$PS1\$(git-radar --bash --fetch --minimal) " -``` -(note: the `\` escaping the `$` is important) - -**Zsh** -```zsh -export PROMPT="$PROMPT$(git-radar --zsh --fetch --minimal) " -``` - ## License Git Radar is licensed under the MIT license. diff --git a/prompt.bash b/prompt.bash index 1e79cd9..429c88d 100755 --- a/prompt.bash +++ b/prompt.bash @@ -1,15 +1,11 @@ #! /usr/bin/env bash dot="$(cd "$(dirname "$0")"; pwd)" -git_label="" args=$@ source "$dot/radar-base.sh" if is_repo; then - if show_git_label $args; then - git_label="git:" - fi - printf " \x01\033[1;30m\x02$git_label(\x01\033[0m\x02" + printf " \x01\033[1;30m\x02git:(\x01\033[0m\x02" if show_remote_status $args; then bash_color_remote_commits fi diff --git a/radar-base.sh b/radar-base.sh index a2f5115..d019629 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -1,4 +1,3 @@ -IS_MINIMAL='--minimal' NO_REMOTE_STATUS='--no-remote-status' dot_git="" @@ -472,14 +471,6 @@ zsh_color_remote_commits() { printf %s "$remote" } - -show_git_label() { - if [[ $@ == *$IS_MINIMAL* ]]; then - return 1 # don't show the git label - fi - return 0 -} - show_remote_status() { if [[ $@ == *$NO_REMOTE_STATUS* ]]; then return 1 # don't show the git remote status diff --git a/test-radar-base.sh b/test-radar-base.sh index ca95136..9f7f8ee 100755 --- a/test-radar-base.sh +++ b/test-radar-base.sh @@ -2,29 +2,6 @@ scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" -test_show_git_label() { - show_git_label - assertTrue $? - - show_git_label --bash - assertTrue $? - - show_git_label --bash --fetch - assertTrue $? - - show_git_label --bash --minimal --fetch - assertFalse $? - - show_git_label --bash --fetch --minimal - assertFalse $? - - show_git_label --minimal --bash --fetch - assertFalse $? - - show_git_label --bash --fetch --minimal --no-remote-status - assertFalse $? -} - test_show_remote_status() { show_remote_status assertTrue $? -- cgit v1.2.3 From c03a462177bc2ec469a0cdb06234d08f35054966 Mon Sep 17 00:00:00 2001 From: Reinaldo Colina Date: Fri, 28 Aug 2015 20:23:06 -0700 Subject: Added change for issue-17 to prompt.zsh as well --- prompt.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prompt.zsh b/prompt.zsh index cb1eb91..a5ccba5 100755 --- a/prompt.zsh +++ b/prompt.zsh @@ -1,12 +1,15 @@ #! /usr/bin/env zsh dot="$(cd "$(dirname "$0")"; pwd)" +args=$@ source "$dot/radar-base.sh" if is_repo; then autoload colors && colors printf '%s' "%{$fg_bold[black]%} git:(%{$reset_color%}" - zsh_color_remote_commits + if show_remote_status $args; then + zsh_color_remote_commits + fi readable_branch_name zsh_color_local_commits printf '%s' "%{$fg_bold[black]%})%{$reset_color%}" -- cgit v1.2.3 From 049dfa2146ea28b426d80600b0172e8b8405cd2d Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sun, 30 Aug 2015 12:06:45 +0100 Subject: Describe how to ensure proper execution of the prompt --- README.md | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 61ae983..145f02b 100644 --- a/README.md +++ b/README.md @@ -29,16 +29,17 @@ Add to your `.bashrc` ```bash export PS1="$PS1\$(git-radar --bash --fetch)" ``` -(note: the `\` escaping the `$` is important) +[(note: the `\` escaping the `$` is important)](#ensuring-prompt-execution) **Zsh** Add to your `.zshrc` ```zsh -export PROMPT="$PROMPT$(git-radar --zsh --fetch) " +export PROMPT="$PROMPT\$(git-radar --zsh --fetch) " ``` +[(note: the `\` escaping the `$` is important)](#ensuring-prompt-execution) -**fish** +**Fish** Add to your `config.fish` ```bash @@ -121,12 +122,13 @@ If you don't rely on this status, you can always hide this part of the prompt by ```bash export PS1="$PS1\$(git-radar --bash --fetch --no-remote-status) " ``` -(note: the `\` escaping the `$` is important) +[(note: the `\` escaping the `$` is important)](#ensuring-prompt-execution) **Zsh** ```zsh -export PROMPT="$PROMPT$(git-radar --zsh --fetch --no-remote-status) " +export PROMPT="$PROMPT\$(git-radar --zsh --fetch --no-remote-status) " ``` +[(note: the `\` escaping the `$` is important)](#ensuring-prompt-execution) ### (Optional) Auto-fetch repos @@ -143,11 +145,33 @@ To use this feature, when setting your prompt, call git-radar with `--fetch`: ```bash export PS1="$PS1\$(git-radar --bash --fetch)" ``` -(note: the `\` escaping the `$` is important) +[(note: the `\` escaping the `$` is important)](#ensuring-prompt-execution) **Zsh** ```zsh -export PROMPT="$PROMPT$(git-radar --zsh --fetch) " +export PROMPT="$PROMPT\$(git-radar --zsh --fetch) " +``` +[(note: the `\` escaping the `$` is important)](#ensuring-prompt-execution) + +## Support + +### Ensuring prompt execution + +When setting your prompt variable, `PROMPT` in Zsh and `PS1` in Bash, it's +important that the function executes each time the prompt renders. That way the +prompt will respond to changes in your git repo. To ensure this you will need +to escape the execution of the function. There are two ways to do this: + +**1. Use `$'` to render raw characters** +```bash +export PROMPT=$'$(git-radar --zsh)' +export PS1=$'$(git-radar --bash)' +``` + +**2. Use `\` to escape execution of the subshell** +```bash +export PROMPT="\$(git-radar --zsh)" +export PS1="\$(git-radar --bash)" ``` ## License -- cgit v1.2.3 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 1356a5100c272c77d39a2639ecb5c3d63992990f Mon Sep 17 00:00:00 2001 From: Max Linke Date: Tue, 1 Sep 2015 11:56:51 +0200 Subject: Add Makefile This will make it easier to install the tool. Currently everything is just copied into the home directory. But nothing works I have to figure out a little bit how to make this run under Linux. The develop command can be used for quick iteration cycles. --- Makefile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5e73c9f --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +SOURCES=git-radar radar-base.sh prompt.zsh prompt.bash fetch.sh +PREFIX=$(HOME)/.local + +all: + @echo 'Simple Install script for *git-radar* ' + @echo 'For a normal installation for your user only use:' + @echo ' make install' + @echo '' + @echo 'If you want to install *git-radar* system wide you should change' + @echo 'the prefix' + @echo '' + @echo ' PREFIX=/usr/local/bin make install' + @echo '' + @echo 'For a development install (symlinking files) do:' + @echo '' + @echo ' make develop' + +.PHONY: install develop + +install: $(SOURCES) + @echo 'Installing in ' $(PREFIX)/bin + cp git-radar $(PREFIX)/bin + cp radar-base.sh $(PREFIX)/bin + cp prompt.zsh $(PREFIX)/bin + cp prompt.bash $(PREFIX)/bin + cp fetch.sh $(PREFIX)/bin + + +develop: $(SOURCES) + @echo 'Symlinking in ' $(PREFIX)/bin + ln -s $(PWD)/git-radar $(PREFIX)/bin/git-radar + ln -s $(PWD)/radar-base.sh $(PREFIX)/bin/radar-base.sh + ln -s $(PWD)/prompt.zsh $(PREFIX)/bin/prompt.zsh + ln -s $(PWD)/prompt.bash $(PREFIX)/bin/prompt.bash + ln -s $(PWD)/fetch.sh $(PREFIX)/bin/fetch.sh -- 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 7696a556e593bb8d2e8675298cef5499d0b66f61 Mon Sep 17 00:00:00 2001 From: joaoschaab Date: Wed, 2 Sep 2015 16:22:36 -0300 Subject: Add manually installation instructions --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d4bd3dd..95cc4cd 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,19 @@ last few years. Maybe it can help you too. ## Installation -Install from brew: +### Install from brew: ``` > brew install michaeldfallen/formula/git-radar ``` +### Manually: + +``` +> cd ~ && git clone https://github.com/michaeldfallen/git-radar .git-radar +> echo 'export PATH=$PATH:$HOME/.git-radar' >> ~/.bashrc +``` + Then run `git-radar` to see the docs and prove it's installed. ## Usage -- 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 From a6c7770c2456747d3f06102d0dad2cbbf0f81542 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 4 Sep 2015 13:12:02 +0100 Subject: Adding new readme stuff to the table of contents --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 8ca65f9..1538681 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,16 @@ last few years. Maybe it can help you too. - [(Optional) Auto-fetch repos](#optional-auto-fetch-repos) - [Support](#support) - [Ensuring prompt execution](#ensuring-prompt-execution) + - [Configuring colours](#configuring-colours) + - [Exporting Environment Variables](#exporting-environment-variables) + - [Setting an RC file](#setting-an-rc-file) + - [Bash Colour Codes](#bash-colour-codes) + - [Zsh Colour Codes](#zsh-colour-codes) + - [Configuration values](#configuration-values) + - [Colouring the Branch part](#colouring-the-branch-part) + - [Colouring the local commits status](#colouring-the-local-commits-status) + - [Colouring the remote commits status](#colouring-the-remote-commits-status) + - [Colouring the file changes status](#colouring-the-file-changes-status) - [License](#license) ## Installation @@ -319,6 +329,8 @@ 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). +##### Colouring the Branch part + **GIT_RADAR_COLOR_BRANCH='[colour code]'** ``` git:(my-branch) @@ -330,6 +342,8 @@ It is unset by `GIT_RADAR_COLOR_BRANCH_RESET` which you can set if you want a different background colour to return to. +##### Colouring the local commits status + **GIT_RADAR_COLOR_LOCAL_AHEAD='[colour code]'** ``` git:(my-branch 1↑) @@ -362,6 +376,8 @@ The colour to use for the arrow that indicates how many commits your branch has It is unset by `GIT_RADAR_COLOR_LOCAL_RESET` which you can set if you want a different background colour to return to. +##### Colouring the remote commits status + **GIT_RADAR_COLOR_REMOTE_AHEAD='[colour code]'** ``` git:(m ← 1 my-branch) @@ -405,6 +421,8 @@ 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. +##### Colouring the file changes status + **GIT_RADAR_COLOR_CHANGES_STAGED='[colour code]'** ``` git:(my-branch) 1M -- cgit v1.2.3 From 373f8b4371abb8e4366efe4421981d5727ecd923 Mon Sep 17 00:00:00 2001 From: Albert Date: Sat, 5 Sep 2015 08:14:04 +0500 Subject: Fix bug with the view of colored branch name in bash --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index 25a4113..c793eab 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -182,7 +182,7 @@ branch_ref() { readable_branch_name() { if is_repo; then - printf '%s' "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" + printf "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" fi } -- cgit v1.2.3 From f2f8fe92cea4ab6ab8a82cdf4863b1dc6e6e2471 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sat, 5 Sep 2015 10:33:28 +0100 Subject: Fix mistaken colour output on bash --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index 25a4113..c793eab 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -182,7 +182,7 @@ branch_ref() { readable_branch_name() { if is_repo; then - printf '%s' "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" + printf "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" fi } -- cgit v1.2.3 From 3884b1fdf423f4e8655dd47bef0ccb2ebdd68c6d Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Sat, 5 Sep 2015 10:50:47 +0100 Subject: Fix colour issue for zsh --- prompt.bash | 2 +- prompt.zsh | 2 +- radar-base.sh | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/prompt.bash b/prompt.bash index 604d8e1..264ea7b 100755 --- a/prompt.bash +++ b/prompt.bash @@ -10,7 +10,7 @@ if is_repo; then if show_remote_status $args; then bash_color_remote_commits fi - readable_branch_name + bash_readable_branch_name bash_color_local_commits printf "\x01\033[1;30m\x02)\x01\033[0m\x02" bash_color_changes_status diff --git a/prompt.zsh b/prompt.zsh index e996b77..5a7cb40 100755 --- a/prompt.zsh +++ b/prompt.zsh @@ -12,7 +12,7 @@ if is_repo; then if show_remote_status $args; then zsh_color_remote_commits fi - readable_branch_name + zsh_readable_branch_name zsh_color_local_commits printf '%s' "%{$fg_bold[black]%})%{$reset_color%}" zsh_color_changes_status diff --git a/radar-base.sh b/radar-base.sh index c793eab..2ad9ce7 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -180,7 +180,13 @@ branch_ref() { fi } -readable_branch_name() { +zsh_readable_branch_name() { + if is_repo; then + printf '%s' "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" + fi +} + +bash_readable_branch_name() { if is_repo; then printf "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" fi -- cgit v1.2.3 From 1fcd42c3ecc41b6a6c4c9e75b6bfe274a1b595e2 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:18:30 +0100 Subject: Fix readable_branch_name test --- test-branches.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-branches.sh b/test-branches.sh index c886e82..f380a2d 100755 --- a/test-branches.sh +++ b/test-branches.sh @@ -54,7 +54,8 @@ test_detached_from_branch() { assertNotEquals "master" "$(branch_name)" assertEquals "$sha" "$(branch_ref)" - assertEquals "detached@$sha" "$(readable_branch_name)" + assertEquals "detached@$sha" "$(zsh_readable_branch_name)" + assertEquals "detached@$sha" "$(bash_readable_branch_name)" rm_tmp } -- cgit v1.2.3 From 9cfc2ed7f46fa9dea9fbeeef51a8ea8883c41c59 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:21:43 +0100 Subject: Merge bash and zsh specific render functions --- radar-base.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 2ad9ce7..12cab90 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -12,6 +12,8 @@ prepare_bash_colors() { source "$rcfile_path/.gitradarrc" fi + PRINT_F_OPTION="" + 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" @@ -42,6 +44,8 @@ prepare_zsh_colors() { source "$rcfile_path/.gitradarrc" fi + PRINT_F_OPTION="%s" + 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]}%}" @@ -398,7 +402,7 @@ bash_color_changes_status() { changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes" fi - printf "$changes" + printf $PRINT_F_OPTION "$changes" } zsh_color_changes_status() { @@ -430,7 +434,7 @@ zsh_color_changes_status() { changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes" fi - printf %s "$changes" + printf $PRINT_F_OPTION "$changes" } bash_color_local_commits() { @@ -453,7 +457,7 @@ bash_color_local_commits() { local_commits="$separator$local_ahead$green_ahead_arrow" fi fi - printf "$local_commits" + printf $PRINT_F_OPTION "$local_commits" } zsh_color_local_commits() { @@ -476,7 +480,7 @@ zsh_color_local_commits() { local_commits="$separator$local_ahead$ahead_arrow" fi fi - printf %s "$local_commits" + printf $PRINT_F_OPTION "$local_commits" } bash_color_remote_commits() { @@ -500,7 +504,7 @@ bash_color_remote_commits() { remote="upstream $not_upstream " fi - printf "$remote" + printf $PRINT_F_OPTION "$remote" } zsh_color_remote_commits() { @@ -524,7 +528,7 @@ zsh_color_remote_commits() { remote="upstream $not_upstream " fi - printf %s "$remote" + printf $PRINT_F_OPTION "$remote" } show_remote_status() { if [[ $@ == *$NO_REMOTE_STATUS* ]]; then -- cgit v1.2.3 From 1285baa3c095962265dc07b515ac9c0f7e75b959 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:24:29 +0100 Subject: Merge zsh and bash remote commit diff --- radar-base.sh | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 12cab90..747cb5e 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -483,7 +483,7 @@ zsh_color_local_commits() { printf $PRINT_F_OPTION "$local_commits" } -bash_color_remote_commits() { +color_remote_commits() { 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" @@ -507,29 +507,14 @@ bash_color_remote_commits() { printf $PRINT_F_OPTION "$remote" } -zsh_color_remote_commits() { - 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="$MASTER_SYMBOL $remote_behind $yellow_diverged_arrow $remote_ahead " - elif [[ "$remote_ahead" -gt "0" ]]; then - remote="$MASTER_SYMBOL $green_ahead_arrow $remote_ahead " - elif [[ "$remote_behind" -gt "0" ]]; then - remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow " - fi - else - remote="upstream $not_upstream " - fi +bash_color_remote_commits() { + color_remote_commits +} - printf $PRINT_F_OPTION "$remote" +zsh_color_remote_commits() { + color_remote_commits } + show_remote_status() { if [[ $@ == *$NO_REMOTE_STATUS* ]]; then return 1 # don't show the git remote status -- cgit v1.2.3 From d4ce9372c1f5ee82ac019d5a3c84f8af64cb0e4f Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:26:27 +0100 Subject: Merge zsh and bash local commit render func --- radar-base.sh | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 747cb5e..fb5fa90 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -437,7 +437,7 @@ zsh_color_changes_status() { printf $PRINT_F_OPTION "$changes" } -bash_color_local_commits() { +color_local_commits() { local separator="${1:- }" local green_ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL" @@ -460,27 +460,12 @@ bash_color_local_commits() { printf $PRINT_F_OPTION "$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 local_commits="" - if remote_branch="$(remote_branch_name)"; then - local_ahead="$(commits_ahead_of_remote "$remote_branch")" - local_behind="$(commits_behind_of_remote "$remote_branch")" +bash_color_local_commits() { + color_local_commits +} - if [[ "$local_behind" -gt "0" && "$local_ahead" -gt "0" ]]; then - local_commits="$separator$local_behind$diverged_arrow$local_ahead" - elif [[ "$local_behind" -gt "0" ]]; then - local_commits="$separator$local_behind$behind_arrow" - elif [[ "$local_ahead" -gt "0" ]]; then - local_commits="$separator$local_ahead$ahead_arrow" - fi - fi - printf $PRINT_F_OPTION "$local_commits" +zsh_color_local_commits() { + color_local_commits } color_remote_commits() { -- cgit v1.2.3 From 223312b3ce46caaabb233d03722d6393e9631706 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:28:19 +0100 Subject: Merge the zsh/bash changes render function --- radar-base.sh | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index fb5fa90..a4c67a1 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -373,7 +373,7 @@ untracked_status() { printf '%s' "$untracked_string" } -bash_color_changes_status() { +color_changes_status() { local separator="${1:- }" local porcelain="$(porcelain_status)" @@ -405,36 +405,12 @@ bash_color_changes_status() { printf $PRINT_F_OPTION "$changes" } -zsh_color_changes_status() { - local separator="${1:- }" - - local porcelain="$(porcelain_status)" - local changes="" - - 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_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 - - if [[ -n "$unstaged_changes" ]]; then - unstaged_changes="$separator$unstaged_changes" - fi - - if [[ -n "$conflicted_changes" ]]; then - conflicted_changes="$separator$conflicted_changes" - fi - - if [[ -n "$untracked_changes" ]]; then - untracked_changes="$separator$untracked_changes" - fi +bash_color_changes_status() { + color_changes_status +} - changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes" - fi - printf $PRINT_F_OPTION "$changes" +zsh_color_changes_status() { + color_changes_status } color_local_commits() { -- cgit v1.2.3 From 2c0be1e2fd311a5fd18726b44be1a0ff8ae823e4 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:31:23 +0100 Subject: Merge the zsh/bash readable branch function --- radar-base.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index a4c67a1..d9cd8f5 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -184,18 +184,6 @@ branch_ref() { fi } -zsh_readable_branch_name() { - if is_repo; then - printf '%s' "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" - fi -} - -bash_readable_branch_name() { - if is_repo; then - printf "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" - fi -} - remote_branch_name() { local localRef="\/$(branch_name)$" if [[ -n "$localRef" ]]; then @@ -476,6 +464,20 @@ zsh_color_remote_commits() { color_remote_commits } +readable_branch_name() { + if is_repo; then + printf $PRINT_F_OPTION "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" + fi +} + +zsh_readable_branch_name() { + readable_branch_name +} + +bash_readable_branch_name() { + readable_branch_name +} + show_remote_status() { if [[ $@ == *$NO_REMOTE_STATUS* ]]; then return 1 # don't show the git remote status -- cgit v1.2.3 From 131d04ea52fa194d8e027e495ca3b46e4b36f0ae Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 15:15:33 +0100 Subject: Test the new functions directly --- test-branches.sh | 1 + test-colors.sh | 7 +++++++ test-commits.sh | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/test-branches.sh b/test-branches.sh index f380a2d..5c33d23 100755 --- a/test-branches.sh +++ b/test-branches.sh @@ -56,6 +56,7 @@ test_detached_from_branch() { assertEquals "$sha" "$(branch_ref)" assertEquals "detached@$sha" "$(zsh_readable_branch_name)" assertEquals "detached@$sha" "$(bash_readable_branch_name)" + assertEquals "detached@$sha" "$(readable_branch_name)" rm_tmp } diff --git a/test-colors.sh b/test-colors.sh index 59a8704..73c20f7 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -293,12 +293,14 @@ test_bash_colors_local() { printf -v expected " 1\x01local-ahead\x02↑\x01local-reset\x02" assertEquals "$expected" "$(bash_color_local_commits)" + assertEquals "$expected" "$(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)" + assertEquals "$expected" "$(color_local_commits)" echo "foo" > foo git add . @@ -306,6 +308,7 @@ test_bash_colors_local() { printf -v expected " 1\x01local-diverged\x02⇵\x01local-reset\x021" assertEquals "$expected" "$(bash_color_local_commits)" + assertEquals "$expected" "$(color_local_commits)" rm_tmp } @@ -379,6 +382,7 @@ test_bash_colors_remote() { printf -v expected "m 1 \x01remote-behind\x02→\x01remote-reset\x02 " assertEquals "$expected" "$(bash_color_remote_commits)" + assertEquals "$expected" "$(color_remote_commits)" echo "bar" > bar git add . @@ -387,12 +391,14 @@ test_bash_colors_remote() { printf -v expected "m 1 \x01remote-diverged\x02⇄\x01remote-reset\x02 1 " assertEquals "$expected" "$(bash_color_remote_commits)" + assertEquals "$expected" "$(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)" + assertEquals "$expected" "$(color_remote_commits)" rm_tmp } @@ -459,6 +465,7 @@ test_bash_colors_changes() { printf -v expected " $staged $unstaged $untracked" assertEquals "$expected" "$(bash_color_changes_status)" + assertEquals "$expected" "$(color_changes_status)" rm_tmp } diff --git a/test-commits.sh b/test-commits.sh index 8aa2da2..1a4a86c 100755 --- a/test-commits.sh +++ b/test-commits.sh @@ -378,6 +378,7 @@ test_local_commits() { assertEquals "" "$(zsh_color_local_commits)" assertEquals "" "$(bash_color_local_commits)" + assertEquals "" "$(color_local_commits)" git init --quiet touch README @@ -394,6 +395,7 @@ test_local_commits() { assertEquals "" "$(zsh_color_local_commits)" assertEquals "" "$(bash_color_local_commits)" + assertEquals "" "$(color_local_commits)" cd "$repo" echo "bar" > bar @@ -402,6 +404,7 @@ test_local_commits() { assertEquals " 1$up" "$(zsh_color_local_commits)" assertEquals " 1$up" "$(bash_color_local_commits)" + assertEquals " 1$up" "$(color_local_commits)" cd "$remote" echo "foo" > foo @@ -413,11 +416,13 @@ test_local_commits() { assertEquals " 1${both}1" "$(zsh_color_local_commits)" assertEquals " 1${both}1" "$(bash_color_local_commits)" + assertEquals " 1${both}1" "$(color_local_commits)" git reset --hard HEAD^ --quiet assertEquals " 1$down" "$(zsh_color_local_commits)" assertEquals " 1$down" "$(bash_color_local_commits)" + assertEquals " 1$down" "$(color_local_commits)" } . ./shunit/shunit2 -- cgit v1.2.3 From eb9c08b9b0e05ca2aaf958e34979f6ae58af4e61 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 15:25:54 +0100 Subject: switch prompt files to use new shared render functions --- prompt.bash | 8 ++++---- prompt.zsh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/prompt.bash b/prompt.bash index 264ea7b..51c4db7 100755 --- a/prompt.bash +++ b/prompt.bash @@ -8,10 +8,10 @@ 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 + color_remote_commits fi - bash_readable_branch_name - bash_color_local_commits + readable_branch_name + color_local_commits printf "\x01\033[1;30m\x02)\x01\033[0m\x02" - bash_color_changes_status + color_changes_status fi diff --git a/prompt.zsh b/prompt.zsh index 5a7cb40..2d31820 100755 --- a/prompt.zsh +++ b/prompt.zsh @@ -10,10 +10,10 @@ if is_repo; then prepare_zsh_colors printf '%s' "%{$fg_bold[black]%} git:(%{$reset_color%}" if show_remote_status $args; then - zsh_color_remote_commits + color_remote_commits fi - zsh_readable_branch_name - zsh_color_local_commits + readable_branch_name + color_local_commits printf '%s' "%{$fg_bold[black]%})%{$reset_color%}" - zsh_color_changes_status + color_changes_status fi -- cgit v1.2.3