From 9ac79bd3aa49f037d3fc19bdf859b7ae1b05b762 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 26 Feb 2016 14:26:49 +0100 Subject: [PATCH 1/3] Rename VCS default state to `clean` --- CHANGELOG.md | 10 ++++++++++ powerlevel9k.zsh-theme | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 728f3578..557f977b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ ## v0.4.0 (next) +### `vcs` changes + +The default state was renamed to `clean`. If you overrode foreground +or background color in the past, you need to rename your variables to: + +```zsh +POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' +POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' +``` + ### `aws_eb_env` added This segment displays the current Elastic Beanstalk environment. diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 37950e76..4ff14489 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -755,11 +755,11 @@ prompt_vcs() { VCS_WORKDIR_DIRTY=false VCS_WORKDIR_HALF_DIRTY=false - # The vcs segment can have three different states - defaults to ''. + # The vcs segment can have three different states - defaults to 'clean'. local current_state="" typeset -AH vcs_states vcs_states=( - '' 'green' + 'clean' 'green' 'modified' 'red' 'untracked' 'yellow' ) @@ -815,7 +815,7 @@ prompt_vcs() { if [[ "$VCS_WORKDIR_HALF_DIRTY" == true ]]; then current_state='untracked' else - current_state='' + current_state='clean' fi fi "$1_prompt_segment" "${0}_${(U)current_state}" "$2" "${vcs_states[$current_state]}" "$DEFAULT_COLOR" "$vcs_prompt" "$vcs_visual_identifier" From 359109978964d226e9b0697c2e30e074ae5c8548 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 26 Feb 2016 15:21:33 +0100 Subject: [PATCH 2/3] Add tests for dynamic color overriding of vcs segment --- .travis.yml | 1 + test/segments/vcs.spec | 77 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100755 test/segments/vcs.spec diff --git a/.travis.yml b/.travis.yml index 71aff690..4f2c7a39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,4 +24,5 @@ script: - test/segments/dir.spec - test/segments/rust_version.spec - test/segments/go_version.spec + - test/segments/vcs.spec diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec new file mode 100755 index 00000000..862067b7 --- /dev/null +++ b/test/segments/vcs.spec @@ -0,0 +1,77 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme +} + +function testColorOverridingForCleanStateWorks() { + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' + POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' + + FOLDER=/tmp/powerlevel9k-test/vcs-test + mkdir -p $FOLDER + cd $FOLDER + git init 1>/dev/null + + assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_VCS_CLEAN_FOREGROUND + unset POWERLEVEL9K_VCS_CLEAN_BACKGROUND +} + +function testColorOverridingForModifiedStateWorks() { + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red' + POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow' + + FOLDER=/tmp/powerlevel9k-test/vcs-test + mkdir -p $FOLDER + cd $FOLDER + git init 1>/dev/null + touch testfile + git add testfile + + assertEquals "%K{yellow} %F{red} master ✚ %k%F{yellow}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_VCS_MODIFIED_FOREGROUND + unset POWERLEVEL9K_VCS_MODIFIED_BACKGROUND +} + +function testColorOverridingForUntrackedStateWorks() { + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='cyan' + POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow' + + FOLDER=/tmp/powerlevel9k-test/vcs-test + mkdir -p $FOLDER + cd $FOLDER + git init 1>/dev/null + touch testfile + + assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND +} + +source shunit2/source/2.1/src/shunit2 From cb5d33affb4fb223ec29f6dfb89ff8b0bb6e9133 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 26 Feb 2016 15:23:02 +0100 Subject: [PATCH 3/3] Fix untracked state of the vcs segment --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 9baccd24..9d3883ca 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -17,7 +17,7 @@ function +vi-git-untracked() { fi if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \ - -n $(git status ${FLAGS} | grep -E '^??' 2> /dev/null | tail -n1) ]]; then + -n $(git status ${FLAGS} | grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true else