diff options
-rw-r--r-- | README.md | 21 | ||||
-rwxr-xr-x | functions/colors.zsh | 6 | ||||
-rwxr-xr-x | functions/utilities.zsh | 1 | ||||
-rwxr-xr-x | functions/vcs.zsh | 30 | ||||
-rwxr-xr-x | powerlevel9k.zsh-theme | 36 | ||||
-rwxr-xr-x | test/segments/dir.spec | 21 |
6 files changed, 78 insertions, 37 deletions
@@ -130,6 +130,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:** @@ -213,8 +214,10 @@ 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 @@ -254,10 +257,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|(red1 orangered1 darkorange orange1 gold1 yellow1 yellow2 greenyellow chartreuse1 chartreuse2 green1)| -|Normal Colors|(red3 darkorange3 darkgoldenrod gold3 yellow3 chartreuse2 mediumspringgreen green3 green3 green4 darkgreen)| -|Subdued Colors|(darkred orange4 yellow4 yellow4 chartreuse3 green3 green4 darkgreen)| + +| Brightness | Possible Array | +|----------------|---------------------------------------------------------------------------------------------------------------| +| Bright Colors | `(red1 orangered1 darkorange orange1 gold1 yellow1 yellow2 greenyellow chartreuse1 chartreuse2 green1)` | +| Normal Colors | `(red3 darkorange3 darkgoldenrod gold3 yellow3 chartreuse2 mediumspringgreen green3 green3 green4 darkgreen)` | +| Subdued Colors | `(darkred orange4 yellow4 yellow4 chartreuse3 green3 green4 darkgreen)` | ##### command_execution_time @@ -538,6 +543,10 @@ Variable | Default Value | Description | |----------|---------------|-------------| |`POWERLEVEL9K_RBENV_ALWAYS`|'false'|Always show the `rbenv` segment, even if the local version matches the global.| +| 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. diff --git a/functions/colors.zsh b/functions/colors.zsh index f421165c..e98bfd4f 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -35,11 +35,11 @@ function getColor() { fi else # named color added to parameter expansion print -P to test if the name exists in terminal - named="%K{$1}" + local named="%K{$1}" # https://misc.flogisoft.com/bash/tip_colors_and_formatting - default="$'\033'\[49m" + local default="$'\033'\[49m" # http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html - quoted=$(printf "%q" $(print -P "$named")) + local quoted=$(printf "%q" $(print -P "$named")) if [[ $quoted = "$'\033'\[49m" && $1 != "black" ]]; then # color not found, so try to get the code 1=$(getColorCode $1) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 0f33a1b0..9a651a0b 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -39,6 +39,7 @@ printSizeHumanReadable() { # if the base is not Bytes if [[ -n $2 ]]; then + local idx for idx in "${extension[@]}"; do if [[ "$2" == "$idx" ]]; then break diff --git a/functions/vcs.zsh b/functions/vcs.zsh index c936f27d..b99e7c86 100755 --- 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) if [[ -n "$POWERLEVEL9K_VCS_SHORTEN_LENGTH" ]] && [[ -n "$POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH" ]]; then set_default POWERLEVEL9K_VCS_SHORTEN_DELIMITER $'\U2026' @@ -80,18 +80,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. @@ -106,8 +106,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 } @@ -126,7 +126,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 diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8379f68a..436398c0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -278,7 +278,7 @@ CURRENT_BG='NONE' prompt_anaconda() { # Depending on the conda version, either might be set. This # variant works even if both are set. - _path=$CONDA_ENV_PATH$CONDA_PREFIX + local _path=$CONDA_ENV_PATH$CONDA_PREFIX if ! [ -z "$_path" ]; then # config - can be overwritten in users' zshrc file. set_default POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "(" @@ -895,7 +895,9 @@ prompt_dir() { fi ;; *) - 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 @@ -921,7 +923,7 @@ prompt_dir() { fi # declare variables used for bold and state colors - local bld dir_state_foreground dir_state_user_foreground + local bld_on bld_off dir_state_foreground dir_state_user_foreground # test if user wants the last directory printed in bold if [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" == "true" ]]; then bld_on="%B" @@ -1229,18 +1231,19 @@ prompt_ram() { "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$ramfree" $base)" 'RAM_ICON' } -################################################################ -# Segment to display rbenv information -set_default POWERLEVEL9K_RBENV_ALWAYS false + +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 - # unless `POWERLEVEL9K_RBENV_ALWAYS` is set. - if [[ $POWERLEVEL9K_RBENV_ALWAYS == true || $rbenv_version_name != $rbenv_global ]];then - "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON' + # unless `POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW` is set. + if [[ $rbenv_version_name == $rbenv_global && "$POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW" = false ]]; then + return fi fi } @@ -1337,8 +1340,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")" @@ -1685,6 +1693,7 @@ build_left_prompt() { # Right prompt build_right_prompt() { local index=1 + local element for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do # Remove joined information in direct calls element=${element%_joined} @@ -1707,6 +1716,7 @@ powerlevel9k_preexec() { set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false powerlevel9k_prepare_prompts() { + local RETVAL RPROMPT_PREFIX RPROMPT_SUFFIX RETVAL=$? RETVALS=( "$pipestatus[@]" ) @@ -1741,7 +1751,7 @@ $(print_icon 'MULTILINE_LAST_PROMPT_PREFIX')' RPROMPT='$RPROMPT_PREFIX%f%b%k$(build_right_prompt)%{$reset_color%}$RPROMPT_SUFFIX' fi -NEWLINE=' +local NEWLINE=' ' if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 66009a86..e8bbaf93 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -46,6 +46,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' |