From 05f44b94bf670d9f828b44e31ecf7b90e624fab8 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Apr 2018 10:52:15 -0700 Subject: [PATCH 1/2] Add options for customizing `chruby` segment --- README.md | 11 +++++++++++ powerlevel9k.zsh-theme | 21 +++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1f7dcadb..57018938 100644 --- a/README.md +++ b/README.md @@ -393,6 +393,17 @@ segment will not be displayed. |`POWERLEVEL9K_PUBLIC_IP_METHODS`|(dig curl wget)| These methods in that order are used to refresh your IP.| |`POWERLEVEL9K_PUBLIC_IP_NONE`|None|The string displayed when an IP was not obtained| +##### chruby + +This segment shows the version of Ruby being used when using `chruby` to change your current Ruby stack. + +It uses `$RUBY_ENGINE` and `$RUBY_VERSION` as set by `chruby`. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_CHRUBY_SHOW_ENGINE`|true|Show the currently selected Ruby engine (e.g. `ruby`, `jruby`, `rbx`, etc) +|`POWERLEVEL9K_CHRUBY_SHOW_VERSION`|true|Shows the currently selected engine's version (e.g. `2.5.1`) + ##### rbenv This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack. diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 26ab9cd5..62f6d352 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -950,11 +950,24 @@ prompt_rbenv() { # chruby information # see https://github.com/postmodern/chruby/issues/245 for chruby_auto issue with ZSH prompt_chruby() { - local chruby_env - chrb_env="$(chruby 2> /dev/null | grep \* | tr -d '* ')" + # Uses $RUBY_VERSION and $RUBY_ENGINE set by chruby + set_default POWERLEVEL9K_CHRUBY_SHOW_VERSION true + set_default POWERLEVEL9K_CHRUBY_SHOW_ENGINE true + local chruby_label="" + + if [[ "$POWERLEVEL9K_CHRUBY_SHOW_ENGINE" == true ]]; then + chruby_label+="$RUBY_ENGINE " + fi + if [[ "$POWERLEVEL9K_CHRUBY_SHOW_VERSION" == true ]]; then + chruby_label+="$RUBY_VERSION" + fi + + # Truncate trailing spaces + chruby_label="${chruby_label%"${chruby_label##*[![:space:]]}"}" + # Don't show anything if the chruby did not change the default ruby - if [[ "${chrb_env:-system}" != "system" ]]; then - "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "${chrb_env}" 'RUBY_ICON' + if [[ "$RUBY_ENGINE" != "" ]]; then + "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "${chruby_label}" 'RUBY_ICON' fi } From 75c6838a0dbb2fc84f2cf7d71cae9b147b04a379 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Apr 2018 10:56:44 -0700 Subject: [PATCH 2/2] Alphabetize chruby documentation --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 57018938..949f3ac7 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,17 @@ Note that you can [modify the `_FOREGROUND` color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization) without affecting the icon color. +##### chruby + +This segment shows the version of Ruby being used when using `chruby` to change your current Ruby stack. + +It uses `$RUBY_ENGINE` and `$RUBY_VERSION` as set by `chruby`. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_CHRUBY_SHOW_ENGINE`|true|Show the currently selected Ruby engine (e.g. `ruby`, `jruby`, `rbx`, etc) +|`POWERLEVEL9K_CHRUBY_SHOW_VERSION`|true|Shows the currently selected engine's version (e.g. `2.5.1`) + ##### command_execution_time Display the time the previous command took to execute if the time is above @@ -393,17 +404,6 @@ segment will not be displayed. |`POWERLEVEL9K_PUBLIC_IP_METHODS`|(dig curl wget)| These methods in that order are used to refresh your IP.| |`POWERLEVEL9K_PUBLIC_IP_NONE`|None|The string displayed when an IP was not obtained| -##### chruby - -This segment shows the version of Ruby being used when using `chruby` to change your current Ruby stack. - -It uses `$RUBY_ENGINE` and `$RUBY_VERSION` as set by `chruby`. - -| Variable | Default Value | Description | -|----------|---------------|-------------| -|`POWERLEVEL9K_CHRUBY_SHOW_ENGINE`|true|Show the currently selected Ruby engine (e.g. `ruby`, `jruby`, `rbx`, etc) -|`POWERLEVEL9K_CHRUBY_SHOW_VERSION`|true|Shows the currently selected engine's version (e.g. `2.5.1`) - ##### rbenv This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack.