From 085610cccf8b1ad4731588ec2c2713283bb597d2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 1 Apr 2015 03:51:19 +0200 Subject: [PATCH 1/9] Display a tests vs code ratio (RSpec and Symfony2-PHPUnit-tests). --- powerlevel9k.zsh-theme | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 86c16ecb..9d823ff3 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -294,6 +294,41 @@ prompt_aws() { fi } +# RSpec test ratio +prompt_rspec_stats() { + if [[ (-d app && -d spec) ]]; then + local code_amount=$(wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1) + local tests_amount=$(wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1) + + build_test_stats $1 $code_amount $tests_amount "RSpec" + fi +} + +# Symfony2-PHPUnit test ratio +prompt_symfony2_tests() { + if [[ (-d src && -d app && -f app/AppKernel.php) ]]; then + local code_amount=$(ls -1 src/**/*.php | grep -v Tests | wc -l) + local tests_amount=$(ls -1 src/**/*.php | grep Tests | wc -l) + + build_test_stats $1 $code_amount $tests_amount "SF2-Tests" + fi +} + +# Show a ratio of tests vs code +build_test_stats() { + local code_amount=$2 + local tests_amount=$3+0.01 + local headline=$4 + + # Set float precision to 2 digits: + typeset -F 2 ratio + local ratio=$(( (tests_amount/code_amount) * 100 )) + + [[ ratio -ge 0.75 ]] && $1_prompt_segment cyan $DEFAULT_COLOR "$headline: $ratio%%" + [[ ratio -ge 0.5 && ratio -lt 0.75 ]] && $1_prompt_segment yellow $DEFAULT_COLOR "$headline: $ratio%%" + [[ ratio -lt 0.5 ]] && $1_prompt_segment red $DEFAULT_COLOR "$headline: $ratio%%" +} + # Main prompt build_left_prompt() { if [[ ${#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS} == 0 ]]; then From 18cbe235b8e4f7e5ef30937664a5afbcdb887e47 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 01:59:02 +0200 Subject: [PATCH 2/9] Added documentation. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 100fd588..1782e15f 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,9 @@ currently available are: * **dir** - Your current working directory. * **history** - The command number for the current line. * **rbenv** - Ruby environment information (if one is active). +* **rspec** - Show a ratio of test classes vs code classes for RSpec. * **status** - The return code of the previous command, and status of background jobs. +* **symfony2_tests** - Show a ratio of test classes vs code classes for Symfony2. * **time** - System time. * **vcs** - Information about this `git` or `hg` repository (if you are in one). From a06c53902d626af6a7b2eb7152082dba9ccf4c5f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 02:17:25 +0200 Subject: [PATCH 3/9] Whitespace. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 53f5023d..f279f994 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -336,9 +336,9 @@ build_test_stats() { local tests_amount=$3+0.01 local headline=$4 - # Set float precision to 2 digits: - typeset -F 2 ratio - local ratio=$(( (tests_amount/code_amount) * 100 )) + # Set float precision to 2 digits: + typeset -F 2 ratio + local ratio=$(( (tests_amount/code_amount) * 100 )) [[ ratio -ge 0.75 ]] && $1_prompt_segment cyan $DEFAULT_COLOR "$headline: $ratio%%" [[ ratio -ge 0.5 && ratio -lt 0.75 ]] && $1_prompt_segment yellow $DEFAULT_COLOR "$headline: $ratio%%" From aadf37bd35c960fd337f73f78b91774e2ee13b0f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 09:43:57 +0200 Subject: [PATCH 4/9] Documentation is now correct. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6ab7870..cb72bcde 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ currently available are: * **dir** - Your current working directory. * **history** - The command number for the current line. * **rbenv** - Ruby environment information (if one is active). -* **rspec** - Show a ratio of test classes vs code classes for RSpec. +* **rspec_stats** - Show a ratio of test classes vs code classes for RSpec. * **status** - The return code of the previous command, and status of background jobs. * **symfony2_tests** - Show a ratio of test classes vs code classes for Symfony2. * **time** - System time. From 94af6aae4335a01b522cc1379d6e1ff96025e3fb Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 09:49:26 +0200 Subject: [PATCH 5/9] Better implementation of counting Classes and Tests for RSpec. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f279f994..92efcaee 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -313,8 +313,8 @@ prompt_aws() { # RSpec test ratio prompt_rspec_stats() { if [[ (-d app && -d spec) ]]; then - local code_amount=$(wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1) - local tests_amount=$(wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1) + local code_amount=$(ls -1 app/**/*.rb | wc -l) + local tests_amount=$(ls -1 spec/**/*.rb | wc -l) build_test_stats $1 $code_amount $tests_amount "RSpec" fi From 4ad84c0936cde7549e46d85a05d3586946a28fef Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 09:54:40 +0200 Subject: [PATCH 6/9] Improved correction factor, so that the ratio is a nice percentage. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 92efcaee..b13b2159 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -333,7 +333,7 @@ prompt_symfony2_tests() { # Show a ratio of tests vs code build_test_stats() { local code_amount=$2 - local tests_amount=$3+0.01 + local tests_amount=$3+0.00001 local headline=$4 # Set float precision to 2 digits: From b25c0adc4d247e4ea3fbc75b1ae8d714339764da Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Thu, 2 Apr 2015 10:45:53 -0700 Subject: [PATCH 7/9] Adding settings var docs to the theme file for people without README --- powerlevel9k.zsh-theme | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b13b2159..8a3d97b9 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1,5 +1,5 @@ # vim:ft=zsh ts=2 sw=2 sts=2 -# +################################################################ # powerlevel9k Theme # https://github.com/bhilburn/powerlevel9k # @@ -11,10 +11,34 @@ # # In order for this theme to render correctly, you will need a Powerline-patched font: # https://github.com/Lokaltog/powerline-fonts -# +################################################################ -### Segment drawing -# A few utility functions to make it easy and re-usable to draw segmented prompts +################################################################ +# Please see the README file located in the source repository for full docs. +# What follows is a brief list of the settings variables used by this theme. +# You should define these variables in your `~/.zshrc`. +# +# Customize which segments appear in which prompts (below is also the default): +# POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) +# POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) +# +# Set your Amazon Web Services profile for the `aws` segment: +# export AWS_DEFAULT_PROFILE= +# +# Set your username for the `context` segment: +# export DEFAULT_USER= +# +# Show the hash/changeset string in the `vcs` segment: +# POWERLEVEL9K_SHOW_CHANGESET=true +# Set the length of the hash/changeset if enabled in the `vcs` segment: +# POWERLEVEL9K_CHANGESET_HASH_LENGTH=6 +# +# Make powerlevel9k a double-lined prompt: +# POWERLEVEL9K_PROMPT_ON_NEWLINE=true +# +# Set the colorscheme: +# POWERLEVEL9K_COLOR_SCHEME='light' +################################################################ # The `CURRENT_BG` variable is used to remember what the last BG color used was # when building the left-hand prompt. Because the RPROMPT is created from From cfd8484ce50680fb0db350ceb127f4fc7ea70895 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Thu, 2 Apr 2015 10:49:47 -0700 Subject: [PATCH 8/9] Few additions to the README --- README.md | 2 ++ powerlevel9k.zsh-theme | 1 + 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index cb72bcde..54893457 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ currently available are: * **status** - The return code of the previous command, and status of background jobs. * **symfony2_tests** - Show a ratio of test classes vs code classes for Symfony2. * **time** - System time. +* **virtualenv** - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). * **vcs** - Information about this `git` or `hg` repository (if you are in one). To specify which segments you want, just add the following variables to your @@ -132,6 +133,7 @@ The `vcs` segment uses various symbols to tell you the state of your repository: * `●` - There are unstaged changes in your working copy * `✚` - There are staged changes in your working copy * `?` - There are files in your working copy, that are unknown to your repository +* `→` - The name of your branch differs from it's tracking branch. ### Styling diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8a3d97b9..1ac02d6d 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -395,6 +395,7 @@ build_right_prompt() { done } +################################################################ # Create the prompts precmd() { vcs_info From b1d6d3e67d6f6c936c1150ab5f438813bed0a23a Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Thu, 2 Apr 2015 10:51:08 -0700 Subject: [PATCH 9/9] README: Derp. Silly grammar error. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54893457..0dd20689 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ The `vcs` segment uses various symbols to tell you the state of your repository: * `●` - There are unstaged changes in your working copy * `✚` - There are staged changes in your working copy * `?` - There are files in your working copy, that are unknown to your repository -* `→` - The name of your branch differs from it's tracking branch. +* `→` - The name of your branch differs from its tracking branch. ### Styling