From 5657fe6ac7d75cac48a386f55e429b716f8d7623 Mon Sep 17 00:00:00 2001 From: Chris Chou Date: Fri, 6 Oct 2017 09:47:37 +1300 Subject: [PATCH 01/40] #632: Indicate `Rust` or `(rust)` for rust_version segment only if icon is unavailable --- functions/icons.zsh | 4 ++-- powerlevel9k.zsh-theme | 4 ++-- test/segments/rust_version.spec | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index 3a4909f7..be507563 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -77,7 +77,7 @@ case $POWERLEVEL9K_MODE in VCS_GIT_GITLAB_ICON $'\uE20E ' # VCS_HG_ICON $'\uE1C3 ' #  VCS_SVN_ICON '(svn) ' - RUST_ICON '' + RUST_ICON '(rust)' PYTHON_ICON $'\ue63c' #  SWIFT_ICON '' GO_ICON '' @@ -290,7 +290,7 @@ case $POWERLEVEL9K_MODE in VCS_GIT_GITLAB_ICON '' VCS_HG_ICON '' VCS_SVN_ICON '' - RUST_ICON '' + RUST_ICON 'Rust' PYTHON_ICON '' SWIFT_ICON 'Swift' GO_ICON 'Go' diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5aa280c6..edb94632 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1095,9 +1095,9 @@ prompt_root_indicator() { prompt_rust_version() { local rust_version rust_version=$(rustc --version 2>&1 | grep -oe "^rustc\s*[^ ]*" | grep -o '[0-9.a-z\\\-]*$') - + if [[ -n "$rust_version" ]]; then - "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "Rust $rust_version" 'RUST_ICON' + "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "$rust_version" 'RUST_ICON' fi } # RSpec test ratio diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 49b06bcf..c945f8ae 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -19,7 +19,7 @@ function testRust() { alias rustc=mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) - assertEquals "%K{208} %F{black}Rust 0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" + assertEquals "%K{208} %F{black%}Rust%f %F{black}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias rustc From a761e3c28a78cfbf7d7ca9cde5bdcd1126c2996c Mon Sep 17 00:00:00 2001 From: Conrad Haupt Date: Mon, 12 Mar 2018 14:28:17 +0200 Subject: [PATCH 02/40] Fixed home abbreviation not being exclusive with circular navigation --- powerlevel9k.zsh-theme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 14d7bd81..12d05db3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -809,7 +809,9 @@ prompt_dir() { current_path="${cur_short_path: : -1}" ;; *) - current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" + if [[ $current_path != "~" ]]; then + current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" + fi ;; esac fi From 83ad5b598e1524fa76055f8ed086eb155c39c580 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 20 Mar 2018 22:39:20 +0100 Subject: [PATCH 03/40] Add test for wrong truncation if switching back to home folder This happens if a user switches from a subdirectory of $HOME back to the home folder and truncation strategy is "truncate folders from left". Then the folder is displayed as .../~ PR: #773 --- test/segments/dir.spec | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/segments/dir.spec b/test/segments/dir.spec index ef27e160..97bc857c 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -36,6 +36,27 @@ function testTruncateFoldersWorks() { unset POWERLEVEL9K_SHORTEN_STRATEGY } +function testTruncateFolderWithHomeDirWorks() { + POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 + CURRENT_DIR=$(pwd) + + cd ~ + FOLDER="powerlevel9k-test-${RANDOM}" + mkdir -p $FOLDER + cd $FOLDER + # Switch back to home folder as this causes the problem. + cd .. + + assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + + rmdir $FOLDER + cd ${CURRENT_DIR} + + unset CURRENT_DIR + unset FOLDER + unset POWERLEVEL9K_SHORTEN_DIR_LENGTH +} + function testTruncateMiddleWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' From 70fa74f6313bf6a6df3c71e1c82783f6af46c7a0 Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Wed, 21 Mar 2018 16:28:23 +0100 Subject: [PATCH 04/40] Fix Brightness Table --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 46d8ab61..cb5c065c 100644 --- a/README.md +++ b/README.md @@ -250,10 +250,12 @@ As with the battery stages, you can use any number of colors and Powerlevel9k will automatically use all of them appropriately. Some example settings: -|Brightness|Possible Array| -|Bright Colors|(196 202 208 214 220 226 190 154 118 82 46)| -|Normal Colors|(124 130 136 142 148 112 76 40 34 28 22)| -|Subdued Colors|( 88 94 100 106 70 34 28 22)| + +| Brightness | Possible Array | +|----------------|-------------------------------------------------| +| Bright Colors | `(196 202 208 214 220 226 190 154 118 82 46)` | +| Normal Colors | `(124 130 136 142 148 112 76 40 34 28 22)` | +| Subdued Colors | `( 88 94 100 106 70 34 28 22)` | ##### command_execution_time From 4de4e8d9d70ba3faeea31c2486632b5cb142b40d Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Thu, 22 Mar 2018 01:05:35 +0100 Subject: [PATCH 05/40] Fix POWERLEVEL9k_BATTERY_STAGES Table --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb5c065c..9991547a 100644 --- a/README.md +++ b/README.md @@ -209,8 +209,9 @@ You can also change the battery icon automatically depending on the battery level. This will override the default battery icon. In order to do this, you need to define the `POWERLEVEL9k_BATTERY_STAGES` variable. -| Variable | Default Value | Description | -| `POWERLEVEL9K_BATTERY_STAGES`|Unset|A string or array, which each index indicates a charge level.| +| Variable | Default Value | Description | +|-------------------------------|---------------|---------------------------------------------------------------| +| `POWERLEVEL9K_BATTERY_STAGES` | Unset | A string or array, which each index indicates a charge level. | Powerlevel9k will use each index of the string or array as a stage to indicate battery charge level, progressing from left to right. You can provide any number of From b260adbc1bc68d9729d6eebcfd344f83655bfda9 Mon Sep 17 00:00:00 2001 From: Julien Roy Date: Sat, 24 Mar 2018 11:04:16 +0100 Subject: [PATCH 06/40] Added a segment that shows the Java version. --- README.md | 2 ++ functions/icons.zsh | 4 ++++ powerlevel9k.zsh-theme | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 46d8ab61..2686b2e7 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ The segments that are currently available are: * `rust_version` - Display the current rust version and [logo](https://www.rust-lang.org/logos/rust-logo-blk.svg). * **Swift Segments:** * `swift_version` - Show the version number of the installed Swift. +* **Java Segments:** + * `java_version` - Show the current Java version. **Cloud Segments:** * **AWS Segments:** diff --git a/functions/icons.zsh b/functions/icons.zsh index 7124386b..b7da9940 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -87,6 +87,7 @@ case $POWERLEVEL9K_MODE in SSH_ICON '(ssh)' VPN_ICON '(vpn)' KUBERNETES_ICON $'\U2388' # ⎈ + JAVA_ICON $'\U2615' # ☕︎ ) ;; 'awesome-fontconfig') @@ -158,6 +159,7 @@ case $POWERLEVEL9K_MODE in SSH_ICON '(ssh)' VPN_ICON $'\uF023' KUBERNETES_ICON $'\U2388' # ⎈ + JAVA_ICON $'\U2615' # ☕︎ ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -229,6 +231,7 @@ case $POWERLEVEL9K_MODE in SSH_ICON $'\uF489' #  VPN_ICON '(vpn)' KUBERNETES_ICON $'\U2388' # ⎈ + JAVA_ICON $'\U2615' # ☕︎ ) ;; *) @@ -300,6 +303,7 @@ case $POWERLEVEL9K_MODE in SSH_ICON '(ssh)' VPN_ICON '(vpn)' KUBERNETES_ICON $'\U2388' # ⎈ + JAVA_ICON $'\U2615' # ☕︎ ) ;; esac diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 14d7bd81..e3be9c53 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1433,6 +1433,15 @@ prompt_kubecontext() { fi } +# print Java version number +prompt_java_version() { + local java_version + java_version=$(java -fullversion 2>&1 | cut -d '"' -f 2) + + if [[ -n "$java_version" ]]; then + "$1_prompt_segment" "$0" "$2" "red" "white" "$java_version" "JAVA_ICON" + fi +} ################################################################ # Prompt processing and drawing From fe33c401bac783181e0fc53401685fa9b2ad0e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Mon, 26 Mar 2018 14:55:06 -0400 Subject: [PATCH 07/40] workaround for ZSH status behavior `$pipestatus` is returning all zeros when using `[[ ]]` expressions that are false. This works around it by using `$status` (A.K.A. `$?`) when `$pipestatus` has only 1 items. Fixes #749 --- powerlevel9k.zsh-theme | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 14d7bd81..2255a04a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1163,8 +1163,13 @@ prompt_status() { local ec if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then - ec_text=$(exit_code_or_status "${RETVALS[1]}") - ec_sum=${RETVALS[1]} + if (( $#RETVALS > 1 )); then + ec_text=$(exit_code_or_status "${RETVALS[1]}") + ec_sum=${RETVALS[1]} + else + ec_text=$(exit_code_or_status "${RETVAL}") + ec_sum=${RETVAL} + fi for ec in "${(@)RETVALS[2,-1]}"; do ec_text="${ec_text}|$(exit_code_or_status "$ec")" From 9f7b0b7404a3d5307755d5e55ddc33e2e39090ba Mon Sep 17 00:00:00 2001 From: Ryan Davidson Date: Tue, 3 Apr 2018 13:52:13 +0100 Subject: [PATCH 08/40] #777 Add POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW variable to display prompt_rbenv if rbenv_version_name is the same as rbenv_global --- powerlevel9k.zsh-theme | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 14d7bd81..07902ba6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1065,14 +1065,15 @@ prompt_ram() { "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$ramfree" $base)" 'RAM_ICON' } +set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false # rbenv information prompt_rbenv() { - if which rbenv 2>/dev/null >&2; then + if command which rbenv 2>/dev/null >&2; then local rbenv_version_name="$(rbenv version-name)" local rbenv_global="$(rbenv global)" # Don't show anything if the current Ruby is the same as the global Ruby. - if [[ $rbenv_version_name == $rbenv_global ]]; then + if [[ $rbenv_version_name == $rbenv_global && "$POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW" = false ]]; then return fi @@ -1418,7 +1419,7 @@ prompt_kubecontext() { if [[ -z "$k8s_namespace" ]]; then k8s_namespace="default" fi - + local k8s_final_text="" if [[ "$k8s_context" == "k8s_namespace" ]]; then @@ -1427,8 +1428,8 @@ prompt_kubecontext() { else k8s_final_text="$k8s_context/$k8s_namespace" fi - - + + "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_final_text" "KUBERNETES_ICON" fi } From e85fb6c93d6bc77d827133a3419d888fed5c8a4d Mon Sep 17 00:00:00 2001 From: Ryan Davidson Date: Tue, 3 Apr 2018 14:04:28 +0100 Subject: [PATCH 09/40] #777 update Readme with POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW variable description --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 46d8ab61..a04b4eea 100644 --- a/README.md +++ b/README.md @@ -511,6 +511,10 @@ It figures out the version being used by taking the output of the `rbenv version * If `rbenv` is not in $PATH, nothing will be shown. * If the current Ruby version is the same as the global Ruby version, nothing will be shown. +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW`|`false`|Set to true if you wish to show the rbenv segment even if the current Ruby version is the same as the global Ruby version| + ##### rspec_stats See [Unit Test Ratios](#unit-test-ratios), below. From 1aee125470cd16add49fb700fbde4691197ae3da Mon Sep 17 00:00:00 2001 From: Guilherme Cassolato Date: Wed, 11 Apr 2018 17:07:24 +0200 Subject: [PATCH 10/40] Fixes wrapper slowness in vcs segment --- functions/vcs.zsh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index c3e507b9..6a30903e 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -16,8 +16,8 @@ function +vi-git-untracked() { FLAGS+='--ignore-submodules=dirty' 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 + if [[ $(command git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \ + -n $(command 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 @@ -29,16 +29,16 @@ function +vi-git-aheadbehind() { local ahead behind branch_name local -a gitstatus - branch_name=$(git symbolic-ref --short HEAD 2>/dev/null) + branch_name=$(command git symbolic-ref --short HEAD 2>/dev/null) # for git prior to 1.7 - # ahead=$(git rev-list origin/${branch_name}..HEAD | wc -l) - ahead=$(git rev-list "${branch_name}"@{upstream}..HEAD 2>/dev/null | wc -l) + # ahead=$(command git rev-list origin/${branch_name}..HEAD | wc -l) + ahead=$(command git rev-list "${branch_name}"@{upstream}..HEAD 2>/dev/null | wc -l) (( ahead )) && gitstatus+=( " $(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}" ) # for git prior to 1.7 - # behind=$(git rev-list HEAD..origin/${branch_name} | wc -l) - behind=$(git rev-list HEAD.."${branch_name}"@{upstream} 2>/dev/null | wc -l) + # behind=$(command git rev-list HEAD..origin/${branch_name} | wc -l) + behind=$(command git rev-list HEAD.."${branch_name}"@{upstream} 2>/dev/null | wc -l) (( behind )) && gitstatus+=( " $(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}" ) hook_com[misc]+=${(j::)gitstatus} @@ -48,8 +48,8 @@ function +vi-git-remotebranch() { local remote branch_name # Are we on a remote-tracking branch? - remote=${$(git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} - branch_name=$(git symbolic-ref --short HEAD 2>/dev/null) + remote=${$(command git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} + branch_name=$(command git symbolic-ref --short HEAD 2>/dev/null) hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}" # Always show the remote @@ -65,18 +65,18 @@ function +vi-git-tagname() { if [[ "$POWERLEVEL9K_VCS_HIDE_TAGS" == "false" ]]; then # If we are on a tag, append the tagname to the current branch string. local tag - tag=$(git describe --tags --exact-match HEAD 2>/dev/null) + tag=$(command git describe --tags --exact-match HEAD 2>/dev/null) if [[ -n "${tag}" ]] ; then # There is a tag that points to our current commit. Need to determine if we # are also on a branch, or are in a DETACHED_HEAD state. - if [[ -z $(git symbolic-ref HEAD 2>/dev/null) ]]; then + if [[ -z $(command git symbolic-ref HEAD 2>/dev/null) ]]; then # DETACHED_HEAD state. We want to append the tag name to the commit hash # and print it. Unfortunately, `vcs_info` blows away the hash when a tag # exists, so we have to manually retrieve it and clobber the branch # string. local revision - revision=$(git rev-list -n 1 --abbrev-commit --abbrev=${POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} HEAD) + revision=$(command git rev-list -n 1 --abbrev-commit --abbrev=${POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} HEAD) hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${revision} $(print_icon 'VCS_TAG_ICON')${tag}" else # We are on both a tag and a branch; print both by appending the tag name. @@ -91,8 +91,8 @@ function +vi-git-tagname() { function +vi-git-stash() { local -a stashes - if [[ -s $(git rev-parse --git-dir)/refs/stash ]] ; then - stashes=$(git stash list 2>/dev/null | wc -l) + if [[ -s $(command git rev-parse --git-dir)/refs/stash ]] ; then + stashes=$(command git stash list 2>/dev/null | wc -l) hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${stashes// /}" fi } @@ -111,7 +111,7 @@ function +vi-hg-bookmarks() { function +vi-vcs-detect-changes() { if [[ "${hook_com[vcs]}" == "git" ]]; then - local remote=$(git ls-remote --get-url 2> /dev/null) + local remote=$(command git ls-remote --get-url 2> /dev/null) if [[ "$remote" =~ "github" ]] then vcs_visual_identifier='VCS_GIT_GITHUB_ICON' elif [[ "$remote" =~ "bitbucket" ]] then From 111d152d48cc92229cb523a992a0ecee740381e7 Mon Sep 17 00:00:00 2001 From: Taras Shpachenko Date: Thu, 12 Apr 2018 13:39:39 +0300 Subject: [PATCH 11/40] Add vcs branch name truncating. --- README.md | 23 ++++++++++++ functions/vcs.zsh | 15 ++++++++ test/segments/vcs.spec | 80 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/README.md b/README.md index 8b0fc03c..bd3b8318 100644 --- a/README.md +++ b/README.md @@ -637,6 +637,29 @@ from the [Installation](#Installation) section above. | None | None | ![icon_git](https://cloud.githubusercontent.com/assets/1544760/7976092/b5909f80-0a76-11e5-9950-1438b9d72465.gif) | Repository is a git repository | None | None | ![icon_mercurial](https://cloud.githubusercontent.com/assets/1544760/7976090/b5908da6-0a76-11e5-8c91-452b6e73f631.gif) | Repository is a Mercurial repository +You can limit the branch name to a certain length by truncating long names. +Customizations available are: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_VCS_SHORTEN_LENGTH`|None|This field determines how many characters to show.| +|`POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH`|None|This field determines minimum branch length. Branch name will be truncated if its length greater than this field.| +|`POWERLEVEL9K_VCS_SHORTEN_STRATEGY`|None|This field determines how branch name should be truncated. See the table below for more information.| +|`POWERLEVEL9K_SHORTEN_DELIMITER`|`...`|Delimiter to use in truncated strings. This can be any string you choose, including an empty string if you wish to have no delimiter.| + +| Strategy Name | Description | +|---------------|-------------| +|`truncate_middle`|Truncates the middle part of a branch. E.g. branch name is `1234-super_super_long_branch_name`, then it will truncated to `1234-..._name`, if `POWERLEVEL9K_VCS_SHORTEN_LENGTH=5` is also set (controls the amount of characters to be left).| +|`truncate_from_right`|Just leaves the beginning of a branch name untouched. E.g. branch name will be truncated like so: `1234-...`. How many characters will be untouched is controlled by `POWERLEVEL9K_VCS_SHORTEN_LENGTH`.| + +For example, if you want to truncate `1234-super_super_long_branch_name` to `1234-..` and don't do it with `development`: +```zsh +POWERLEVEL9K_VCS_SHORTEN_LENGTH=4 +POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=11 +POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" +POWERLEVEL9K_VCS_SHORTEN_DELIMITER=".." +``` + ##### vi_mode This segment shows ZSH's current input mode. Note that this is only useful if diff --git a/functions/vcs.zsh b/functions/vcs.zsh index e2e9f3a3..c936f27d 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -51,6 +51,21 @@ function +vi-git-remotebranch() { remote=${$(git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} branch_name=$(git symbolic-ref --short HEAD 2>/dev/null) + if [[ -n "$POWERLEVEL9K_VCS_SHORTEN_LENGTH" ]] && [[ -n "$POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH" ]]; then + set_default POWERLEVEL9K_VCS_SHORTEN_DELIMITER $'\U2026' + + if [ ${#hook_com[branch]} -gt $POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH ] && [ ${#hook_com[branch]} -gt $POWERLEVEL9K_VCS_SHORTEN_LENGTH ]; then + case "$POWERLEVEL9K_VCS_SHORTEN_STRATEGY" in + truncate_middle) + hook_com[branch]="$(echo "${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}")$POWERLEVEL9K_VCS_SHORTEN_DELIMITER$(echo "${branch_name: -$POWERLEVEL9K_VCS_SHORTEN_LENGTH}")" + ;; + truncate_from_right) + hook_com[branch]="$(echo "${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}")$POWERLEVEL9K_VCS_SHORTEN_DELIMITER" + ;; + esac + fi + fi + hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}" # Always show the remote #if [[ -n ${remote} ]] ; then diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec index c33b564d..f6474f61 100755 --- a/test/segments/vcs.spec +++ b/test/segments/vcs.spec @@ -78,4 +78,84 @@ function testColorOverridingForUntrackedStateWorks() { unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND } +function testBranchNameTruncatingShortenLength() { + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + POWERLEVEL9K_VCS_SHORTEN_LENGTH=6 + POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3 + POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right" + + FOLDER=/tmp/powerlevel9k-test/vcs-test + mkdir -p $FOLDER + cd $FOLDER + git init 1>/dev/null + touch testfile + + assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" + + POWERLEVEL9K_VCS_SHORTEN_LENGTH=3 + assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_VCS_SHORTEN_LENGTH + unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH + unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY +} + +function testBranchNameTruncatingMinLength() { + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + POWERLEVEL9K_VCS_SHORTEN_LENGTH=3 + POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=6 + POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right" + + FOLDER=/tmp/powerlevel9k-test/vcs-test + mkdir -p $FOLDER + cd $FOLDER + git init 1>/dev/null + touch testfile + + assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" + + POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=7 + + assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_VCS_SHORTEN_LENGTH + unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH + unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY +} + +function testBranchNameTruncatingShortenStrategy() { + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + POWERLEVEL9K_VCS_SHORTEN_LENGTH=3 + POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3 + POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right" + + FOLDER=/tmp/powerlevel9k-test/vcs-test + mkdir -p $FOLDER + cd $FOLDER + git init 1>/dev/null + touch testfile + + assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)" + + POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_middle" + + assertEquals "%K{green} %F{black} mas…ter ? %k%F{green}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_VCS_SHORTEN_LENGTH + unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH + unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY +} + source shunit2/source/2.1/src/shunit2 From 2eddce2f62ec848fb8063390e7382d7d7e07a22f Mon Sep 17 00:00:00 2001 From: Alexandre ZANNI <16578570+noraj@users.noreply.github.com> Date: Thu, 12 Apr 2018 22:54:34 +0200 Subject: [PATCH 12/40] add rvm see those files and look for `rvm` + https://github.com/bhilburn/powerlevel9k/blob/master/CHANGELOG.md + https://github.com/bhilburn/powerlevel9k/blob/master/powerlevel9k.zsh-theme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 46d8ab61..5a8ae852 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ The segments that are currently available are: * [`chruby`](#chruby) - Ruby environment information using `chruby` (if one is active). * [`rbenv`](#rbenv) - Ruby environment information using `rbenv` (if one is active). * [`rspec_stats`](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. + * `rvm` - Ruby environment information using `$GEM_HOME` and `$MY_RUBY_HOME` (if one is active). * **Rust Segments:** * `rust_version` - Display the current rust version and [logo](https://www.rust-lang.org/logos/rust-logo-blk.svg). * **Swift Segments:** From 02d4e76eb4e7864a9f5ee326b6971a8407c93c4e Mon Sep 17 00:00:00 2001 From: lifehackett Date: Fri, 13 Apr 2018 08:07:43 -0600 Subject: [PATCH 13/40] Fix table formatting in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 46d8ab61..43e9cb68 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,7 @@ level. This will override the default battery icon. In order to do this, you need to define the `POWERLEVEL9k_BATTERY_STAGES` variable. | Variable | Default Value | Description | +|----------|---------------|-------------| | `POWERLEVEL9K_BATTERY_STAGES`|Unset|A string or array, which each index indicates a charge level.| Powerlevel9k will use each index of the string or array as a stage to indicate battery From cfda084eb80b76471f1b0fff5eb1332be153974f Mon Sep 17 00:00:00 2001 From: lifehackett Date: Fri, 13 Apr 2018 08:13:15 -0600 Subject: [PATCH 14/40] Another table formatting fix --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 43e9cb68..f7bab697 100644 --- a/README.md +++ b/README.md @@ -251,7 +251,9 @@ As with the battery stages, you can use any number of colors and Powerlevel9k will automatically use all of them appropriately. Some example settings: + |Brightness|Possible Array| +|----------|--------------| |Bright Colors|(196 202 208 214 220 226 190 154 118 82 46)| |Normal Colors|(124 130 136 142 148 112 76 40 34 28 22)| |Subdued Colors|( 88 94 100 106 70 34 28 22)| From c36b47b00780cf680f2133782124dcbaab5eb9a0 Mon Sep 17 00:00:00 2001 From: Kevin Chandler Date: Tue, 24 Apr 2018 16:07:20 -0700 Subject: [PATCH 15/40] Update default public ip file name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47a62c95..7a6dd49c 100644 --- a/README.md +++ b/README.md @@ -481,7 +481,7 @@ segment will not be displayed. | Variable | Default Value | Description | |----------|---------------|-------------| -|`POWERLEVEL9K_PUBLIC_IP_FILE`|'/tmp/p8k_public_ip'|This is the file your public IP is cached in.| +|`POWERLEVEL9K_PUBLIC_IP_FILE`|'/tmp/p9k_public_ip'|This is the file your public IP is cached in.| |`POWERLEVEL9K_PUBLIC_IP_HOST`|'http://ident.me'|This is the default host to get your public IP.| |`POWERLEVEL9K_PUBLIC_IP_TIMEOUT`|300|The amount of time in seconds between refreshing your cached IP.| |`POWERLEVEL9K_PUBLIC_IP_METHODS`|(dig curl wget)| These methods in that order are used to refresh your IP.| From 05f44b94bf670d9f828b44e31ecf7b90e624fab8 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Apr 2018 10:52:15 -0700 Subject: [PATCH 16/40] 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 17/40] 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. From 5fd171c33421fcea2af034e7a0083235f005b401 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Sat, 5 May 2018 13:25:29 -0400 Subject: [PATCH 18/40] Fixed prompt_rust_version to avoid grep aliases --- powerlevel9k.zsh-theme | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0e09ef03..c901103d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1104,10 +1104,14 @@ prompt_root_indicator() { # Print Rust version number prompt_rust_version() { local rust_version - rust_version=$(rustc --version 2>&1 | grep -oe "^rustc\s*[^ ]*" | grep -o '[0-9.a-z\\\-]*$') + rust_version=$(command rustc --version 2>&1) + # Remove "rustc " (including the whitespace) from the beginning + # of the version string and remove everything after the next + # whitespace. This way we'll end up with only the version. + rust_version=${${rust_version/rustc /}%% *} if [[ -n "$rust_version" ]]; then - "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "Rust $rust_version" 'RUST_ICON' + "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "$rust_version" 'RUST_ICON' fi } # RSpec test ratio From 3c27f14581086ab04bf7de9f69c24bdaf3e6de45 Mon Sep 17 00:00:00 2001 From: Tim Otlik Date: Tue, 8 May 2018 10:50:04 +0200 Subject: [PATCH 19/40] add new option "POWERLEVEL9K_BATTERY_HIDE_FULL" Hides the battery segment if percentage hits 100% --- powerlevel9k.zsh-theme | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8f06866f..0ac0b938 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -488,14 +488,27 @@ prompt_battery() { fi fi - # override the default color if we are using a color level array - if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then - local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) - local offset=$(( ($bat_percent / $segment) + 1 )) - "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + if [[ -v "POWERLEVEL9K_BATTERY_HIDE_FULL" && "$POWERLEVEL9K_BATTERY_HIDE_FULL" == true ]]; then + if [[ "$bat_percent" != "100" ]]; then + if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) + local offset=$(( ($bat_percent / $segment) + 1 )) + "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + else + # Draw the prompt_segment + "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + fi + fi else - # Draw the prompt_segment - "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + # override the default color if we are using a color level array + if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) + local offset=$(( ($bat_percent / $segment) + 1 )) + "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + else + # Draw the prompt_segment + "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + fi fi } From 642034eef2b455aa75819e4c394cd4416206665b Mon Sep 17 00:00:00 2001 From: Tim Otlik Date: Wed, 9 May 2018 10:18:06 +0200 Subject: [PATCH 20/40] remove duplicate code in battery segment --- powerlevel9k.zsh-theme | 49 +++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0ac0b938..45d0cc25 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -488,28 +488,19 @@ prompt_battery() { fi fi - if [[ -v "POWERLEVEL9K_BATTERY_HIDE_FULL" && "$POWERLEVEL9K_BATTERY_HIDE_FULL" == true ]]; then - if [[ "$bat_percent" != "100" ]]; then - if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then - local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) - local offset=$(( ($bat_percent / $segment) + 1 )) - "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" - else - # Draw the prompt_segment - "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" - fi - fi - else - # override the default color if we are using a color level array - if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then - local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) - local offset=$(( ($bat_percent / $segment) + 1 )) - "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" - else - # Draw the prompt_segment - "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" - fi + if [[ "${POWERLEVEL9K_BATTERY_HIDE_FULL}" == "true" && "${bat_percent}" = 100 ]]; then + return fi + + # override the default color if we are using a color level array + if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) + local offset=$(( ($bat_percent / $segment) + 1 )) + "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + else + # Draw the prompt_segment + "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + fi } ################################################################ @@ -650,14 +641,14 @@ prompt_user() { "FOREGROUND_COLOR" "yellow" "VISUAL_IDENTIFIER" "ROOT_ICON" ) - elif sudo -n true 2>/dev/null; then - user_state=( - "STATE" "SUDO" - "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" - "BACKGROUND_COLOR" "${DEFAULT_COLOR}" - "FOREGROUND_COLOR" "yellow" - "VISUAL_IDENTIFIER" "SUDO_ICON" - ) + elif sudo -n true 2>/dev/null; then + user_state=( + "STATE" "SUDO" + "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "SUDO_ICON" + ) else user_state=( "STATE" "DEFAULT" From 238b231c3e9f76f5f2d50b2deab3696a99e2340e Mon Sep 17 00:00:00 2001 From: Tim Otlik Date: Wed, 9 May 2018 10:21:13 +0200 Subject: [PATCH 21/40] rename variable to POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD Variable now holds an integer, if your battery status is greater or equal to this integer the segment will be hidden --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 45d0cc25..4924d269 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -488,7 +488,7 @@ prompt_battery() { fi fi - if [[ "${POWERLEVEL9K_BATTERY_HIDE_FULL}" == "true" && "${bat_percent}" = 100 ]]; then + if [[ -v "POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD" && "${bat_percent}" -ge $POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ]]; then return fi From 9b0e0c786af71048c3f615e99de079d7ff86266e Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Wed, 9 May 2018 23:37:32 -0400 Subject: [PATCH 22/40] Removed 'Rust' text from test; Silenced missing rustc warning --- powerlevel9k.zsh-theme | 2 +- test/segments/rust_version.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c901103d..530b0d9a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1104,7 +1104,7 @@ prompt_root_indicator() { # Print Rust version number prompt_rust_version() { local rust_version - rust_version=$(command rustc --version 2>&1) + rust_version=$(command rustc --version 2>/dev/null) # Remove "rustc " (including the whitespace) from the beginning # of the version string and remove everything after the next # whitespace. This way we'll end up with only the version. diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 49b06bcf..8274789f 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -19,7 +19,7 @@ function testRust() { alias rustc=mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) - assertEquals "%K{208} %F{black}Rust 0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" + assertEquals "%K{208} %F{black}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias rustc From 7ab9cb150ecaef0d5fe906b9ef490b4e7c4f097d Mon Sep 17 00:00:00 2001 From: Tim Otlik Date: Sat, 12 May 2018 01:22:48 +0200 Subject: [PATCH 23/40] add comment line above battery-threshold condition --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4924d269..8e6bf9ad 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -487,7 +487,7 @@ prompt_battery() { [[ "${(t)POWERLEVEL9K_BATTERY_STAGES}" =~ "array" ]] && POWERLEVEL9K_BATTERY_ICON="$POWERLEVEL9K_BATTERY_STAGES[$offset]" || POWERLEVEL9K_BATTERY_ICON=${POWERLEVEL9K_BATTERY_STAGES:$offset:1} fi fi - + # return if POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD is set and the battery percentage is greater or equal if [[ -v "POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD" && "${bat_percent}" -ge $POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ]]; then return fi From 27bd1cd65df8878812adefcf1ab6974660c2714d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 12 May 2018 23:17:49 +0200 Subject: [PATCH 24/40] Fix test for rust segment --- powerlevel9k.zsh-theme | 1 + test/segments/rust_version.spec | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 530b0d9a..2b21b3de 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1114,6 +1114,7 @@ prompt_rust_version() { "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "$rust_version" 'RUST_ICON' fi } + # RSpec test ratio prompt_rspec_stats() { if [[ (-d app && -d spec) ]]; then diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 8274789f..85b4ec69 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -5,28 +5,39 @@ setopt shwordsplit SHUNIT_PARENT=$0 +TEST_BASE_FOLDER=/tmp/powerlevel9k-test +RUST_TEST_FOLDER="${TEST_BASE_FOLDER}/rust-test" + function setUp() { + OLDPATH="${PATH}" + mkdir -p "${RUST_TEST_FOLDER}" + PATH="${RUST_TEST_FOLDER}:${PATH}" + export TERM="xterm-256color" # Load Powerlevel9k source powerlevel9k.zsh-theme } +function tearDown() { + PATH="${OLDPATH}" + rm -fr "${TEST_BASE_FOLDER}" +} + function mockRust() { - echo 'rustc 0.4.1a-alpha' + echo "#!/bin/sh\n\necho 'rustc 0.4.1a-alpha'" > "${RUST_TEST_FOLDER}/rustc" + chmod +x "${RUST_TEST_FOLDER}/rustc" } function testRust() { - alias rustc=mockRust + mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) assertEquals "%K{208} %F{black}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unalias rustc } function testRustPrintsNothingIfRustIsNotAvailable() { - alias rustc=noRust POWERLEVEL9K_CUSTOM_WORLD='echo world' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version) @@ -34,7 +45,6 @@ function testRustPrintsNothingIfRustIsNotAvailable() { unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_CUSTOM_WORLD - unalias rustc } source shunit2/source/2.1/src/shunit2 From 557f5993ea7c8ae1fb196bcb21c4e9fd9dee26ce Mon Sep 17 00:00:00 2001 From: Tim Otlik Date: Thu, 17 May 2018 12:08:04 +0200 Subject: [PATCH 25/40] add cog symbol to dir segment if folder is /etc* --- functions/icons.zsh | 5 +++++ powerlevel9k.zsh-theme | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index f758d55c..742d8d36 100755 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -71,6 +71,7 @@ case $POWERLEVEL9K_MODE in HOME_SUB_ICON $'\uE18D' #  FOLDER_ICON $'\uE818' #  NETWORK_ICON $'\uE1AD' #  + ETC_ICON $'\uE818' #  LOAD_ICON $'\uE190 ' #  SWAP_ICON $'\uE87D' #  RAM_ICON $'\uE1E2 ' #  @@ -167,6 +168,7 @@ case $POWERLEVEL9K_MODE in HOME_ICON $'\uF015' #  HOME_SUB_ICON $'\uF07C' #  FOLDER_ICON $'\uF115' #  + ETC_ICON $'\uF013' #  NETWORK_ICON $'\uF09E' #  LOAD_ICON $'\uF080 ' #  SWAP_ICON $'\uF0E4' #  @@ -266,6 +268,7 @@ case $POWERLEVEL9K_MODE in HOME_ICON '\u'$CODEPOINT_OF_AWESOME_HOME #  HOME_SUB_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_OPEN #  FOLDER_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_O #  + ETC_ICON $'\uF013' #  NETWORK_ICON '\u'$CODEPOINT_OF_AWESOME_RSS #  LOAD_ICON '\u'$CODEPOINT_OF_AWESOME_BAR_CHART' ' #  SWAP_ICON '\u'$CODEPOINT_OF_AWESOME_DASHBOARD #  @@ -359,6 +362,7 @@ case $POWERLEVEL9K_MODE in HOME_ICON $'\uF015' #  HOME_SUB_ICON $'\uF07C' #  FOLDER_ICON $'\uF115' #  + ETC_ICON $'\uF013' #  NETWORK_ICON $'\uF1EB' #  LOAD_ICON $'\uF080 ' #  SWAP_ICON $'\uF464' #  @@ -452,6 +456,7 @@ case $POWERLEVEL9K_MODE in HOME_ICON '' HOME_SUB_ICON '' FOLDER_ICON '' + ETC_ICON $'\uF013' #  NETWORK_ICON 'IP' LOAD_ICON 'L' SWAP_ICON 'SWP' diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8f06866f..b6493fed 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -909,10 +909,13 @@ prompt_dir() { "HOME" "HOME_ICON" "HOME_SUBFOLDER" "HOME_SUB_ICON" "NOT_WRITABLE" "LOCK_ICON" + "ETC" "ETC_ICON" ) local state_path="$(print -P '%~')" local current_state="DEFAULT" - if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then + if [[ $state_path == '/etc'* ]]; then + current_state='ETC' + elif [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then current_state="NOT_WRITABLE" elif [[ $state_path == '~' ]]; then current_state="HOME" From fcea56be5c3da7db8c2c37f143d837eb9fa4986b Mon Sep 17 00:00:00 2001 From: Max O'Cull Date: Fri, 18 May 2018 20:12:05 -0400 Subject: [PATCH 26/40] Fix Linux distribution detection --- functions/utilities.zsh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 9a651a0b..61f8cd77 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -106,58 +106,58 @@ case $(uname) in OS='Linux' os_release_id="$(grep -E '^ID=([a-zA-Z]*)' /etc/os-release | cut -d '=' -f 2)" case "$os_release_id" in - "arch") + *arch*) OS_ICON=$(print_icon 'LINUX_ARCH_ICON') ;; - "debian") + *debian*) OS_ICON=$(print_icon 'LINUX_DEBIAN_ICON') ;; - "ubuntu") + *ubuntu*) OS_ICON=$(print_icon 'LINUX_UBUNTU_ICON') ;; - "elementary") + *elementary*) OS_ICON=$(print_icon 'LINUX_ELEMENTARY_ICON') ;; - "fedora") + *fedora*) OS_ICON=$(print_icon 'LINUX_FEDORA_ICON') ;; - "coreos") + *coreos*) OS_ICON=$(print_icon 'LINUX_COREOS_ICON') ;; - "gentoo") + *gentoo*) OS_ICON=$(print_icon 'LINUX_GENTOO_ICON') ;; - "mageia") + *mageia*) OS_ICON=$(print_icon 'LINUX_MAGEIA_ICON') ;; - "centos") + *centos*) OS_ICON=$(print_icon 'LINUX_CENTOS_ICON') ;; - "opensuse"|"tumbleweed") + *opensuse*|*tumbleweed*) OS_ICON=$(print_icon 'LINUX_OPENSUSE_ICON') ;; - "sabayon") + *sabayon*) OS_ICON=$(print_icon 'LINUX_SABAYON_ICON') ;; - "slackware") + *slackware*) OS_ICON=$(print_icon 'LINUX_SLACKWARE_ICON') ;; - "linuxmint") + *linuxmint*) OS_ICON=$(print_icon 'LINUX_MINT_ICON') ;; - "alpine") + *alpine*) OS_ICON=$(print_icon 'LINUX_ALPINE_ICON') ;; - "aosc") + *aosc*) OS_ICON=$(print_icon 'LINUX_AOSC_ICON') ;; - "nixos") + *nixos*) OS_ICON=$(print_icon 'LINUX_NIXOS_ICON') ;; - "devuan") + *devuan*) OS_ICON=$(print_icon 'LINUX_DEVUAN_ICON') ;; - "manjaro") + *manjaro*) OS_ICON=$(print_icon 'LINUX_MANJARO_ICON') ;; *) From 37cbc9a02d16b1d152dcc2c6af51214d316639d3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 26 May 2018 00:27:36 +0200 Subject: [PATCH 27/40] Fix RPROMPT placement This fixes #841 --- powerlevel9k.zsh-theme | 2 +- test/powerlevel9k.spec | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8f06866f..e201d35c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1740,7 +1740,7 @@ $(print_icon 'MULTILINE_LAST_PROMPT_PREFIX')' fi if [[ "$POWERLEVEL9K_DISABLE_RPROMPT" != true ]]; then - RPROMPT='$RPROMPT_PREFIX%f%b%k$(build_right_prompt)%{$reset_color%}$RPROMPT_SUFFIX' + RPROMPT="${RPROMPT_PREFIX}"'%f%b%k$(build_right_prompt)%{$reset_color%}'"${RPROMPT_SUFFIX}" fi local NEWLINE=' diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 5f6b6f27..4178a4f6 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -114,4 +114,23 @@ function testOverwritingIconsWork() { # rm -fr ~/$testFolder } +function testNewlineOnRpromptCanBeDisabled() { + POWERLEVEL9K_PROMPT_ON_NEWLINE=true + POWERLEVEL9K_RPROMPT_ON_NEWLINE=false + POWERLEVEL9K_CUSTOM_WORLD='echo world' + POWERLEVEL9K_CUSTOM_RWORLD='echo rworld' + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_rworld) + + powerlevel9k_prepare_prompts + assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld ' "$(print -P ${PROMPT}${RPROMPT})" + + unset POWERLEVEL9K_PROMPT_ON_NEWLINE + unset POWERLEVEL9K_RPROMPT_ON_NEWLINE + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + unset POWERLEVEL9K_CUSTOM_WORLD + unset POWERLEVEL9K_CUSTOM_RWORLD +} + source shunit2/source/2.1/src/shunit2 From 2f95fd04d94a5b2fed33f17ecd1c1d7bab5ad44a Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Fri, 1 Jun 2018 11:49:23 -0400 Subject: [PATCH 28/40] Fix icons cut off in some terminal emulators --- powerlevel9k.zsh-theme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0e09ef03..836d4ae0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -156,12 +156,12 @@ left_prompt_segment() { if [[ -n $6 ]]; then visual_identifier="$(print_icon $6)" if [[ -n "$visual_identifier" ]]; then + # Add an whitespace if we print more than just the visual identifier + [[ -n "$5" ]] && visual_identifier="$visual_identifier " # Allow users to overwrite the color for the visual identifier only. local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR set_default $visual_identifier_color_variable $4 visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" - # Add an whitespace if we print more than just the visual identifier - [[ -n "$5" ]] && visual_identifier="$visual_identifier " fi fi @@ -240,12 +240,12 @@ right_prompt_segment() { if [[ -n "$6" ]]; then visual_identifier="$(print_icon $6)" if [[ -n "$visual_identifier" ]]; then + # Add an whitespace if we print more than just the visual identifier + [[ -n "$5" ]] && visual_identifier=" $visual_identifier" # Allow users to overwrite the color for the visual identifier only. local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR set_default $visual_identifier_color_variable $4 visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" - # Add an whitespace if we print more than just the visual identifier - [[ -n "$5" ]] && visual_identifier=" $visual_identifier" fi fi From 5e0b92434660ed73894b41a8a586c22c30830552 Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Fri, 1 Jun 2018 13:34:52 -0400 Subject: [PATCH 29/40] Update unit tests for fixing icons cut off --- test/powerlevel9k.spec | 6 +++--- test/segments/command_execution_time.spec | 12 ++++++------ test/segments/dir.spec | 10 +++++----- test/segments/go_version.spec | 2 +- test/segments/kubecontext.spec | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 5f6b6f27..99b3ea17 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -65,7 +65,7 @@ function testDynamicColoringOfVisualIdentifiersWork() { cd /tmp - assertEquals "%K{blue} %F{green%}icon-here%f %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{green%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -86,7 +86,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { cd /tmp - assertEquals "%K{yellow} %F{green%}icon-here%f %F{red}/tmp %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{green%}icon-here %f%F{red}/tmp %k%F{yellow}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -106,7 +106,7 @@ function testOverwritingIconsWork() { #cd ~/$testFolder cd /tmp - assertEquals "%K{blue} %F{black%}icon-here%f %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_FOLDER_ICON diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec index 09738859..66d2dc1d 100755 --- a/test/segments/command_execution_time.spec +++ b/test/segments/command_execution_time.spec @@ -28,7 +28,7 @@ function testCommandExecutionTimeThresholdCouldBeChanged() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 _P9K_COMMAND_DURATION=2.03 - assertEquals "%K{red} %F{226%}Dur%f %F{226}2.03 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{226%}Dur %f%F{226}2.03 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -40,7 +40,7 @@ function testCommandExecutionTimeThresholdCouldBeSetToZero() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 _P9K_COMMAND_DURATION=0.03 - assertEquals "%K{red} %F{226%}Dur%f %F{226}0.03 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{226%}Dur %f%F{226}0.03 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -53,7 +53,7 @@ function testCommandExecutionTimePrecisionCouldBeChanged() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 _P9K_COMMAND_DURATION=0.0001 - assertEquals "%K{red} %F{226%}Dur%f %F{226}0.0001 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{226%}Dur %f%F{226}0.0001 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -66,7 +66,7 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 _P9K_COMMAND_DURATION=23.5001 - assertEquals "%K{red} %F{226%}Dur%f %F{226}23 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{226%}Dur %f%F{226}23 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -77,7 +77,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) _P9K_COMMAND_DURATION=180 - assertEquals "%K{red} %F{226%}Dur%f %F{226}03:00 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{226%}Dur %f%F{226}03:00 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -87,7 +87,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) _P9K_COMMAND_DURATION=7200 - assertEquals "%K{red} %F{226%}Dur%f %F{226}02:00:00 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{226%}Dur %f%F{226}02:00:00 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 97bc857c..fdaf6a31 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -265,7 +265,7 @@ function testHomeFolderDetectionWorks() { POWERLEVEL9K_HOME_ICON='home-icon' cd ~ - assertEquals "%K{blue} %F{black%}home-icon%f %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_HOME_ICON @@ -277,7 +277,7 @@ function testHomeSubfolderDetectionWorks() { FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}sub-icon%f %F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}sub-icon %f%F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -291,7 +291,7 @@ function testOtherFolderDetectionWorks() { FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -343,7 +343,7 @@ function testOmittingFirstCharacterWorks() { POWERLEVEL9K_FOLDER_ICON='folder-icon' cd /tmp - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_FOLDER_ICON @@ -357,7 +357,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec index 2aac460b..b434dce5 100755 --- a/test/segments/go_version.spec +++ b/test/segments/go_version.spec @@ -40,7 +40,7 @@ function testGo() { PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k" - assertEquals "%K{green} %F{255%}%f %F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)" + assertEquals "%K{green} %F{255%} %f%F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)" unset POWERLEVEL9K_GO_ICON unset PWD diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec index eaaa2300..abcfec07 100755 --- a/test/segments/kubecontext.spec +++ b/test/segments/kubecontext.spec @@ -51,7 +51,7 @@ function testKubeContext() { alias kubectl=mockKubectl POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) - assertEquals "%K{magenta} %F{white%}⎈%f %F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" + assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl @@ -60,7 +60,7 @@ function testKubeContextOtherNamespace() { alias kubectl=mockKubectlOtherNamespace POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) - assertEquals "%K{magenta} %F{white%}⎈%f %F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" + assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl From 9c4203bdf80440b43b5f559b5d8856f6b817ad9e Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Fri, 1 Jun 2018 14:18:18 -0400 Subject: [PATCH 30/40] Add comments about the whitespace and coloring --- powerlevel9k.zsh-theme | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 836d4ae0..b8d4b0cc 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -156,7 +156,9 @@ left_prompt_segment() { if [[ -n $6 ]]; then visual_identifier="$(print_icon $6)" if [[ -n "$visual_identifier" ]]; then - # Add an whitespace if we print more than just the visual identifier + # Add an whitespace if we print more than just the visual identifier. + # To avoid cutting off the visual identifier in some terminal emulators (e.g., Konsole, st), + # we need to color both the visual identifier and the whitespace. [[ -n "$5" ]] && visual_identifier="$visual_identifier " # Allow users to overwrite the color for the visual identifier only. local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR @@ -240,7 +242,9 @@ right_prompt_segment() { if [[ -n "$6" ]]; then visual_identifier="$(print_icon $6)" if [[ -n "$visual_identifier" ]]; then - # Add an whitespace if we print more than just the visual identifier + # Add an whitespace if we print more than just the visual identifier. + # To avoid cutting off the visual identifier in some terminal emulators (e.g., Konsole, st), + # we need to color both the visual identifier and the whitespace. [[ -n "$5" ]] && visual_identifier=" $visual_identifier" # Allow users to overwrite the color for the visual identifier only. local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR From a2d8cccd098bc1f739c324623bdabb701e65ba90 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 1 May 2018 02:10:26 +0200 Subject: [PATCH 31/40] Add a Laravel version segment --- CHANGELOG.md | 6 ++++++ README.md | 1 + functions/icons.zsh | 5 +++++ powerlevel9k.zsh-theme | 12 ++++++++++++ 4 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a8842a3..e7e61af6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## next + +### New Segment: `laravel_version` + +Displays the current laravel version. + ## v0.6.4 - `load` segment now has configurable averages. diff --git a/README.md b/README.md index 9b86067f..1e01e915 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,7 @@ The segments that are currently available are: * `nvm` - Show the version of Node that is currently active, if it differs from the version used by NVM * **PHP Segments:** * `php_version` - Show the current PHP version. + * `laravel_version` - Show the current Laravel version. * [`symfony2_tests`](#symfony2_tests) - Show a ratio of test classes vs code classes for Symfony2. * `symfony2_version` - Show the current Symfony2 version, if you are in a Symfony2-Project dir. * **Python Segments:** diff --git a/functions/icons.zsh b/functions/icons.zsh index 1f90e94f..98c6f13d 100755 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -111,6 +111,7 @@ case $POWERLEVEL9K_MODE in DATE_ICON $'\uE184' #  TIME_ICON $'\uE12E' #  JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' ) ;; 'awesome-fontconfig') @@ -206,6 +207,7 @@ case $POWERLEVEL9K_MODE in DATE_ICON $'\uF073 ' #  TIME_ICON $'\uF017 ' #  JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' ) ;; 'awesome-mapped-fontconfig') @@ -306,6 +308,7 @@ case $POWERLEVEL9K_MODE in DATE_ICON $'\uF073 ' #  TIME_ICON $'\uF017 ' #  JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -402,6 +405,7 @@ case $POWERLEVEL9K_MODE in DATE_ICON $'\uF073 ' #  TIME_ICON $'\uF017 ' #  JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON $'\ue73f ' #  ) ;; *) @@ -497,6 +501,7 @@ case $POWERLEVEL9K_MODE in DATE_ICON '' TIME_ICON '' JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' ) ;; esac diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b9119d4c..dde838d9 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1109,6 +1109,18 @@ prompt_vpn_ip() { done } +################################################################ +# Segment to display laravel version +prompt_laravel_version() { + local laravel_version="$(php artisan --version 2>/dev/null)" + if [[ -n "${laravel_version}" ]]; then + # Remove unrelevant infos + laravel_version="${laravel_version//Laravel Framework version /}" + + "$1_prompt_segment" "$0" "$2" "maroon" "white" "${laravel_version}" 'LARAVEL_ICON' + fi +} + ################################################################ # Segment to display load set_default POWERLEVEL9K_LOAD_WHICH 5 From 0257159e1ef634f2ccd7121b1c93f359fae07e46 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 1 May 2018 02:15:37 +0200 Subject: [PATCH 32/40] Add tests for laravel version segment to travis --- .travis.yml | 1 + test/segments/laravel_version.spec | 69 ++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 test/segments/laravel_version.spec diff --git a/.travis.yml b/.travis.yml index e0ad5a93..648499ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,3 +29,4 @@ script: - test/segments/go_version.spec - test/segments/vcs.spec - test/segments/kubecontext.spec + - test/segments/laravel_version.spec diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec new file mode 100755 index 00000000..bebbfcfc --- /dev/null +++ b/test/segments/laravel_version.spec @@ -0,0 +1,69 @@ +#!/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 mockLaravelVersion() { + case "$1" in + "artisan") + echo "Laravel Framework version 5.4.23" + ;; + default) + esac +} + +function mockNoLaravelVersion() { + # This should output some error + >&2 echo "Artisan not available" + return 1 +} + +function testLaravelVersionSegment() { + alias php=mockLaravelVersion + POWERLEVEL9K_LARAVEL_ICON='x' + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version) + + assertEquals "%K{001} %F{white%}x%f %F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_LARAVEL_ICON + unalias php +} + +function testLaravelVersionSegmentIfArtisanIsNotAvailable() { + alias php=mockNoLaravelVersion + POWERLEVEL9K_CUSTOM_WORLD='echo world' + POWERLEVEL9K_LARAVEL_ICON='x' + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) + + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_LARAVEL_ICON + unset POWERLEVEL9K_CUSTOM_WORLD + unalias php +} + +function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() { + alias php=noPhp + POWERLEVEL9K_CUSTOM_WORLD='echo world' + POWERLEVEL9K_LARAVEL_ICON='x' + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) + + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_LARAVEL_ICON + unset POWERLEVEL9K_CUSTOM_WORLD + unalias php +} + +source shunit2/source/2.1/src/shunit2 From dc21b973350a1ebc0a6ff1699e2d8439a9f8820c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 7 Jun 2018 02:01:36 +0200 Subject: [PATCH 33/40] Fix travis build --- powerlevel9k.zsh-theme | 3 ++- test/segments/laravel_version.spec | 2 +- test/segments/rust_version.spec | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dde838d9..59178708 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1307,7 +1307,8 @@ prompt_root_indicator() { ################################################################ # Segment to display Rust version number prompt_rust_version() { - local rust_version=$(command rustc --version 2>/dev/null) + local rust_version + rust_version=$(command rustc --version 2>/dev/null) # Remove "rustc " (including the whitespace) from the beginning # of the version string and remove everything after the next # whitespace. This way we'll end up with only the version. diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec index bebbfcfc..40b130d2 100755 --- a/test/segments/laravel_version.spec +++ b/test/segments/laravel_version.spec @@ -31,7 +31,7 @@ function testLaravelVersionSegment() { POWERLEVEL9K_LARAVEL_ICON='x' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version) - assertEquals "%K{001} %F{white%}x%f %F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{white%}x %f%F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_LARAVEL_ICON diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 2a344f64..34883a10 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -32,7 +32,7 @@ function testRust() { mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) - assertEquals "%K{208} %F{black%}Rust%f %F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)" + assertEquals "%K{208} %F{black%}Rust %f%F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } From 51b53cd4b5e715ae148ba588ea573491cdcc17c5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 9 Jun 2018 14:37:56 +0200 Subject: [PATCH 34/40] Fix `rbenv` segment after merge --- powerlevel9k.zsh-theme | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 59178708..730cff49 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1262,12 +1262,13 @@ prompt_rbenv() { local rbenv_version_name="$(rbenv version-name)" local rbenv_global="$(rbenv global)" - # Don't show anything if the current Ruby is the same as the global Ruby # unless `POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW` is set. if [[ $rbenv_version_name == $rbenv_global && "$POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW" = false ]]; then return fi + + "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON' fi } From b7681a00cab4b5eb672163b4a76695716dd83e56 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 11 Jun 2018 08:38:30 +0200 Subject: [PATCH 35/40] Fix variable in README - Fix the variable name for the VCS shorten strategy. - Add a heading for VCS truncation. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e01e915..90680ac8 100644 --- a/README.md +++ b/README.md @@ -660,6 +660,8 @@ from the [Installation](#Installation) section above. | None | None | ![icon_git](https://cloud.githubusercontent.com/assets/1544760/7976092/b5909f80-0a76-11e5-9950-1438b9d72465.gif) | Repository is a git repository | None | None | ![icon_mercurial](https://cloud.githubusercontent.com/assets/1544760/7976090/b5908da6-0a76-11e5-8c91-452b6e73f631.gif) | Repository is a Mercurial repository +##### vcs truncation + You can limit the branch name to a certain length by truncating long names. Customizations available are: @@ -679,7 +681,7 @@ For example, if you want to truncate `1234-super_super_long_branch_name` to `123 ```zsh POWERLEVEL9K_VCS_SHORTEN_LENGTH=4 POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=11 -POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" +POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right" POWERLEVEL9K_VCS_SHORTEN_DELIMITER=".." ``` From 3989834bfef217115dc2ceb20cfbd6f3ac717756 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 14 Jun 2018 21:41:13 -0600 Subject: [PATCH 36/40] Hide one-space indent at right margin ZSH displays the right prompt indented one space from the right margin. This can be tweaked with ZLE_RPROMPT_INDENT=0, but that makes display problems very likely and I don't recommend it. But all is not lost. The %E prompt format does continue the current background color through that last indent space. So it can *look* like our prompt goes right up to the margin, if: 1) We remove the trailing space from the last segment, and 2) We add %E before clearing the background color --- powerlevel9k.zsh-theme | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0e09ef03..61dfdba0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -222,6 +222,12 @@ right_prompt_segment() { [[ -n "$4" ]] && fg="%F{$4}" || fg="%f" # If CURRENT_RIGHT_BG is "NONE", we are the first right segment. + + if [[ "$CURRENT_RIGHT_BG" != "NONE" ]]; then + # This is the closing whitespace for the previous segment + echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}%f" + fi + if [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]]; then if isSameColor "$CURRENT_RIGHT_BG" "$3"; then # Middle segment with same color as previous segment @@ -257,7 +263,7 @@ right_prompt_segment() { # Print segment content if there is any [[ -n "$5" ]] && echo -n "${5}" # Print the visual identifier - echo -n "${visual_identifier}${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}%f" + echo -n "${visual_identifier}" CURRENT_RIGHT_BG=$3 last_right_element_index=$current_index @@ -1484,6 +1490,9 @@ build_right_prompt() { index=$((index + 1)) done + + # Clear to the end of the line + echo -n "%E" } powerlevel9k_preexec() { From d09a46f9e017541dc350dc44bf519d3d77ccd4e4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 17 Jun 2018 22:47:43 +0200 Subject: [PATCH 37/40] Mute errors when asking for java version --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 730cff49..0a6cc055 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1707,7 +1707,7 @@ prompt_dropbox() { # print Java version number prompt_java_version() { local java_version - java_version=$(java -fullversion 2>&1 | cut -d '"' -f 2) + java_version=$(java -fullversion 2>/dev/null | cut -d '"' -f 2) if [[ -n "$java_version" ]]; then "$1_prompt_segment" "$0" "$2" "red" "white" "$java_version" "JAVA_ICON" From 595bdb4fa35a4dcd424a74297cbae1ee8a20df7a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 17 Jun 2018 22:57:13 +0200 Subject: [PATCH 38/40] Use cog glyph on all modes --- functions/icons.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index 98c6f13d..358f9580 100755 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -71,7 +71,7 @@ case $POWERLEVEL9K_MODE in HOME_SUB_ICON $'\uE18D' #  FOLDER_ICON $'\uE818' #  NETWORK_ICON $'\uE1AD' #  - ETC_ICON $'\uE818' #  + ETC_ICON $'\uE82F' #  LOAD_ICON $'\uE190 ' #  SWAP_ICON $'\uE87D' #  RAM_ICON $'\uE1E2 ' #  @@ -170,7 +170,7 @@ case $POWERLEVEL9K_MODE in HOME_ICON $'\uF015' #  HOME_SUB_ICON $'\uF07C' #  FOLDER_ICON $'\uF115' #  - ETC_ICON $'\uF013' #  + ETC_ICON $'\uF013 ' #  NETWORK_ICON $'\uF09E' #  LOAD_ICON $'\uF080 ' #  SWAP_ICON $'\uF0E4' #  @@ -272,7 +272,7 @@ case $POWERLEVEL9K_MODE in HOME_ICON '\u'$CODEPOINT_OF_AWESOME_HOME #  HOME_SUB_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_OPEN #  FOLDER_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_O #  - ETC_ICON $'\uF013' #  + ETC_ICON '\u'$CODEPOINT_OF_AWESOME_COG' ' #  NETWORK_ICON '\u'$CODEPOINT_OF_AWESOME_RSS #  LOAD_ICON '\u'$CODEPOINT_OF_AWESOME_BAR_CHART' ' #  SWAP_ICON '\u'$CODEPOINT_OF_AWESOME_DASHBOARD #  @@ -464,7 +464,7 @@ case $POWERLEVEL9K_MODE in HOME_ICON '' HOME_SUB_ICON '' FOLDER_ICON '' - ETC_ICON $'\uF013' #  + ETC_ICON $'\u2699' # ⚙ NETWORK_ICON 'IP' LOAD_ICON 'L' SWAP_ICON 'SWP' From 8c0df73d81149ac3346e4ced3dd769db1d05b74a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 20 Jun 2018 21:44:12 +0200 Subject: [PATCH 39/40] Fix tests --- test/powerlevel9k.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 16043d00..0ddf36c1 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -123,7 +123,7 @@ function testNewlineOnRpromptCanBeDisabled() { POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_rworld) powerlevel9k_prepare_prompts - assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld ' "$(print -P ${PROMPT}${RPROMPT})" + assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})" unset POWERLEVEL9K_PROMPT_ON_NEWLINE unset POWERLEVEL9K_RPROMPT_ON_NEWLINE From bda3171237e83ab7fd47d5b2fa6c2d3f44f02e92 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 20 Jun 2018 22:55:14 +0200 Subject: [PATCH 40/40] Fix java_version segment --- powerlevel9k.zsh-theme | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 05a75489..ff3a9466 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1713,7 +1713,12 @@ prompt_dropbox() { # print Java version number prompt_java_version() { local java_version - java_version=$(java -fullversion 2>/dev/null | cut -d '"' -f 2) + # Stupid: Java prints its version on STDERR. + # The first version ouput will print nothing, we just + # use it to transport whether the command was successful. + # If yes, we parse the version string (and need to + # redirect the stderr to stdout to make the pipe work). + java_version=$(java -version 2>/dev/null && java -fullversion 2>&1 | cut -d '"' -f 2) if [[ -n "$java_version" ]]; then "$1_prompt_segment" "$0" "$2" "red" "white" "$java_version" "JAVA_ICON"