From 2809000f9c11a932464810ff73ecbb6ac02d2952 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 20 Sep 2015 20:33:50 +0200 Subject: printHumanReadableSize should be able to process floats. --- powerlevel9k.zsh-theme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 86fc2c42..5fa56836 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -180,7 +180,8 @@ function print_icon() { } printSizeHumanReadable() { - local size=$1 + typeset -F 2 size + size="$1"+0.00001 local extension extension=(B K M G T P E Z Y) local index=1 @@ -195,7 +196,7 @@ printSizeHumanReadable() { done fi - while (( (size / 1024) > 0 )); do + while (( (size / 1024) > 0.1 )); do size=$(( size / 1024 )) index=$(( index + 1 )) done -- cgit v1.2.3 From 43a6079d8396611e6d3693c1766b79b0356af65d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 20 Sep 2015 20:34:43 +0200 Subject: Ram as own prompt. --- powerlevel9k.zsh-theme | 56 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5fa56836..428db392 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -654,22 +654,11 @@ prompt_ip() { "$1_prompt_segment" "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip" } -set_default POWERLEVEL9K_LOAD_SHOW_FREE_RAM true prompt_load() { if [[ "$OS" == "OSX" ]]; then load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) - if [[ "$POWERLEVEL9K_LOAD_SHOW_FREE_RAM" == true ]]; then - ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') - # Convert pages into Bytes - ramfree=$(( ramfree * 4096 )) - base='' - fi else load_avg_5min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) - if [[ "$POWERLEVEL9K_LOAD_SHOW_FREE_RAM" == true ]]; then - ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") - base=K - fi fi # Replace comma @@ -687,10 +676,49 @@ prompt_load() { fi "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min" +} - if [[ "$POWERLEVEL9K_LOAD_SHOW_FREE_RAM" == true ]]; then - echo -n "$(print_icon 'RAM_ICON') $(printSizeHumanReadable "$ramfree" $base) " - fi +prompt_ram() { + defined POWERLEVEL9K_RAM_ELEMENTS || POWERLEVEL9K_RAM_ELEMENTS=(ram_free swap_used) + + local rendition base + for element in "${POWERLEVEL9K_RAM_ELEMENTS[@]}"; do + case $element in + ram_free) + if [[ "$OS" == "OSX" ]]; then + ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') + # Convert pages into Bytes + ramfree=$(( ramfree * 4096 )) + base='' + else + ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") + base=K + fi + + rendition+="$(print_icon 'RAM_ICON') $(printSizeHumanReadable "$ramfree" $base) " + ;; + swap_used) + if [[ "$OS" == "OSX" ]]; then + raw_swap_used=$(sysctl vm.swapusage | grep -o "used\s*=\s*[0-9,.A-Z]*" | grep -o "[0-9,.A-Z]*$") + typeset -F 2 swap_used + swap_used=${$(echo $raw_swap_used | grep -o "[0-9,.]*")//,/.} + # Replace comma + swap_used=${swap_used//,/.} + + base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$") + else + swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") + swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") + swap_used=$(( swap_free - swap_total )) + base=K + fi + + rendition+="$(printSizeHumanReadable "$swap_used" $base) " + ;; + esac + done + + "$1_prompt_segment" "$0" "yellow" "$DEFAULT_COLOR" "${rendition% }" } # Right Status: (return code, root status, background jobs) -- cgit v1.2.3 From 1a5edebae76586361258ab68cb3f26148dfe026e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 21 Sep 2015 18:27:03 +0200 Subject: Added a segment that shows the current GO version number. --- README.md | 1 + powerlevel9k.zsh-theme | 10 ++++++++++ 2 files changed, 11 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 98033e79..6dfd7240 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,7 @@ currently available are: * **context** - Your username and host (more info below) * **vi_mode** - Vi editing mode (NORMAL|INSERT). * **dir** - Your current working directory. +* **go_version** - Show the current GO version. * **history** - The command number for the current line. * **ip** - Shows the current IP address. * **load** - Your machines 5 minute load average and free RAM. diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 86fc2c42..413a61f5 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -608,6 +608,16 @@ prompt_dir() { "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$(print_icon 'HOME_ICON')$current_path" } +# GO-prompt +prompt_go_version() { + local go_version + go_version=$(go version 2>&1 | grep -oe "^go[0-9.]*") + + if [[ -n "$go_version" ]]; then + "$1_prompt_segment" "$0" "green" "255" "$go_version" + fi +} + # Command number (in local history) prompt_history() { "$1_prompt_segment" "$0" "244" "$DEFAULT_COLOR" '%h' -- cgit v1.2.3 From f52a7f25701a42bda48be32e0649c86dd291fbb2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 26 Sep 2015 12:33:14 +0200 Subject: Corrected calculation of used swap under linux. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 428db392..c707923e 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -709,7 +709,7 @@ prompt_ram() { else swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") - swap_used=$(( swap_free - swap_total )) + swap_used=$(( swap_total - swap_free )) base=K fi -- cgit v1.2.3 From 6d24f93760d866feceda8750a115e19beb6250b1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 26 Sep 2015 12:51:08 +0200 Subject: Alphabetical order. --- powerlevel9k.zsh-theme | 87 +++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 43 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c707923e..b48bce4b 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -678,49 +678,6 @@ prompt_load() { "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min" } -prompt_ram() { - defined POWERLEVEL9K_RAM_ELEMENTS || POWERLEVEL9K_RAM_ELEMENTS=(ram_free swap_used) - - local rendition base - for element in "${POWERLEVEL9K_RAM_ELEMENTS[@]}"; do - case $element in - ram_free) - if [[ "$OS" == "OSX" ]]; then - ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') - # Convert pages into Bytes - ramfree=$(( ramfree * 4096 )) - base='' - else - ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") - base=K - fi - - rendition+="$(print_icon 'RAM_ICON') $(printSizeHumanReadable "$ramfree" $base) " - ;; - swap_used) - if [[ "$OS" == "OSX" ]]; then - raw_swap_used=$(sysctl vm.swapusage | grep -o "used\s*=\s*[0-9,.A-Z]*" | grep -o "[0-9,.A-Z]*$") - typeset -F 2 swap_used - swap_used=${$(echo $raw_swap_used | grep -o "[0-9,.]*")//,/.} - # Replace comma - swap_used=${swap_used//,/.} - - base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$") - else - swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") - swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") - swap_used=$(( swap_total - swap_free )) - base=K - fi - - rendition+="$(printSizeHumanReadable "$swap_used" $base) " - ;; - esac - done - - "$1_prompt_segment" "$0" "yellow" "$DEFAULT_COLOR" "${rendition% }" -} - # Right Status: (return code, root status, background jobs) # This creates a status segment for the *right* prompt. Exact same thing as # above - just other side. @@ -766,6 +723,50 @@ prompt_php_version() { fi } +# Show free RAM and used Swap +prompt_ram() { + defined POWERLEVEL9K_RAM_ELEMENTS || POWERLEVEL9K_RAM_ELEMENTS=(ram_free swap_used) + + local rendition base + for element in "${POWERLEVEL9K_RAM_ELEMENTS[@]}"; do + case $element in + ram_free) + if [[ "$OS" == "OSX" ]]; then + ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') + # Convert pages into Bytes + ramfree=$(( ramfree * 4096 )) + base='' + else + ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") + base=K + fi + + rendition+="$(print_icon 'RAM_ICON') $(printSizeHumanReadable "$ramfree" $base) " + ;; + swap_used) + if [[ "$OS" == "OSX" ]]; then + raw_swap_used=$(sysctl vm.swapusage | grep -o "used\s*=\s*[0-9,.A-Z]*" | grep -o "[0-9,.A-Z]*$") + typeset -F 2 swap_used + swap_used=${$(echo $raw_swap_used | grep -o "[0-9,.]*")//,/.} + # Replace comma + swap_used=${swap_used//,/.} + + base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$") + else + swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") + swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") + swap_used=$(( swap_total - swap_free )) + base=K + fi + + rendition+="$(printSizeHumanReadable "$swap_used" $base) " + ;; + esac + done + + "$1_prompt_segment" "$0" "yellow" "$DEFAULT_COLOR" "${rendition% }" +} + # rbenv information prompt_rbenv() { if [[ -n "$RBENV_VERSION" ]]; then -- cgit v1.2.3 From 66b4194daf1970b7a000f9c3bdb2fdd34727af33 Mon Sep 17 00:00:00 2001 From: John Koelndorfer Date: Tue, 6 Oct 2015 10:20:52 -0500 Subject: Quote value of IS_BSD_SED. If this isn't quoted, in can bleed through to stdout in certain circumstances. --- powerlevel9k.zsh-theme | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0c69a02e..c2ee2625 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -317,8 +317,7 @@ esac # `sed` is unfortunately not consistent across OSes when it comes to flags. SED_EXTENDED_REGEX_PARAMETER="-r" if [[ "$OS" == 'OSX' ]]; then - local IS_BSD_SED - IS_BSD_SED=$(sed --version &>> /dev/null || echo "BSD sed") + local IS_BSD_SED="$(sed --version &>> /dev/null || echo "BSD sed")" if [[ -n "$IS_BSD_SED" ]]; then SED_EXTENDED_REGEX_PARAMETER="-E" fi -- cgit v1.2.3 From 0e37d8ef865daddd6af02ba78b4a3bb86fd5917e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 11 Oct 2015 16:18:27 +0200 Subject: Added a new function `isSameColor` to handle color comparisons. It is now possible to compare ANSI colors (e.g. "black" or "bg-red") with ZSH-style colors (e.g. "001"). This way the subsegments work much better, as users can define color codes the way they like. --- powerlevel9k.zsh-theme | 52 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0c69a02e..8331fcb0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -225,6 +225,52 @@ function print_icon() { fi } +# Get numerical color codes. That way we translate ANSI codes +# into ZSH-Style color codes. +function getColorCode() { + # Check if given value is already numerical + if [[ "$1" = <-> ]]; then + # ANSI color codes distinguish between "foreground" + # and "background" colors. We don't need to do that, + # as ZSH uses a 256 color space anyway. + if [[ "$1" = <8-15> ]]; then + echo $(($1 - 8)) + else + echo "$1" + fi + else + typeset -A codes + codes=( + 'black' '000' + 'red' '001' + 'green' '002' + 'yellow' '003' + 'blue' '004' + 'magenta' '005' + 'cyan' '006' + 'white' '007' + ) + + # Strip eventual "bg-" prefixes + 1=${1#bg-} + # Strip eventual "fg-" prefixes + 1=${1#fg-} + echo $codes[$1] + fi +} + +# Check if two colors are equal, even if one is specified as ANSI code. +function isSameColor() { + if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then + return 1 + fi + + local color1=$(getColorCode "$1") + local color2=$(getColorCode "$2") + + return $(( color1 != color2 )) +} + # Converts large memory values into a human-readable unit (e.g., bytes --> GB) printSizeHumanReadable() { local size=$1 @@ -425,10 +471,10 @@ left_prompt_segment() { local bg fg [[ -n $2 ]] && bg="%K{$2}" || bg="%k" [[ -n $3 ]] && fg="%F{$3}" || fg="%f" - if [[ $CURRENT_BG != 'NONE' ]] && [[ "$2" != "$CURRENT_BG" ]]; then + if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$2" "$CURRENT_BG"; then # Middle segment echo -n "%{$bg%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')%{$fg%} " - elif [[ "$CURRENT_BG" == "$2" ]]; then + elif isSameColor "$CURRENT_BG" "$2"; then # Middle segment with same color as previous segment # We take the current foreground color as color for our # subsegment (or the default color). This should have @@ -480,7 +526,7 @@ right_prompt_segment() { [[ -n $2 ]] && bg="%K{$2}" || bg="%k" [[ -n $3 ]] && fg="%F{$3}" || fg="%f" - if [[ "$CURRENT_RIGHT_BG" == "$2" ]]; then + if isSameColor "$CURRENT_RIGHT_BG" "$2"; then # Middle segment with same color as previous segment # We take the current foreground color as color for our # subsegment (or the default color). This should have -- cgit v1.2.3 From 20447a22c93c9fab1cd84b5882924c67771a4c61 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 11 Oct 2015 16:22:01 +0200 Subject: Removed unnecessary literal escape sequences. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8331fcb0..dfe19925 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -495,9 +495,9 @@ left_prompt_end() { if [[ -n $CURRENT_BG ]]; then echo -n "%{%k%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')" else - echo -n "%{%k%}" + echo -n "%k" fi - echo -n "%{%f%} " + echo -n "%f " CURRENT_BG='' } -- cgit v1.2.3 From 6bf2869a1c8e509d1d0bb05ea05e179c48b9f7c4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 11 Oct 2015 19:41:52 +0200 Subject: Cleanup of VCS-segment. Now `vcs_info` is only invoked, if the user configured to show the `vcs` segment. --- powerlevel9k.zsh-theme | 92 ++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 47 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0c69a02e..8ffc6384 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -341,51 +341,6 @@ fi set_default POWERLEVEL9K_VCS_FOREGROUND "$DEFAULT_COLOR" set_default POWERLEVEL9K_VCS_DARK_FOREGROUND "$DEFAULT_COLOR_DARK" -################################################################ -# VCS Information Settings -################################################################ - -setopt prompt_subst -autoload -Uz vcs_info - -VCS_WORKDIR_DIRTY=false -VCS_CHANGESET_PREFIX='' -if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then - # Default: Just display the first 12 characters of our changeset-ID. - local VCS_CHANGESET_HASH_LENGTH=12 - if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then - VCS_CHANGESET_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" - fi - - VCS_CHANGESET_PREFIX="%F{$POWERLEVEL9K_VCS_DARK_FOREGROUND}$(print_icon 'VCS_COMMIT_ICON')%0.$VCS_CHANGESET_HASH_LENGTH""i%f " -fi - -zstyle ':vcs_info:*' enable git hg -zstyle ':vcs_info:*' check-for-changes true - -VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%F{$POWERLEVEL9K_VCS_FOREGROUND}%b%c%u%m%f" -zstyle ':vcs_info:git*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_GIT_ICON')%f$VCS_DEFAULT_FORMAT" -zstyle ':vcs_info:hg*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_HG_ICON')%f$VCS_DEFAULT_FORMAT" - -zstyle ':vcs_info:*' actionformats "%b %F{red}| %a%f" - -zstyle ':vcs_info:*' stagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_STAGED_ICON')%f" -zstyle ':vcs_info:*' unstagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_UNSTAGED_ICON')%f" - -zstyle ':vcs_info:git*+set-message:*' hooks vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname -zstyle ':vcs_info:hg*+set-message:*' hooks vcs-detect-changes - -# For Hg, only show the branch name -zstyle ':vcs_info:hg*:*' branchformat "$(print_icon 'VCS_BRANCH_ICON')%b" -# The `get-revision` function must be turned on for dirty-check to work for Hg -zstyle ':vcs_info:hg*:*' get-revision true -zstyle ':vcs_info:hg*:*' get-bookmarks true -zstyle ':vcs_info:hg*+gen-hg-bookmark-string:*' hooks hg-bookmarks - -if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then - zstyle ':vcs_info:*' get-revision true -fi - ################################################################ # Prompt Segment Constructors # @@ -500,6 +455,48 @@ right_prompt_segment() { # The `vcs` Segment and VCS_INFO hooks / helper functions ################################################################ prompt_vcs() { + autoload -Uz vcs_info + + VCS_WORKDIR_DIRTY=false + VCS_CHANGESET_PREFIX='' + if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then + # Default: Just display the first 12 characters of our changeset-ID. + local VCS_CHANGESET_HASH_LENGTH=12 + if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then + VCS_CHANGESET_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" + fi + + VCS_CHANGESET_PREFIX="%F{$POWERLEVEL9K_VCS_DARK_FOREGROUND}$(print_icon 'VCS_COMMIT_ICON')%0.$VCS_CHANGESET_HASH_LENGTH""i%f " + fi + + zstyle ':vcs_info:*' enable git hg + zstyle ':vcs_info:*' check-for-changes true + + VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%F{$POWERLEVEL9K_VCS_FOREGROUND}%b%c%u%m%f" + zstyle ':vcs_info:git*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_GIT_ICON')%f$VCS_DEFAULT_FORMAT" + zstyle ':vcs_info:hg*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_HG_ICON')%f$VCS_DEFAULT_FORMAT" + + zstyle ':vcs_info:*' actionformats "%b %F{red}| %a%f" + + zstyle ':vcs_info:*' stagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_STAGED_ICON')%f" + zstyle ':vcs_info:*' unstagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_UNSTAGED_ICON')%f" + + zstyle ':vcs_info:git*+set-message:*' hooks vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname + zstyle ':vcs_info:hg*+set-message:*' hooks vcs-detect-changes + + # For Hg, only show the branch name + zstyle ':vcs_info:hg*:*' branchformat "$(print_icon 'VCS_BRANCH_ICON')%b" + # The `get-revision` function must be turned on for dirty-check to work for Hg + zstyle ':vcs_info:hg*:*' get-revision true + zstyle ':vcs_info:hg*:*' get-bookmarks true + zstyle ':vcs_info:hg*+gen-hg-bookmark-string:*' hooks hg-bookmarks + + if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then + zstyle ':vcs_info:*' get-revision true + fi + + # Actually invoke vcs_info manually to gather all information. + vcs_info local vcs_prompt="${vcs_info_msg_0_}" if [[ -n "$vcs_prompt" ]]; then @@ -940,6 +937,8 @@ powerlevel9k_init() { print "You should set TERM=xterm-256colors in your ~/.zshrc" fi + setopt prompt_subst + setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS setopt PROMPT_CR PROMPT_PERCENT PROMPT_SUBST MULTIBYTE @@ -947,9 +946,8 @@ powerlevel9k_init() { # initialize colors autoload -U colors && colors - # initialize VCS + # initialize hooks autoload -Uz add-zsh-hook - add-zsh-hook precmd vcs_info # prepare prompts add-zsh-hook precmd powerlevel9k_prepare_prompts -- cgit v1.2.3 From f7e1f64b4c0f44408bb06d7dec018768dd767c5b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 13 Oct 2015 23:42:46 +0200 Subject: Added handling for bright colors. --- powerlevel9k.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dfe19925..f07caf2f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -255,6 +255,8 @@ function getColorCode() { 1=${1#bg-} # Strip eventual "fg-" prefixes 1=${1#fg-} + # Strip eventual "br" prefixes ("bright" colors) + 1=${1#br} echo $codes[$1] fi } -- cgit v1.2.3 From 7e6339ec2770bacc71ba83139330aec574f752f6 Mon Sep 17 00:00:00 2001 From: Alex LaFroscia Date: Mon, 12 Oct 2015 00:28:33 -0400 Subject: Add NVM prompt segment Prints out the Node version that is currently active if it is different than the default version specified by NVM --- powerlevel9k.zsh-theme | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2ee2625..af146d4e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -752,6 +752,17 @@ prompt_php_version() { fi } +# Node version from NVM +# Only prints the segment if different than the default value +prompt_nvm() { + local node_version=$(nvm current) + local nvm_default=$(cat $NVM_DIR/alias/default) + [[ -z "${node_version}" ]] && return + [[ "$node_version" =~ "$nvm_default" ]] && return + NODE_ICON=$'\u2B22' # ⬢ + $1_prompt_segment "$0" "green" "011" "${node_version:1} $NODE_ICON" +} + # rbenv information prompt_rbenv() { if [[ -n "$RBENV_VERSION" ]]; then -- cgit v1.2.3 From 86b460f06bfb01f782026af806c2dc68f8925621 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 16 Oct 2015 20:16:31 +0200 Subject: vi_mode segement more customizable. --- README.md | 6 ++++++ powerlevel9k.zsh-theme | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 4baf0629..c5ef1afe 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,12 @@ VI-Mode, you need to configure it separately in your `~/.zshrc`: # make it more responsive export KEYTIMEOUT=1 +If you want to display another string than "NORMAL" or "INSERT" in command or +insert-mode, you can do that by setting environment variables like: + + POWERLEVEL9K_VI_INSERT_MODE_STRING="INS" + POWERLEVEL9K_VI_COMMAND_MODE_STRING="CMD" + #### Unit Test Ratios The `symfony2_tests` and `rspec_stats` segments both show a ratio of "real" diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2ee2625..0af9f56d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -850,13 +850,15 @@ prompt_time() { } # Vi Mode: show editing mode (NORMAL|INSERT) +set_default POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT" +set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL" prompt_vi_mode() { case ${KEYMAP} in main|viins) - "$1_prompt_segment" "$0_INSERT" "$DEFAULT_COLOR" "blue" "INSERT" + "$1_prompt_segment" "$0_INSERT" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING" ;; vicmd) - "$1_prompt_segment" "$0_NORMAL" "$DEFAULT_COLOR" "default" "NORMAL" + "$1_prompt_segment" "$0_NORMAL" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING" ;; esac } -- cgit v1.2.3 From b04fae917358882a0e0aabf387ed3eedf80b26e4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 16 Oct 2015 20:42:21 +0200 Subject: Made whitespaces between segment separators customizable. --- powerlevel9k.zsh-theme | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2ee2625..d1f53198 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -410,6 +410,7 @@ CURRENT_BG='NONE' # * $3: Foreground color # * $4: The segment content # The latter three can be omitted, +set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " " left_prompt_segment() { # Overwrite given background-color by user defined variable for this segment. local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_BACKGROUND @@ -426,7 +427,7 @@ left_prompt_segment() { [[ -n $3 ]] && fg="%F{$3}" || fg="%f" if [[ $CURRENT_BG != 'NONE' ]] && [[ "$2" != "$CURRENT_BG" ]]; then # Middle segment - echo -n "%{$bg%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')%{$fg%} " + echo -n "%{$bg%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" elif [[ "$CURRENT_BG" == "$2" ]]; then # Middle segment with same color as previous segment # We take the current foreground color as color for our @@ -434,13 +435,13 @@ left_prompt_segment() { # enough contrast. local complement [[ -n $3 ]] && complement=$3 || complement=$DEFAULT_COLOR - echo -n "%{$bg%F{$complement}%}$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')%{$fg%} " + echo -n "%{$bg%F{$complement}%}$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" else # First segment - echo -n "%{$bg%}%{$fg%} " + echo -n "%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi CURRENT_BG=$2 - [[ -n $4 ]] && echo -n "$4 " + [[ -n $4 ]] && echo -n "$4$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" } # End the left prompt, closes the final segment. @@ -464,6 +465,7 @@ CURRENT_RIGHT_BG='NONE' # * $3: Foreground color # * $4: The segment content # No ending for the right prompt segment is needed (unlike the left prompt, above). +set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " " right_prompt_segment() { # Overwrite given background-color by user defined variable for this segment. local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_BACKGROUND @@ -486,11 +488,11 @@ right_prompt_segment() { # enough contrast. local complement [[ -n $3 ]] && complement=$3 || complement=$DEFAULT_COLOR - echo -n "%F{$complement}$(print_icon 'RIGHT_SUBSEGMENT_SEPARATOR')%f%{$bg%}%{$fg%} " + echo -n "%F{$complement}$(print_icon 'RIGHT_SUBSEGMENT_SEPARATOR')%f%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS" else - echo -n "%F{$2}$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f%{$bg%}%{$fg%} " + echo -n "%F{$2}$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS" fi - [[ -n $4 ]] && echo -n "$4 %f" + [[ -n $4 ]] && echo -n "$4$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS%f" CURRENT_RIGHT_BG=$2 } -- cgit v1.2.3 From ae035e537afe5435b05a45cb735d5d5d8e885e4b Mon Sep 17 00:00:00 2001 From: Parth Panchal Date: Sat, 17 Oct 2015 23:17:40 +0530 Subject: Fixes `VIRTUAL_ENV_DISABLE_PROMPT` condition --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2ee2625..58c2db66 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -866,7 +866,7 @@ prompt_vi_mode() { # https://virtualenv.pypa.io/en/latest/ prompt_virtualenv() { local virtualenv_path="$VIRTUAL_ENV" - if [[ -n "$virtualenv_path" && -n "$VIRTUAL_ENV_DISABLE_PROMPT" ]]; then + if [[ -n "$virtualenv_path" && "$VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "($(basename "$virtualenv_path"))" fi } -- cgit v1.2.3 From 5add0daad027fab254a7c2a322e636dd7dc982d2 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sat, 17 Oct 2015 11:30:55 -0700 Subject: added prompt segment for todo.txt task number --- README.md | 3 ++- powerlevel9k.zsh-theme | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 4baf0629..4c5e6809 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ The segments that are currently available are: * [symphony2_tests](#symphony2_tests) - Show a ratio of test classes vs code classes for Symfony2. * **symphony2_version** - Show the current Symfony2 version, if you are in a Symfony2-Project dir. * [time](#time) - System time. +* [todo.txt](http://todotxt.com/) - Shows the number of tasks in your todo.txt tasks file. * [vi_mode](#vi_mode)- Vi editing mode (NORMAL|INSERT). * **virtualenv** - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). * [vcs](#vcs) - Information about this `git` or `hg` repository (if you are in one). @@ -127,7 +128,7 @@ To change the way how the current working directory is truncated, just set: # default behaviour is to truncate whole directories In each case you have to specify the length you want to shorten the directory -to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in +to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in others whole directories. ##### ip diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2ee2625..0fe32d9d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -45,6 +45,7 @@ case $POWERLEVEL9K_MODE in AWS_ICON $'\UE895' #  BACKGROUND_JOBS_ICON $'\UE82F ' #  TEST_ICON $'\UE891' #  + TODO_ICON $'\U2611' # ☑ OK_ICON $'\U2713' # ✓ FAIL_ICON $'\U2718' # ✘ SYMFONY_ICON 'SF' @@ -93,6 +94,7 @@ case $POWERLEVEL9K_MODE in AWS_ICON $'\UF296' #  BACKGROUND_JOBS_ICON $'\UF013 ' #  TEST_ICON $'\UF291' #  + TODO_ICON $'\U2611' # ☑ OK_ICON $'\UF23A' #  FAIL_ICON $'\UF281' #  SYMFONY_ICON 'SF' @@ -136,6 +138,7 @@ case $POWERLEVEL9K_MODE in AWS_ICON 'AWS:' BACKGROUND_JOBS_ICON $'\u2699' # ⚙ TEST_ICON '' + TODO_ICON $'\U2611' # ☑ OK_ICON $'\u2713' # ✓ FAIL_ICON $'\u2718' # ✘ SYMFONY_ICON 'SF' @@ -849,6 +852,16 @@ prompt_time() { "$1_prompt_segment" "$0" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$time_format" } +# todo.sh: shows the number of tasks in your todo.sh file +prompt_todo() { + if $(hash todo.sh 2>&-); then + count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }') + if [[ "$count" = <-> ]]; then + "$1_prompt_segment" "$0" "244" "$DEFAULT_COLOR" "$(print_icon 'TODO_ICON') $count" + fi + fi +} + # Vi Mode: show editing mode (NORMAL|INSERT) prompt_vi_mode() { case ${KEYMAP} in -- cgit v1.2.3 From 8e458e5e9acac0766f4319eb7494f033201978a9 Mon Sep 17 00:00:00 2001 From: Martin Pelikan Date: Sun, 18 Oct 2015 00:11:24 -0700 Subject: Fixes #122, SI prefixes should be evaluated as strings. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2ee2625..f532cd99 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -229,7 +229,7 @@ function print_icon() { printSizeHumanReadable() { local size=$1 local extension - extension=(B K M G T P E Z Y) + extension=('B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y') local index=1 # if the base is not Bytes -- cgit v1.2.3 From acf5e97756a97c0feb12c38475266b0c079ca25f Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 10:55:37 -0700 Subject: added battery prompt segment usable on OS X systems --- README.md | 17 +++++++++++++++++ powerlevel9k.zsh-theme | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index a06b4857..ac397e65 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ configuration is the default: The segments that are currently available are: * [aws](#aws) - The current AWS profile, if active. +* [battery](#battery) - Current battery status(OS X only). * [context](#context) - Your username and host. * [dir](#dir) - Your current working directory. * **history** - The command number for the current line. @@ -101,6 +102,22 @@ your `~/.zshrc`: export AWS_DEFAULT_PROFILE= +##### battery + +This segment will display your current battery status on an OS X system(fails gracefully +on systems without a battery and non OS X systems). It can be customized in your .zshrc +with the environment variables detailed below with their default values. + + POWERLEVEL9K_BATTERY_CHARGING="yellow" + POWERLEVEL9K_BATTERY_CHARGED="green" + POWERLEVEL9K_BATTERY_DISCONNECTED=$DEFAULT_COLOR + POWERLEVEL9K_BATTERY_LOW_THRESHOLD=10 + POWERLEVEL9K_BATTERY_LOW_COLOR="red" + +In addition to the above it supports standard _FOREGROUND value without affecting the icon color + + + ##### context The `context` segment (user@host string) is conditional. This lets you enable it, but only display diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7063962f..6dd4f8da 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -46,6 +46,7 @@ case $POWERLEVEL9K_MODE in BACKGROUND_JOBS_ICON $'\UE82F ' #  TEST_ICON $'\UE891' #  TODO_ICON $'\U2611' # ☑ + BATTERY_ICON $'\UE894' #  OK_ICON $'\U2713' # ✓ FAIL_ICON $'\U2718' # ✘ SYMFONY_ICON 'SF' @@ -95,6 +96,7 @@ case $POWERLEVEL9K_MODE in BACKGROUND_JOBS_ICON $'\UF013 ' #  TEST_ICON $'\UF291' #  TODO_ICON $'\U2611' # ☑ + BATTERY_ICON $'\u1F50B' # 🔋 OK_ICON $'\UF23A' #  FAIL_ICON $'\UF281' #  SYMFONY_ICON 'SF' @@ -139,6 +141,7 @@ case $POWERLEVEL9K_MODE in BACKGROUND_JOBS_ICON $'\u2699' # ⚙ TEST_ICON '' TODO_ICON $'\U2611' # ☑ + BATTERY_ICON $'\u1F50B' # 🔋 OK_ICON $'\u2713' # ✓ FAIL_ICON $'\u2718' # ✘ SYMFONY_ICON 'SF' @@ -611,6 +614,48 @@ prompt_aws() { fi } +prompt_battery() { + if [[ -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then + # return if there is no battery on system + [[ -z $(ioreg -n AppleSmartBattery | grep MaxCapacity) ]] && return + + # set default values of not specified in shell + [[ -z $POWERLEVEL9K_BATTERY_CHARGING ]] && POWERLEVEL9K_BATTERY_CHARGING="yellow" + [[ -z $POWERLEVEL9K_BATTERY_CHARGED ]] && POWERLEVEL9K_BATTERY_CHARGED="green" + [[ -z $POWERLEVEL9K_BATTERY_DISCONNECTED ]] && POWERLEVEL9K_BATTERY_DISCONNECTED="$DEFAULT_COLOR" + [[ -z $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && POWERLEVEL9K_BATTERY_LOW_THRESHOLD=10 + [[ -z $POWERLEVEL9K_BATTERY_LOW_COLOR ]] && POWERLEVEL9K_BATTERY_LOW_COLOR="red" + [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local fg_color="$DEFAULT_COLOR" || local fg_color=$POWERLEVEL9K_BATTERY_FOREGROUND + + # get charge status + [[ $(ioreg -n AppleSmartBattery | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]] && local connected=true + [[ $(ioreg -n AppleSmartBattery | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]] && local charging=true + + # convert time remaining from minutes to hours:minutes date string + local time_remaining=$(ioreg -n AppleSmartBattery | grep TimeRemaining | awk '{ print $5 }') + if [[ ! -z $time_remaining ]]; then + # this value is set to a very high number when the system is calculating + [[ $time_remaining -gt 10000 ]] && local tstring="..." || local tstring=${(f)$(date -u -r $(($time_remaining * 60)) +%k:%M)} + fi + + # get charge values + local max_capacity=$(ioreg -n AppleSmartBattery | grep MaxCapacity | awk '{ print $5 }') + local current_capacity=$(ioreg -n AppleSmartBattery | grep CurrentCapacity | awk '{ print $5 }') + + # logic for string output + [[ ! -z $max_capacity && ! -z $current_capacity ]] && local bat_percent=$(ruby -e "puts ($current_capacity.to_f / $max_capacity.to_f * 100).round.to_i") + [[ $charging =~ true && $connected =~ true ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGING}" && local remain="($tstring)" + [[ ! $charging =~ true && $connected =~ true ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGED}" && local remain="" + if [[ ! $connected =~ true ]]; then + [[ $bat_percent -lt $POWERLVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="%F{$POWERLEVEL9K_BATTERY_LOW_COLOR}" || local conn="%F{$POWERLEVEL9K_BATTERY_DISCONNECTED}" + local remain="($tstring)" + fi + + # display prompt_segment + [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "black" "$DEFAULT_COLOR" "$conn$(print_icon 'BATTERY_ICON'){$fg_color} $bat_percent%% $remain" + fi +} + # Context: user@hostname (who am I and where am I) # Note that if $DEFAULT_USER is not set, this prompt segment will always print prompt_context() { @@ -965,7 +1010,7 @@ powerlevel9k_init() { fi setopt prompt_subst - + setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS setopt PROMPT_CR PROMPT_PERCENT PROMPT_SUBST MULTIBYTE -- cgit v1.2.3 From 118008c402338b1693ee7db4120b0ff374e542c3 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 11:01:52 -0700 Subject: fixed output string color declaration --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 6dd4f8da..097dac4f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -652,7 +652,7 @@ prompt_battery() { fi # display prompt_segment - [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "black" "$DEFAULT_COLOR" "$conn$(print_icon 'BATTERY_ICON'){$fg_color} $bat_percent%% $remain" + [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "black" "$DEFAULT_COLOR" "$conn$(print_icon 'BATTERY_ICON')%F{$fg_color} $bat_percent%% $remain" fi } -- cgit v1.2.3 From 2e406a5bdfcb33e72771f2290bd9d29e0eb7d497 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 11:05:37 -0700 Subject: editor automatically removed whitespace --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 097dac4f..4dda1474 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1010,7 +1010,7 @@ powerlevel9k_init() { fi setopt prompt_subst - + setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS setopt PROMPT_CR PROMPT_PERCENT PROMPT_SUBST MULTIBYTE -- cgit v1.2.3 From fb6738967ea2e3202d4140c62962d5dd674be430 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 16:30:16 -0700 Subject: added Linux support to battery prompt segment --- README.md | 9 +++++---- powerlevel9k.zsh-theme | 50 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 19 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index ac397e65..bb15d5ca 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ configuration is the default: The segments that are currently available are: * [aws](#aws) - The current AWS profile, if active. -* [battery](#battery) - Current battery status(OS X only). +* [battery](#battery) - Current battery status. * [context](#context) - Your username and host. * [dir](#dir) - Your current working directory. * **history** - The command number for the current line. @@ -104,8 +104,8 @@ your `~/.zshrc`: ##### battery -This segment will display your current battery status on an OS X system(fails gracefully -on systems without a battery and non OS X systems). It can be customized in your .zshrc +This segment will display your current battery status (fails gracefully +on systems without a battery). It can be customized in your .zshrc with the environment variables detailed below with their default values. POWERLEVEL9K_BATTERY_CHARGING="yellow" @@ -116,6 +116,7 @@ with the environment variables detailed below with their default values. In addition to the above it supports standard _FOREGROUND value without affecting the icon color +Supports both OS X and Linux(time remaining is only output in OS X) ##### context @@ -146,7 +147,7 @@ To change the way how the current working directory is truncated, just set: # default behaviour is to truncate whole directories In each case you have to specify the length you want to shorten the directory -to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in +to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in others whole directories. ##### ip diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4dda1474..eefeaa5b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -615,18 +615,19 @@ prompt_aws() { } prompt_battery() { - if [[ -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then + icons[BATTERY_ICON]=$'\UE894' + # set default values of not specified in shell + [[ -z $POWERLEVEL9K_BATTERY_CHARGING ]] && POWERLEVEL9K_BATTERY_CHARGING="yellow" + [[ -z $POWERLEVEL9K_BATTERY_CHARGED ]] && POWERLEVEL9K_BATTERY_CHARGED="green" + [[ -z $POWERLEVEL9K_BATTERY_DISCONNECTED ]] && POWERLEVEL9K_BATTERY_DISCONNECTED="$DEFAULT_COLOR" + [[ -z $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && POWERLEVEL9K_BATTERY_LOW_THRESHOLD=10 + [[ -z $POWERLEVEL9K_BATTERY_LOW_COLOR ]] && POWERLEVEL9K_BATTERY_LOW_COLOR="red" + [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local fg_color="$DEFAULT_COLOR" || local fg_color=$POWERLEVEL9K_BATTERY_FOREGROUND + + if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then # return if there is no battery on system [[ -z $(ioreg -n AppleSmartBattery | grep MaxCapacity) ]] && return - # set default values of not specified in shell - [[ -z $POWERLEVEL9K_BATTERY_CHARGING ]] && POWERLEVEL9K_BATTERY_CHARGING="yellow" - [[ -z $POWERLEVEL9K_BATTERY_CHARGED ]] && POWERLEVEL9K_BATTERY_CHARGED="green" - [[ -z $POWERLEVEL9K_BATTERY_DISCONNECTED ]] && POWERLEVEL9K_BATTERY_DISCONNECTED="$DEFAULT_COLOR" - [[ -z $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && POWERLEVEL9K_BATTERY_LOW_THRESHOLD=10 - [[ -z $POWERLEVEL9K_BATTERY_LOW_COLOR ]] && POWERLEVEL9K_BATTERY_LOW_COLOR="red" - [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local fg_color="$DEFAULT_COLOR" || local fg_color=$POWERLEVEL9K_BATTERY_FOREGROUND - # get charge status [[ $(ioreg -n AppleSmartBattery | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]] && local connected=true [[ $(ioreg -n AppleSmartBattery | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]] && local charging=true @@ -642,18 +643,37 @@ prompt_battery() { local max_capacity=$(ioreg -n AppleSmartBattery | grep MaxCapacity | awk '{ print $5 }') local current_capacity=$(ioreg -n AppleSmartBattery | grep CurrentCapacity | awk '{ print $5 }') - # logic for string output [[ ! -z $max_capacity && ! -z $current_capacity ]] && local bat_percent=$(ruby -e "puts ($current_capacity.to_f / $max_capacity.to_f * 100).round.to_i") - [[ $charging =~ true && $connected =~ true ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGING}" && local remain="($tstring)" + + # logic for string output + [[ $charging =~ true && $connected =~ true ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGING}" && local remain=" ($tstring)" [[ ! $charging =~ true && $connected =~ true ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGED}" && local remain="" if [[ ! $connected =~ true ]]; then - [[ $bat_percent -lt $POWERLVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="%F{$POWERLEVEL9K_BATTERY_LOW_COLOR}" || local conn="%F{$POWERLEVEL9K_BATTERY_DISCONNECTED}" - local remain="($tstring)" + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="%F{$POWERLEVEL9K_BATTERY_LOW_COLOR}" || local conn="%F{$POWERLEVEL9K_BATTERY_DISCONNECTED}" + local remain=" ($tstring)" fi + fi - # display prompt_segment - [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "black" "$DEFAULT_COLOR" "$conn$(print_icon 'BATTERY_ICON')%F{$fg_color} $bat_percent%% $remain" + if [[ $OS =~ Linux ]]; then + local sysp="/sys/class/power_supply" + # reported BAT0 or BAT1 depending on kernel version + [[ -a $sysp/BAT0 ]] && local bat=$sysp/BAT0 + [[ -a $sysp/BAT1 ]] && local bat=$sysp/BAT1 + + # return if no battery found + [[ -z $bat ]] && return + + local bat_percent=$(cat $bat/capacity) + [[ $(cat $bat/status) =~ Charging ]] && local connected=true + [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGED}" + [[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGING}" + if [[ ! $connected =~ true ]]; then + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="%F{$POWERLEVEL9K_BATTERY_LOW_COLOR}" || local conn="%F{$POWERLEVEL9K_BATTERY_DISCONNECTED}" + fi fi + + # display prompt_segment + [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "black" "$DEFAULT_COLOR" "$conn$(print_icon 'BATTERY_ICON')%F{$fg_color} $bat_percent%%$remain" } # Context: user@hostname (who am I and where am I) -- cgit v1.2.3 From ff3f6b8e833946a8e98352ceb15e8eb5682e2b69 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 19:48:45 -0700 Subject: added time remaining support to battery segment on Linux --- README.md | 2 +- powerlevel9k.zsh-theme | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 33b0fc85..b66304bc 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ with the environment variables detailed below with their default values. In addition to the above it supports standard _FOREGROUND value without affecting the icon color -Supports both OS X and Linux(time remaining is only output in OS X) +Supports both OS X and Linux(time remaining requires the acpi program on Linux) ##### context diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index eefeaa5b..bb24e60a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -670,6 +670,10 @@ prompt_battery() { if [[ ! $connected =~ true ]]; then [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="%F{$POWERLEVEL9K_BATTERY_LOW_COLOR}" || local conn="%F{$POWERLEVEL9K_BATTERY_DISCONNECTED}" fi + if [[ -f /usr/bin/acpi ]]; then + [[ $(acpi | awk '{ print $5 }') =~ rate ]] && local tstring="..." || local tstring=${(f)$(date -u -d @$(acpi | awk '{ print $5 }' | sed s/://g) +%k:%M)} + fi + [[ ! -z $tstring ]] && local remain=" ($tstring)" fi # display prompt_segment -- cgit v1.2.3 From 3e828cbaa47227fde34624229018d90d4651a586 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 21:03:47 -0700 Subject: fixed some edge cases I ran into during usage of the linux segment --- powerlevel9k.zsh-theme | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index bb24e60a..bc37de31 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -663,7 +663,7 @@ prompt_battery() { # return if no battery found [[ -z $bat ]] && return - local bat_percent=$(cat $bat/capacity) + [[ $(cat $bat/capacity) -gt 100 ]] && local bat_percent=100 || local bat_percent=$(cat $bat/capacity) [[ $(cat $bat/status) =~ Charging ]] && local connected=true [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGED}" [[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGING}" @@ -671,7 +671,12 @@ prompt_battery() { [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="%F{$POWERLEVEL9K_BATTERY_LOW_COLOR}" || local conn="%F{$POWERLEVEL9K_BATTERY_DISCONNECTED}" fi if [[ -f /usr/bin/acpi ]]; then - [[ $(acpi | awk '{ print $5 }') =~ rate ]] && local tstring="..." || local tstring=${(f)$(date -u -d @$(acpi | awk '{ print $5 }' | sed s/://g) +%k:%M)} + local time_remaining=$(acpi | awk '{ print $5 }') + if [[ $time_remaining =~ rate ]]; then + local tstring="..." + elif [[ $time_remaining =~ "[:digit:]+" ]]; then + local tstring=${(f)$(date -u -d @$(echo $time_remaining | sed s/://g) +%k:%M)} + fi fi [[ ! -z $tstring ]] && local remain=" ($tstring)" fi -- cgit v1.2.3 From 5addfdc9e08b3be1a2377b7f0c28f17ce8b8a4ab Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 19 Oct 2015 17:37:18 +0200 Subject: Moved utility-functions to "functions/power-utilities.zsh". --- functions/power-utilities.zsh | 190 ++++++++++++++++++++++++++++++++++++++++++ powerlevel9k.zsh-theme | 181 +--------------------------------------- 2 files changed, 192 insertions(+), 179 deletions(-) create mode 100644 functions/power-utilities.zsh (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/power-utilities.zsh b/functions/power-utilities.zsh new file mode 100644 index 00000000..370374aa --- /dev/null +++ b/functions/power-utilities.zsh @@ -0,0 +1,190 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# power-functions +# This file holds some utility-functions for +# the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ +################################################################ +# Utility functions +################################################################ + +# Exits with 0 if a variable has been previously defined (even if empty) +# Takes the name of a variable that should be checked. +function defined() { + local varname="$1" + + typeset -p "$varname" > /dev/null 2>&1 +} + +# Given the name of a variable and a default value, sets the variable +# value to the default only if it has not been defined. +# +# Typeset cannot set the value for an array, so this will only work +# for scalar values. +function set_default() { + local varname="$1" + local default_value="$2" + + defined "$varname" || typeset -g "$varname"="$default_value" +} + +# Safety function for printing icons +# Prints the named icon, or if that icon is undefined, the string name. +function print_icon() { + local icon_name=$1 + local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} + local USER_ICON=${(P)ICON_USER_VARIABLE} + if defined "$ICON_USER_VARIABLE"; then + echo -n "$USER_ICON" + else + echo -n "${icons[$icon_name]}" + fi +} + +# Get numerical color codes. That way we translate ANSI codes +# into ZSH-Style color codes. +function getColorCode() { + # Check if given value is already numerical + if [[ "$1" = <-> ]]; then + # ANSI color codes distinguish between "foreground" + # and "background" colors. We don't need to do that, + # as ZSH uses a 256 color space anyway. + if [[ "$1" = <8-15> ]]; then + echo $(($1 - 8)) + else + echo "$1" + fi + else + typeset -A codes + codes=( + 'black' '000' + 'red' '001' + 'green' '002' + 'yellow' '003' + 'blue' '004' + 'magenta' '005' + 'cyan' '006' + 'white' '007' + ) + + # Strip eventual "bg-" prefixes + 1=${1#bg-} + # Strip eventual "fg-" prefixes + 1=${1#fg-} + # Strip eventual "br" prefixes ("bright" colors) + 1=${1#br} + echo $codes[$1] + fi +} + +# Check if two colors are equal, even if one is specified as ANSI code. +function isSameColor() { + if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then + return 1 + fi + + local color1=$(getColorCode "$1") + local color2=$(getColorCode "$2") + + return $(( color1 != color2 )) +} + +# Converts large memory values into a human-readable unit (e.g., bytes --> GB) +printSizeHumanReadable() { + local size=$1 + local extension + extension=(B K M G T P E Z Y) + local index=1 + + # if the base is not Bytes + if [[ -n $2 ]]; then + for idx in "${extension[@]}"; do + if [[ "$2" == "$idx" ]]; then + break + fi + index=$(( index + 1 )) + done + fi + + while (( (size / 1024) > 0 )); do + size=$(( size / 1024 )) + index=$(( index + 1 )) + done + + echo "$size${extension[$index]}" +} + +# Gets the first value out of a list of items that is not empty. +# The items are examined by a callback-function. +# Takes two arguments: +# * $list - A list of items +# * $callback - A callback function to examine if the item is +# worthy. The callback function has access to +# the inner variable $item. +function getRelevantItem() { + setopt shwordsplit # We need to split the words in $interfaces + + local list callback + list=$1 + callback=$2 + + for item in $list; do + # The first non-empty item wins + try=$(eval "$callback") + if [[ -n "$try" ]]; then + echo "$try" + break; + fi + done +} + +get_icon_names() { + for key in ${(@k)icons}; do + echo "POWERLEVEL9K_$key: ${icons[$key]}" + done +} + +# OS detection for the `os_icon` segment +case $(uname) in + Darwin) + OS='OSX' + OS_ICON=$(print_icon 'APPLE_ICON') + ;; + FreeBSD) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + OpenBSD) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + DragonFly) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + Linux) + OS='Linux' + OS_ICON=$(print_icon 'LINUX_ICON') + ;; + SunOS) + OS='Solaris' + OS_ICON=$(print_icon 'SUNOS_ICON') + ;; + *) + OS='' + OS_ICON='' + ;; +esac + +# Determine the correct sed parameter. +# +# `sed` is unfortunately not consistent across OSes when it comes to flags. +SED_EXTENDED_REGEX_PARAMETER="-r" +if [[ "$OS" == 'OSX' ]]; then + local IS_BSD_SED="$(sed --version &>> /dev/null || echo "BSD sed")" + if [[ -n "$IS_BSD_SED" ]]; then + SED_EXTENDED_REGEX_PARAMETER="-E" + fi +fi + diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index a1170974..4ca5f661 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -192,187 +192,10 @@ if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then fi ################################################################ -# Utility functions +# Source utility functions ################################################################ -# Exits with 0 if a variable has been previously defined (even if empty) -# Takes the name of a variable that should be checked. -function defined() { - local varname="$1" - - typeset -p "$varname" > /dev/null 2>&1 -} - -# Given the name of a variable and a default value, sets the variable -# value to the default only if it has not been defined. -# -# Typeset cannot set the value for an array, so this will only work -# for scalar values. -function set_default() { - local varname="$1" - local default_value="$2" - - defined "$varname" || typeset -g "$varname"="$default_value" -} - -# Safety function for printing icons -# Prints the named icon, or if that icon is undefined, the string name. -function print_icon() { - local icon_name=$1 - local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} - local USER_ICON=${(P)ICON_USER_VARIABLE} - if defined "$ICON_USER_VARIABLE"; then - echo -n "$USER_ICON" - else - echo -n "${icons[$icon_name]}" - fi -} - -# Get numerical color codes. That way we translate ANSI codes -# into ZSH-Style color codes. -function getColorCode() { - # Check if given value is already numerical - if [[ "$1" = <-> ]]; then - # ANSI color codes distinguish between "foreground" - # and "background" colors. We don't need to do that, - # as ZSH uses a 256 color space anyway. - if [[ "$1" = <8-15> ]]; then - echo $(($1 - 8)) - else - echo "$1" - fi - else - typeset -A codes - codes=( - 'black' '000' - 'red' '001' - 'green' '002' - 'yellow' '003' - 'blue' '004' - 'magenta' '005' - 'cyan' '006' - 'white' '007' - ) - - # Strip eventual "bg-" prefixes - 1=${1#bg-} - # Strip eventual "fg-" prefixes - 1=${1#fg-} - # Strip eventual "br" prefixes ("bright" colors) - 1=${1#br} - echo $codes[$1] - fi -} - -# Check if two colors are equal, even if one is specified as ANSI code. -function isSameColor() { - if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then - return 1 - fi - - local color1=$(getColorCode "$1") - local color2=$(getColorCode "$2") - - return $(( color1 != color2 )) -} - -# Converts large memory values into a human-readable unit (e.g., bytes --> GB) -printSizeHumanReadable() { - local size=$1 - local extension - extension=(B K M G T P E Z Y) - local index=1 - - # if the base is not Bytes - if [[ -n $2 ]]; then - for idx in "${extension[@]}"; do - if [[ "$2" == "$idx" ]]; then - break - fi - index=$(( index + 1 )) - done - fi - - while (( (size / 1024) > 0 )); do - size=$(( size / 1024 )) - index=$(( index + 1 )) - done - - echo "$size${extension[$index]}" -} - -# Gets the first value out of a list of items that is not empty. -# The items are examined by a callback-function. -# Takes two arguments: -# * $list - A list of items -# * $callback - A callback function to examine if the item is -# worthy. The callback function has access to -# the inner variable $item. -function getRelevantItem() { - setopt shwordsplit # We need to split the words in $interfaces - - local list callback - list=$1 - callback=$2 - - for item in $list; do - # The first non-empty item wins - try=$(eval "$callback") - if [[ -n "$try" ]]; then - echo "$try" - break; - fi - done -} - -get_icon_names() { - for key in ${(@k)icons}; do - echo "POWERLEVEL9K_$key: ${icons[$key]}" - done -} - -# OS detection for the `os_icon` segment -case $(uname) in - Darwin) - OS='OSX' - OS_ICON=$(print_icon 'APPLE_ICON') - ;; - FreeBSD) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - OpenBSD) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - DragonFly) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - Linux) - OS='Linux' - OS_ICON=$(print_icon 'LINUX_ICON') - ;; - SunOS) - OS='Solaris' - OS_ICON=$(print_icon 'SUNOS_ICON') - ;; - *) - OS='' - OS_ICON='' - ;; -esac - -# Determine the correct sed parameter. -# -# `sed` is unfortunately not consistent across OSes when it comes to flags. -SED_EXTENDED_REGEX_PARAMETER="-r" -if [[ "$OS" == 'OSX' ]]; then - local IS_BSD_SED="$(sed --version &>> /dev/null || echo "BSD sed")" - if [[ -n "$IS_BSD_SED" ]]; then - SED_EXTENDED_REGEX_PARAMETER="-E" - fi -fi +source $(dirname "$0")/functions/power-utilities.zsh ################################################################ # Color Scheme -- cgit v1.2.3 From fa85a5158fa3d9ef84ecd3e94ab5deb805b735ab Mon Sep 17 00:00:00 2001 From: Daniel Gordon Date: Mon, 19 Oct 2015 13:02:24 -0500 Subject: Rephrasing of error message when TERM not 256 color - Literal command to be added is highlighted in blue - Now beginners won't try to add an incorrect command to ~/.zshrc --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2ee2625..d078258a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -936,7 +936,7 @@ powerlevel9k_init() { term_colors=$(tput colors) if (( term_colors < 256 )); then print -P "%F{red}WARNING!%f Your terminal supports less than 256 colors!" - print "You should set TERM=xterm-256colors in your ~/.zshrc" + print -P "You should put: %F{blue}export TERM=\"xterm-256color\"%f in your \~\/.zshrc" fi setopt LOCAL_OPTIONS -- cgit v1.2.3 From fbd1b99babd5065b62b4b16a6e622dddc33838bc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 23 Oct 2015 23:39:50 +0200 Subject: Renamed "power-utilities.zsh" to just "utilities.zsh". --- functions/power-utilities.zsh | 190 ------------------------------------------ functions/utilities.zsh | 190 ++++++++++++++++++++++++++++++++++++++++++ powerlevel9k.zsh-theme | 2 +- 3 files changed, 191 insertions(+), 191 deletions(-) delete mode 100644 functions/power-utilities.zsh create mode 100644 functions/utilities.zsh (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/power-utilities.zsh b/functions/power-utilities.zsh deleted file mode 100644 index be0ffc86..00000000 --- a/functions/power-utilities.zsh +++ /dev/null @@ -1,190 +0,0 @@ -# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 -################################################################ -# power-functions -# This file holds some utility-functions for -# the powerlevel9k-ZSH-theme -# https://github.com/bhilburn/powerlevel9k -################################################################ -################################################################ -# Utility functions -################################################################ - -# Exits with 0 if a variable has been previously defined (even if empty) -# Takes the name of a variable that should be checked. -function defined() { - local varname="$1" - - typeset -p "$varname" > /dev/null 2>&1 -} - -# Given the name of a variable and a default value, sets the variable -# value to the default only if it has not been defined. -# -# Typeset cannot set the value for an array, so this will only work -# for scalar values. -function set_default() { - local varname="$1" - local default_value="$2" - - defined "$varname" || typeset -g "$varname"="$default_value" -} - -# Safety function for printing icons -# Prints the named icon, or if that icon is undefined, the string name. -function print_icon() { - local icon_name=$1 - local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} - local USER_ICON=${(P)ICON_USER_VARIABLE} - if defined "$ICON_USER_VARIABLE"; then - echo -n "$USER_ICON" - else - echo -n "${icons[$icon_name]}" - fi -} - -# Get numerical color codes. That way we translate ANSI codes -# into ZSH-Style color codes. -function getColorCode() { - # Check if given value is already numerical - if [[ "$1" = <-> ]]; then - # ANSI color codes distinguish between "foreground" - # and "background" colors. We don't need to do that, - # as ZSH uses a 256 color space anyway. - if [[ "$1" = <8-15> ]]; then - echo $(($1 - 8)) - else - echo "$1" - fi - else - typeset -A codes - codes=( - 'black' '000' - 'red' '001' - 'green' '002' - 'yellow' '003' - 'blue' '004' - 'magenta' '005' - 'cyan' '006' - 'white' '007' - ) - - # Strip eventual "bg-" prefixes - 1=${1#bg-} - # Strip eventual "fg-" prefixes - 1=${1#fg-} - # Strip eventual "br" prefixes ("bright" colors) - 1=${1#br} - echo $codes[$1] - fi -} - -# Check if two colors are equal, even if one is specified as ANSI code. -function isSameColor() { - if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then - return 1 - fi - - local color1=$(getColorCode "$1") - local color2=$(getColorCode "$2") - - return $(( color1 != color2 )) -} - -# Converts large memory values into a human-readable unit (e.g., bytes --> GB) -printSizeHumanReadable() { - typeset -F 2 size - size="$1"+0.00001 - local extension - extension=('B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y') - local index=1 - - # if the base is not Bytes - if [[ -n $2 ]]; then - for idx in "${extension[@]}"; do - if [[ "$2" == "$idx" ]]; then - break - fi - index=$(( index + 1 )) - done - fi - - while (( (size / 1024) > 0.1 )); do - size=$(( size / 1024 )) - index=$(( index + 1 )) - done - - echo "$size${extension[$index]}" -} - -# Gets the first value out of a list of items that is not empty. -# The items are examined by a callback-function. -# Takes two arguments: -# * $list - A list of items -# * $callback - A callback function to examine if the item is -# worthy. The callback function has access to -# the inner variable $item. -function getRelevantItem() { - setopt shwordsplit # We need to split the words in $interfaces - - local list callback - list=$1 - callback=$2 - - for item in $list; do - # The first non-empty item wins - try=$(eval "$callback") - if [[ -n "$try" ]]; then - echo "$try" - break; - fi - done -} - -get_icon_names() { - for key in ${(@k)icons}; do - echo "POWERLEVEL9K_$key: ${icons[$key]}" - done -} - -# OS detection for the `os_icon` segment -case $(uname) in - Darwin) - OS='OSX' - OS_ICON=$(print_icon 'APPLE_ICON') - ;; - FreeBSD) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - OpenBSD) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - DragonFly) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - Linux) - OS='Linux' - OS_ICON=$(print_icon 'LINUX_ICON') - ;; - SunOS) - OS='Solaris' - OS_ICON=$(print_icon 'SUNOS_ICON') - ;; - *) - OS='' - OS_ICON='' - ;; -esac - -# Determine the correct sed parameter. -# -# `sed` is unfortunately not consistent across OSes when it comes to flags. -SED_EXTENDED_REGEX_PARAMETER="-r" -if [[ "$OS" == 'OSX' ]]; then - local IS_BSD_SED="$(sed --version &>> /dev/null || echo "BSD sed")" - if [[ -n "$IS_BSD_SED" ]]; then - SED_EXTENDED_REGEX_PARAMETER="-E" - fi -fi diff --git a/functions/utilities.zsh b/functions/utilities.zsh new file mode 100644 index 00000000..be0ffc86 --- /dev/null +++ b/functions/utilities.zsh @@ -0,0 +1,190 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# power-functions +# This file holds some utility-functions for +# the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ +################################################################ +# Utility functions +################################################################ + +# Exits with 0 if a variable has been previously defined (even if empty) +# Takes the name of a variable that should be checked. +function defined() { + local varname="$1" + + typeset -p "$varname" > /dev/null 2>&1 +} + +# Given the name of a variable and a default value, sets the variable +# value to the default only if it has not been defined. +# +# Typeset cannot set the value for an array, so this will only work +# for scalar values. +function set_default() { + local varname="$1" + local default_value="$2" + + defined "$varname" || typeset -g "$varname"="$default_value" +} + +# Safety function for printing icons +# Prints the named icon, or if that icon is undefined, the string name. +function print_icon() { + local icon_name=$1 + local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} + local USER_ICON=${(P)ICON_USER_VARIABLE} + if defined "$ICON_USER_VARIABLE"; then + echo -n "$USER_ICON" + else + echo -n "${icons[$icon_name]}" + fi +} + +# Get numerical color codes. That way we translate ANSI codes +# into ZSH-Style color codes. +function getColorCode() { + # Check if given value is already numerical + if [[ "$1" = <-> ]]; then + # ANSI color codes distinguish between "foreground" + # and "background" colors. We don't need to do that, + # as ZSH uses a 256 color space anyway. + if [[ "$1" = <8-15> ]]; then + echo $(($1 - 8)) + else + echo "$1" + fi + else + typeset -A codes + codes=( + 'black' '000' + 'red' '001' + 'green' '002' + 'yellow' '003' + 'blue' '004' + 'magenta' '005' + 'cyan' '006' + 'white' '007' + ) + + # Strip eventual "bg-" prefixes + 1=${1#bg-} + # Strip eventual "fg-" prefixes + 1=${1#fg-} + # Strip eventual "br" prefixes ("bright" colors) + 1=${1#br} + echo $codes[$1] + fi +} + +# Check if two colors are equal, even if one is specified as ANSI code. +function isSameColor() { + if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then + return 1 + fi + + local color1=$(getColorCode "$1") + local color2=$(getColorCode "$2") + + return $(( color1 != color2 )) +} + +# Converts large memory values into a human-readable unit (e.g., bytes --> GB) +printSizeHumanReadable() { + typeset -F 2 size + size="$1"+0.00001 + local extension + extension=('B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y') + local index=1 + + # if the base is not Bytes + if [[ -n $2 ]]; then + for idx in "${extension[@]}"; do + if [[ "$2" == "$idx" ]]; then + break + fi + index=$(( index + 1 )) + done + fi + + while (( (size / 1024) > 0.1 )); do + size=$(( size / 1024 )) + index=$(( index + 1 )) + done + + echo "$size${extension[$index]}" +} + +# Gets the first value out of a list of items that is not empty. +# The items are examined by a callback-function. +# Takes two arguments: +# * $list - A list of items +# * $callback - A callback function to examine if the item is +# worthy. The callback function has access to +# the inner variable $item. +function getRelevantItem() { + setopt shwordsplit # We need to split the words in $interfaces + + local list callback + list=$1 + callback=$2 + + for item in $list; do + # The first non-empty item wins + try=$(eval "$callback") + if [[ -n "$try" ]]; then + echo "$try" + break; + fi + done +} + +get_icon_names() { + for key in ${(@k)icons}; do + echo "POWERLEVEL9K_$key: ${icons[$key]}" + done +} + +# OS detection for the `os_icon` segment +case $(uname) in + Darwin) + OS='OSX' + OS_ICON=$(print_icon 'APPLE_ICON') + ;; + FreeBSD) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + OpenBSD) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + DragonFly) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + Linux) + OS='Linux' + OS_ICON=$(print_icon 'LINUX_ICON') + ;; + SunOS) + OS='Solaris' + OS_ICON=$(print_icon 'SUNOS_ICON') + ;; + *) + OS='' + OS_ICON='' + ;; +esac + +# Determine the correct sed parameter. +# +# `sed` is unfortunately not consistent across OSes when it comes to flags. +SED_EXTENDED_REGEX_PARAMETER="-r" +if [[ "$OS" == 'OSX' ]]; then + local IS_BSD_SED="$(sed --version &>> /dev/null || echo "BSD sed")" + if [[ -n "$IS_BSD_SED" ]]; then + SED_EXTENDED_REGEX_PARAMETER="-E" + fi +fi diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0dc15ebe..2db7e84b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -198,7 +198,7 @@ fi # Source utility functions ################################################################ -source $(dirname "$0")/functions/power-utilities.zsh +source $(dirname "$0")/functions/utilities.zsh ################################################################ # Color Scheme -- cgit v1.2.3 From d6584e13dac22ffa6318c9624aa76f60a3add7bf Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 23 Oct 2015 23:42:59 +0200 Subject: Extracted icons into a separate file. --- functions/icons.zsh | 200 ++++++++++++++++++++++++++++++++++++++++++++++++ functions/utilities.zsh | 24 +----- powerlevel9k.zsh-theme | 175 +----------------------------------------- 3 files changed, 203 insertions(+), 196 deletions(-) create mode 100644 functions/icons.zsh (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/icons.zsh b/functions/icons.zsh new file mode 100644 index 00000000..fb2683b2 --- /dev/null +++ b/functions/icons.zsh @@ -0,0 +1,200 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# icons +# This file holds the icon definitions and +# icon-functions for the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ + +# These characters require the Powerline fonts to work properly. If you see +# boxes or bizarre characters below, your fonts are not correctly installed. If +# you do not want to install a special font, you can set `POWERLEVEL9K_MODE` to +# `compatible`. This shows all icons in regular symbols. + +# Initialize the icon list according to the user's `POWERLEVEL9K_MODE`. +typeset -gAH icons +case $POWERLEVEL9K_MODE in + 'flat'|'awesome-patched') + # Awesome-Patched Font required! See: + # https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\UE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\UE0B2' #  + LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  + CARRIAGE_RETURN_ICON $'\U21B5' # ↵ + ROOT_ICON $'\UE801' #  + RUBY_ICON $'\UE847' #  + AWS_ICON $'\UE895' #  + BACKGROUND_JOBS_ICON $'\UE82F ' #  + TEST_ICON $'\UE891' #  + TODO_ICON $'\U2611' # ☑ + BATTERY_ICON $'\UE894' #  + OK_ICON $'\U2713' # ✓ + FAIL_ICON $'\U2718' # ✘ + SYMFONY_ICON 'SF' + NODE_ICON $'\U2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\U256D'$'\U2500' + MULTILINE_SECOND_PROMPT_PREFIX $'\U2570'$'\U2500 ' + APPLE_ICON $'\UE26E' #  + FREEBSD_ICON $'\U1F608 ' # 😈 + LINUX_ICON $'\UE271' #  + SUNOS_ICON $'\U1F31E ' # 🌞 + HOME_ICON $'\UE12C ' #  + NETWORK_ICON $'\UE1AD ' #  + LOAD_ICON $'\UE190 ' #  + #RAM_ICON $'\UE87D' #  + RAM_ICON $'\UE1E2 ' #  + VCS_UNTRACKED_ICON $'\UE16C' #  + VCS_UNSTAGED_ICON $'\UE17C' #  + VCS_STAGED_ICON $'\UE168' #  + VCS_STASH_ICON $'\UE133 ' #  + #VCS_INCOMING_CHANGES_ICON $'\UE1EB ' #  + #VCS_INCOMING_CHANGES_ICON $'\UE80D ' #  + VCS_INCOMING_CHANGES_ICON $'\UE131 ' #  + #VCS_OUTGOING_CHANGES_ICON $'\UE1EC ' #  + #VCS_OUTGOING_CHANGES_ICON $'\UE80E ' #  + VCS_OUTGOING_CHANGES_ICON $'\UE132 ' #  + VCS_TAG_ICON $'\UE817 ' #  + VCS_BOOKMARK_ICON $'\UE87B' #  + VCS_COMMIT_ICON $'\UE821 ' #  + VCS_BRANCH_ICON $'\UE220' #  + VCS_REMOTE_BRANCH_ICON ' '$'\UE804 ' #  + VCS_GIT_ICON $'\UE20E ' #  + VCS_HG_ICON $'\UE1C3 ' #  + ) + ;; + 'awesome-fontconfig') + # fontconfig with awesome-font required! See + # https://github.com/gabrielelana/awesome-terminal-fonts + icons=( + LEFT_SEGMENT_SEPARATOR $'\UE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\UE0B2' #  + LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  + CARRIAGE_RETURN_ICON $'\U21B5' # ↵ + ROOT_ICON $'\uF201' #  + RUBY_ICON $'\UF247' #  + AWS_ICON $'\UF296' #  + BACKGROUND_JOBS_ICON $'\UF013 ' #  + TEST_ICON $'\UF291' #  + TODO_ICON $'\U2611' # ☑ + BATTERY_ICON $'\u1F50B' # 🔋 + OK_ICON $'\UF23A' #  + FAIL_ICON $'\UF281' #  + SYMFONY_ICON 'SF' + NODE_ICON $'\U2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\U256D'$'\U2500' # ╭─ + MULTILINE_SECOND_PROMPT_PREFIX $'\U2570'$'\U2500 ' # ╰─ + APPLE_ICON $'\UF179' #  + FREEBSD_ICON $'\U1F608 ' # 😈 + LINUX_ICON $'\UF17C' #  + SUNOS_ICON $'\UF185 ' #  + HOME_ICON $'\UF015 ' #  + NETWORK_ICON $'\UF09E ' #  + LOAD_ICON $'\UF080 ' #  + RAM_ICON $'\UF0E4' #  + VCS_UNTRACKED_ICON $'\UF059' #  + VCS_UNSTAGED_ICON $'\UF06A' #  + VCS_STAGED_ICON $'\UF055' #  + VCS_STASH_ICON $'\UF01C ' #  + VCS_INCOMING_CHANGES_ICON $'\UF01A ' #  + VCS_OUTGOING_CHANGES_ICON $'\UF01B ' #  + VCS_TAG_ICON $'\UF217 ' #  + VCS_BOOKMARK_ICON $'\UF27B' #  + VCS_COMMIT_ICON $'\UF221 ' #  + VCS_BRANCH_ICON $'\UF126' #  + VCS_REMOTE_BRANCH_ICON ' '$'\UF204 ' #  + VCS_GIT_ICON $'\UF113 ' #  + VCS_HG_ICON $'\UF0C3 ' #  + ) + ;; + *) + # Powerline-Patched Font required! + # See https://github.com/Lokaltog/powerline-fonts + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  + CARRIAGE_RETURN_ICON $'\U21B5' # ↵ + ROOT_ICON $'\u26A1' # ⚡ + RUBY_ICON '' + AWS_ICON 'AWS:' + BACKGROUND_JOBS_ICON $'\u2699' # ⚙ + TEST_ICON '' + TODO_ICON $'\U2611' # ☑ + BATTERY_ICON $'\u1F50B' # 🔋 + OK_ICON $'\u2713' # ✓ + FAIL_ICON $'\u2718' # ✘ + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\u2500' + MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\u2500 ' + APPLE_ICON 'OSX' + FREEBSD_ICON 'BSD' + LINUX_ICON 'Lx' + SUNOS_ICON 'Sun' + HOME_ICON '' + NETWORK_ICON 'IP' + LOAD_ICON 'L' + RAM_ICON 'RAM' + VCS_UNTRACKED_ICON '?' + VCS_UNSTAGED_ICON $'\u25CF' # ● + VCS_STAGED_ICON $'\u271A' # ✚ + VCS_STASH_ICON $'\u235F' # ⍟ + VCS_INCOMING_CHANGES_ICON $'\u2193' # ↓ + VCS_OUTGOING_CHANGES_ICON $'\u2191' # ↑ + VCS_TAG_ICON '' + VCS_BOOKMARK_ICON $'\u263F' # ☿ + VCS_COMMIT_ICON '' + VCS_BRANCH_ICON $'\uE0A0 ' #  + VCS_REMOTE_BRANCH_ICON $'\u2192' # → + VCS_GIT_ICON '' + VCS_HG_ICON '' + ) + ;; +esac + +# Override the above icon settings with any user-defined variables. +case $POWERLEVEL9K_MODE in + 'flat') + icons[LEFT_SEGMENT_SEPARATOR]='' + icons[RIGHT_SEGMENT_SEPARATOR]='' + icons[LEFT_SUBSEGMENT_SEPARATOR]='|' + icons[RIGHT_SUBSEGMENT_SEPARATOR]='|' + ;; + 'compatible') + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons[LEFT_SEGMENT_SEPARATOR]=$'\u2B80' # ⮀ + icons[RIGHT_SEGMENT_SEPARATOR]=$'\u2B82' # ⮂ + icons[VCS_BRANCH_ICON]='@' + ;; +esac + +if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then + icons[VCS_BRANCH_ICON]='' +fi + +# Safety function for printing icons +# Prints the named icon, or if that icon is undefined, the string name. +function print_icon() { + local icon_name=$1 + local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} + local USER_ICON=${(P)ICON_USER_VARIABLE} + if defined "$ICON_USER_VARIABLE"; then + echo -n "$USER_ICON" + else + echo -n "${icons[$icon_name]}" + fi +} + +get_icon_names() { + for key in ${(@k)icons}; do + echo "POWERLEVEL9K_$key: ${icons[$key]}" + done +} + diff --git a/functions/utilities.zsh b/functions/utilities.zsh index be0ffc86..4c2d637a 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -1,13 +1,10 @@ # vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 ################################################################ -# power-functions +# Utility functions # This file holds some utility-functions for # the powerlevel9k-ZSH-theme # https://github.com/bhilburn/powerlevel9k ################################################################ -################################################################ -# Utility functions -################################################################ # Exits with 0 if a variable has been previously defined (even if empty) # Takes the name of a variable that should be checked. @@ -29,19 +26,6 @@ function set_default() { defined "$varname" || typeset -g "$varname"="$default_value" } -# Safety function for printing icons -# Prints the named icon, or if that icon is undefined, the string name. -function print_icon() { - local icon_name=$1 - local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} - local USER_ICON=${(P)ICON_USER_VARIABLE} - if defined "$ICON_USER_VARIABLE"; then - echo -n "$USER_ICON" - else - echo -n "${icons[$icon_name]}" - fi -} - # Get numerical color codes. That way we translate ANSI codes # into ZSH-Style color codes. function getColorCode() { @@ -140,12 +124,6 @@ function getRelevantItem() { done } -get_icon_names() { - for key in ${(@k)icons}; do - echo "POWERLEVEL9K_$key: ${icons[$key]}" - done -} - # OS detection for the `os_icon` segment case $(uname) in Darwin) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2db7e84b..6deea404 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -18,181 +18,10 @@ #set -o xtrace ################################################################ -# Icons +# Source icon functions ################################################################ -# These characters require the Powerline fonts to work properly. If you see -# boxes or bizarre characters below, your fonts are not correctly installed. If -# you do not want to install a special font, you can set `POWERLEVEL9K_MODE` to -# `compatible`. This shows all icons in regular symbols. - -# Initialize the icon list according to the user's `POWERLEVEL9K_MODE`. -typeset -gAH icons -case $POWERLEVEL9K_MODE in - 'flat'|'awesome-patched') - # Awesome-Patched Font required! See: - # https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - icons=( - LEFT_SEGMENT_SEPARATOR $'\UE0B0' #  - RIGHT_SEGMENT_SEPARATOR $'\UE0B2' #  - LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  - RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  - CARRIAGE_RETURN_ICON $'\U21B5' # ↵ - ROOT_ICON $'\UE801' #  - RUBY_ICON $'\UE847' #  - AWS_ICON $'\UE895' #  - BACKGROUND_JOBS_ICON $'\UE82F ' #  - TEST_ICON $'\UE891' #  - TODO_ICON $'\U2611' # ☑ - BATTERY_ICON $'\UE894' #  - OK_ICON $'\U2713' # ✓ - FAIL_ICON $'\U2718' # ✘ - SYMFONY_ICON 'SF' - NODE_ICON $'\U2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\U256D'$'\U2500' - MULTILINE_SECOND_PROMPT_PREFIX $'\U2570'$'\U2500 ' - APPLE_ICON $'\UE26E' #  - FREEBSD_ICON $'\U1F608 ' # 😈 - LINUX_ICON $'\UE271' #  - SUNOS_ICON $'\U1F31E ' # 🌞 - HOME_ICON $'\UE12C ' #  - NETWORK_ICON $'\UE1AD ' #  - LOAD_ICON $'\UE190 ' #  - #RAM_ICON $'\UE87D' #  - RAM_ICON $'\UE1E2 ' #  - VCS_UNTRACKED_ICON $'\UE16C' #  - VCS_UNSTAGED_ICON $'\UE17C' #  - VCS_STAGED_ICON $'\UE168' #  - VCS_STASH_ICON $'\UE133 ' #  - #VCS_INCOMING_CHANGES_ICON $'\UE1EB ' #  - #VCS_INCOMING_CHANGES_ICON $'\UE80D ' #  - VCS_INCOMING_CHANGES_ICON $'\UE131 ' #  - #VCS_OUTGOING_CHANGES_ICON $'\UE1EC ' #  - #VCS_OUTGOING_CHANGES_ICON $'\UE80E ' #  - VCS_OUTGOING_CHANGES_ICON $'\UE132 ' #  - VCS_TAG_ICON $'\UE817 ' #  - VCS_BOOKMARK_ICON $'\UE87B' #  - VCS_COMMIT_ICON $'\UE821 ' #  - VCS_BRANCH_ICON $'\UE220' #  - VCS_REMOTE_BRANCH_ICON ' '$'\UE804 ' #  - VCS_GIT_ICON $'\UE20E ' #  - VCS_HG_ICON $'\UE1C3 ' #  - ) - ;; - 'awesome-fontconfig') - # fontconfig with awesome-font required! See - # https://github.com/gabrielelana/awesome-terminal-fonts - icons=( - LEFT_SEGMENT_SEPARATOR $'\UE0B0' #  - RIGHT_SEGMENT_SEPARATOR $'\UE0B2' #  - LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  - RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  - CARRIAGE_RETURN_ICON $'\U21B5' # ↵ - ROOT_ICON $'\uF201' #  - RUBY_ICON $'\UF247' #  - AWS_ICON $'\UF296' #  - BACKGROUND_JOBS_ICON $'\UF013 ' #  - TEST_ICON $'\UF291' #  - TODO_ICON $'\U2611' # ☑ - BATTERY_ICON $'\u1F50B' # 🔋 - OK_ICON $'\UF23A' #  - FAIL_ICON $'\UF281' #  - SYMFONY_ICON 'SF' - NODE_ICON $'\U2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\U256D'$'\U2500' # ╭─ - MULTILINE_SECOND_PROMPT_PREFIX $'\U2570'$'\U2500 ' # ╰─ - APPLE_ICON $'\UF179' #  - FREEBSD_ICON $'\U1F608 ' # 😈 - LINUX_ICON $'\UF17C' #  - SUNOS_ICON $'\UF185 ' #  - HOME_ICON $'\UF015 ' #  - NETWORK_ICON $'\UF09E ' #  - LOAD_ICON $'\UF080 ' #  - RAM_ICON $'\UF0E4' #  - VCS_UNTRACKED_ICON $'\UF059' #  - VCS_UNSTAGED_ICON $'\UF06A' #  - VCS_STAGED_ICON $'\UF055' #  - VCS_STASH_ICON $'\UF01C ' #  - VCS_INCOMING_CHANGES_ICON $'\UF01A ' #  - VCS_OUTGOING_CHANGES_ICON $'\UF01B ' #  - VCS_TAG_ICON $'\UF217 ' #  - VCS_BOOKMARK_ICON $'\UF27B' #  - VCS_COMMIT_ICON $'\UF221 ' #  - VCS_BRANCH_ICON $'\UF126' #  - VCS_REMOTE_BRANCH_ICON ' '$'\UF204 ' #  - VCS_GIT_ICON $'\UF113 ' #  - VCS_HG_ICON $'\UF0C3 ' #  - ) - ;; - *) - # Powerline-Patched Font required! - # See https://github.com/Lokaltog/powerline-fonts - icons=( - LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  - RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  - LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  - RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  - CARRIAGE_RETURN_ICON $'\U21B5' # ↵ - ROOT_ICON $'\u26A1' # ⚡ - RUBY_ICON '' - AWS_ICON 'AWS:' - BACKGROUND_JOBS_ICON $'\u2699' # ⚙ - TEST_ICON '' - TODO_ICON $'\U2611' # ☑ - BATTERY_ICON $'\u1F50B' # 🔋 - OK_ICON $'\u2713' # ✓ - FAIL_ICON $'\u2718' # ✘ - SYMFONY_ICON 'SF' - NODE_ICON $'\u2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\u2500' - MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\u2500 ' - APPLE_ICON 'OSX' - FREEBSD_ICON 'BSD' - LINUX_ICON 'Lx' - SUNOS_ICON 'Sun' - HOME_ICON '' - NETWORK_ICON 'IP' - LOAD_ICON 'L' - RAM_ICON 'RAM' - VCS_UNTRACKED_ICON '?' - VCS_UNSTAGED_ICON $'\u25CF' # ● - VCS_STAGED_ICON $'\u271A' # ✚ - VCS_STASH_ICON $'\u235F' # ⍟ - VCS_INCOMING_CHANGES_ICON $'\u2193' # ↓ - VCS_OUTGOING_CHANGES_ICON $'\u2191' # ↑ - VCS_TAG_ICON '' - VCS_BOOKMARK_ICON $'\u263F' # ☿ - VCS_COMMIT_ICON '' - VCS_BRANCH_ICON $'\uE0A0 ' #  - VCS_REMOTE_BRANCH_ICON $'\u2192' # → - VCS_GIT_ICON '' - VCS_HG_ICON '' - ) - ;; -esac - -# Override the above icon settings with any user-defined variables. -case $POWERLEVEL9K_MODE in - 'flat') - icons[LEFT_SEGMENT_SEPARATOR]='' - icons[RIGHT_SEGMENT_SEPARATOR]='' - icons[LEFT_SUBSEGMENT_SEPARATOR]='|' - icons[RIGHT_SUBSEGMENT_SEPARATOR]='|' - ;; - 'compatible') - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - icons[LEFT_SEGMENT_SEPARATOR]=$'\u2B80' # ⮀ - icons[RIGHT_SEGMENT_SEPARATOR]=$'\u2B82' # ⮂ - icons[VCS_BRANCH_ICON]='@' - ;; -esac - -if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then - icons[VCS_BRANCH_ICON]='' -fi +source $(dirname "$0")/functions/icons.zsh ################################################################ # Source utility functions -- cgit v1.2.3 From 2b8cb5b9a47c0e97a501a3e804dc7089619c1e9a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 24 Oct 2015 00:05:15 +0200 Subject: Extracted VCS-hooks into a separate file. --- functions/vcs.zsh | 87 +++++++++++++++++++++ powerlevel9k.zsh-theme | 201 ++++++++++++++++--------------------------------- 2 files changed, 150 insertions(+), 138 deletions(-) create mode 100644 functions/vcs.zsh (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/vcs.zsh b/functions/vcs.zsh new file mode 100644 index 00000000..39d0fdae --- /dev/null +++ b/functions/vcs.zsh @@ -0,0 +1,87 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# vcs +# This file holds supplemental VCS functions +# for the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ + +function +vi-git-untracked() { + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \ + -n $(git ls-files --others --exclude-standard | sed q) ]]; then + hook_com[unstaged]+=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_UNTRACKED_ICON')%f" + fi +} + +function +vi-git-aheadbehind() { + local ahead behind branch_name + local -a gitstatus + + branch_name=$(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 )) && gitstatus+=( " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}%f" ) + + # 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 )) && gitstatus+=( " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}%f" ) + + hook_com[misc]+=${(j::)gitstatus} +} + +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) + + hook_com[branch]="%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}%f" + # Always show the remote + #if [[ -n ${remote} ]] ; then + # Only show the remote if it differs from the local + if [[ -n ${remote} ]] && [[ "${remote#*/}" != "${branch_name}" ]] ; then + hook_com[branch]+="%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_REMOTE_BRANCH_ICON')%f%F{$POWERLEVEL9K_VCS_FOREGROUND}${remote// /}%f" + fi +} + +function +vi-git-tagname() { + local tag + + tag=$(git describe --tags --exact-match HEAD 2>/dev/null) + [[ -n "${tag}" ]] && hook_com[branch]=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_TAG_ICON')${tag}%f" +} + +# Show count of stashed changes +# Port from https://github.com/whiteinge/dotfiles/blob/5dfd08d30f7f2749cfc60bc55564c6ea239624d9/.zsh_shouse_prompt#L268 +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) + hook_com[misc]+=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_STASH_ICON')${stashes// /}%f" + fi +} + +function +vi-hg-bookmarks() { + if [[ -n "${hgbmarks[@]}" ]]; then + hook_com[hg-bookmark-string]=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_BOOKMARK_ICON')${hgbmarks[@]}%f" + + # To signal that we want to use the sting we just generated, set the special + # variable `ret' to something other than the default zero: + ret=1 + return 0 + fi +} + +function +vi-vcs-detect-changes() { + if [[ -n "${hook_com[staged]}" ]] || [[ -n "${hook_com[unstaged]}" ]]; then + VCS_WORKDIR_DIRTY=true + else + VCS_WORKDIR_DIRTY=false + fi +} + diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 6deea404..8804e5ca 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -29,6 +29,12 @@ source $(dirname "$0")/functions/icons.zsh source $(dirname "$0")/functions/utilities.zsh +################################################################ +# Source VCS_INFO hooks / helper functions +################################################################ + +source $(dirname "$0")/functions/vcs.zsh + ################################################################ # Color Scheme ################################################################ @@ -158,144 +164,6 @@ right_prompt_segment() { CURRENT_RIGHT_BG=$2 } -################################################################ -# The `vcs` Segment and VCS_INFO hooks / helper functions -################################################################ -prompt_vcs() { - autoload -Uz vcs_info - - VCS_WORKDIR_DIRTY=false - VCS_CHANGESET_PREFIX='' - if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then - # Default: Just display the first 12 characters of our changeset-ID. - local VCS_CHANGESET_HASH_LENGTH=12 - if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then - VCS_CHANGESET_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" - fi - - VCS_CHANGESET_PREFIX="%F{$POWERLEVEL9K_VCS_DARK_FOREGROUND}$(print_icon 'VCS_COMMIT_ICON')%0.$VCS_CHANGESET_HASH_LENGTH""i%f " - fi - - zstyle ':vcs_info:*' enable git hg - zstyle ':vcs_info:*' check-for-changes true - - VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%F{$POWERLEVEL9K_VCS_FOREGROUND}%b%c%u%m%f" - zstyle ':vcs_info:git*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_GIT_ICON')%f$VCS_DEFAULT_FORMAT" - zstyle ':vcs_info:hg*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_HG_ICON')%f$VCS_DEFAULT_FORMAT" - - zstyle ':vcs_info:*' actionformats "%b %F{red}| %a%f" - - zstyle ':vcs_info:*' stagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_STAGED_ICON')%f" - zstyle ':vcs_info:*' unstagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_UNSTAGED_ICON')%f" - - zstyle ':vcs_info:git*+set-message:*' hooks vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname - zstyle ':vcs_info:hg*+set-message:*' hooks vcs-detect-changes - - # For Hg, only show the branch name - zstyle ':vcs_info:hg*:*' branchformat "$(print_icon 'VCS_BRANCH_ICON')%b" - # The `get-revision` function must be turned on for dirty-check to work for Hg - zstyle ':vcs_info:hg*:*' get-revision true - zstyle ':vcs_info:hg*:*' get-bookmarks true - zstyle ':vcs_info:hg*+gen-hg-bookmark-string:*' hooks hg-bookmarks - - if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then - zstyle ':vcs_info:*' get-revision true - fi - - # Actually invoke vcs_info manually to gather all information. - vcs_info - local vcs_prompt="${vcs_info_msg_0_}" - - if [[ -n "$vcs_prompt" ]]; then - if [[ "$VCS_WORKDIR_DIRTY" == true ]]; then - "$1_prompt_segment" "$0_MODIFIED" "yellow" "$DEFAULT_COLOR" - else - "$1_prompt_segment" "$0" "green" "$DEFAULT_COLOR" - fi - - echo -n "$vcs_prompt " - fi -} - -function +vi-git-untracked() { - if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \ - -n $(git ls-files --others --exclude-standard | sed q) ]]; then - hook_com[unstaged]+=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_UNTRACKED_ICON')%f" - fi -} - -function +vi-git-aheadbehind() { - local ahead behind branch_name - local -a gitstatus - - branch_name=$(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 )) && gitstatus+=( " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}%f" ) - - # 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 )) && gitstatus+=( " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}%f" ) - - hook_com[misc]+=${(j::)gitstatus} -} - -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) - - hook_com[branch]="%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}%f" - # Always show the remote - #if [[ -n ${remote} ]] ; then - # Only show the remote if it differs from the local - if [[ -n ${remote} ]] && [[ "${remote#*/}" != "${branch_name}" ]] ; then - hook_com[branch]+="%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_REMOTE_BRANCH_ICON')%f%F{$POWERLEVEL9K_VCS_FOREGROUND}${remote// /}%f" - fi -} - -function +vi-git-tagname() { - local tag - - tag=$(git describe --tags --exact-match HEAD 2>/dev/null) - [[ -n "${tag}" ]] && hook_com[branch]=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_TAG_ICON')${tag}%f" -} - -# Show count of stashed changes -# Port from https://github.com/whiteinge/dotfiles/blob/5dfd08d30f7f2749cfc60bc55564c6ea239624d9/.zsh_shouse_prompt#L268 -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) - hook_com[misc]+=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_STASH_ICON')${stashes// /}%f" - fi -} - -function +vi-hg-bookmarks() { - if [[ -n "${hgbmarks[@]}" ]]; then - hook_com[hg-bookmark-string]=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_BOOKMARK_ICON')${hgbmarks[@]}%f" - - # To signal that we want to use the sting we just generated, set the special - # variable `ret' to something other than the default zero: - ret=1 - return 0 - fi -} - -function +vi-vcs-detect-changes() { - if [[ -n "${hook_com[staged]}" ]] || [[ -n "${hook_com[unstaged]}" ]]; then - VCS_WORKDIR_DIRTY=true - else - VCS_WORKDIR_DIRTY=false - fi -} - ################################################################ # Prompt Segment Definitions ################################################################ @@ -685,6 +553,63 @@ prompt_todo() { fi } +# VCS segment: shows the state of your repository, if you are in a folder under version control +prompt_vcs() { + autoload -Uz vcs_info + + VCS_WORKDIR_DIRTY=false + VCS_CHANGESET_PREFIX='' + if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then + # Default: Just display the first 12 characters of our changeset-ID. + local VCS_CHANGESET_HASH_LENGTH=12 + if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then + VCS_CHANGESET_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" + fi + + VCS_CHANGESET_PREFIX="%F{$POWERLEVEL9K_VCS_DARK_FOREGROUND}$(print_icon 'VCS_COMMIT_ICON')%0.$VCS_CHANGESET_HASH_LENGTH""i%f " + fi + + zstyle ':vcs_info:*' enable git hg + zstyle ':vcs_info:*' check-for-changes true + + VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%F{$POWERLEVEL9K_VCS_FOREGROUND}%b%c%u%m%f" + zstyle ':vcs_info:git*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_GIT_ICON')%f$VCS_DEFAULT_FORMAT" + zstyle ':vcs_info:hg*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_HG_ICON')%f$VCS_DEFAULT_FORMAT" + + zstyle ':vcs_info:*' actionformats "%b %F{red}| %a%f" + + zstyle ':vcs_info:*' stagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_STAGED_ICON')%f" + zstyle ':vcs_info:*' unstagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_UNSTAGED_ICON')%f" + + zstyle ':vcs_info:git*+set-message:*' hooks vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname + zstyle ':vcs_info:hg*+set-message:*' hooks vcs-detect-changes + + # For Hg, only show the branch name + zstyle ':vcs_info:hg*:*' branchformat "$(print_icon 'VCS_BRANCH_ICON')%b" + # The `get-revision` function must be turned on for dirty-check to work for Hg + zstyle ':vcs_info:hg*:*' get-revision true + zstyle ':vcs_info:hg*:*' get-bookmarks true + zstyle ':vcs_info:hg*+gen-hg-bookmark-string:*' hooks hg-bookmarks + + if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then + zstyle ':vcs_info:*' get-revision true + fi + + # Actually invoke vcs_info manually to gather all information. + vcs_info + local vcs_prompt="${vcs_info_msg_0_}" + + if [[ -n "$vcs_prompt" ]]; then + if [[ "$VCS_WORKDIR_DIRTY" == true ]]; then + "$1_prompt_segment" "$0_MODIFIED" "yellow" "$DEFAULT_COLOR" + else + "$1_prompt_segment" "$0" "green" "$DEFAULT_COLOR" + fi + + echo -n "$vcs_prompt " + fi +} + # Vi Mode: show editing mode (NORMAL|INSERT) set_default POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT" set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL" -- cgit v1.2.3 From 0fa635275c99e66b14c972a8aa01cda7343035bf Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 24 Oct 2015 01:05:37 +0200 Subject: Extracted color functions to a separate file. --- functions/colors.zsh | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ functions/utilities.zsh | 48 ------------------------------------------ powerlevel9k.zsh-theme | 6 ++++++ 3 files changed, 62 insertions(+), 48 deletions(-) create mode 100644 functions/colors.zsh (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/colors.zsh b/functions/colors.zsh new file mode 100644 index 00000000..c82af9ea --- /dev/null +++ b/functions/colors.zsh @@ -0,0 +1,56 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# Color functions +# This file holds some color-functions for +# the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ + +# Get numerical color codes. That way we translate ANSI codes +# into ZSH-Style color codes. +function getColorCode() { + # Check if given value is already numerical + if [[ "$1" = <-> ]]; then + # ANSI color codes distinguish between "foreground" + # and "background" colors. We don't need to do that, + # as ZSH uses a 256 color space anyway. + if [[ "$1" = <8-15> ]]; then + echo $(($1 - 8)) + else + echo "$1" + fi + else + typeset -A codes + codes=( + 'black' '000' + 'red' '001' + 'green' '002' + 'yellow' '003' + 'blue' '004' + 'magenta' '005' + 'cyan' '006' + 'white' '007' + ) + + # Strip eventual "bg-" prefixes + 1=${1#bg-} + # Strip eventual "fg-" prefixes + 1=${1#fg-} + # Strip eventual "br" prefixes ("bright" colors) + 1=${1#br} + echo $codes[$1] + fi +} + +# Check if two colors are equal, even if one is specified as ANSI code. +function isSameColor() { + if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then + return 1 + fi + + local color1=$(getColorCode "$1") + local color2=$(getColorCode "$2") + + return $(( color1 != color2 )) +} + diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 4c2d637a..80a38977 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -26,54 +26,6 @@ function set_default() { defined "$varname" || typeset -g "$varname"="$default_value" } -# Get numerical color codes. That way we translate ANSI codes -# into ZSH-Style color codes. -function getColorCode() { - # Check if given value is already numerical - if [[ "$1" = <-> ]]; then - # ANSI color codes distinguish between "foreground" - # and "background" colors. We don't need to do that, - # as ZSH uses a 256 color space anyway. - if [[ "$1" = <8-15> ]]; then - echo $(($1 - 8)) - else - echo "$1" - fi - else - typeset -A codes - codes=( - 'black' '000' - 'red' '001' - 'green' '002' - 'yellow' '003' - 'blue' '004' - 'magenta' '005' - 'cyan' '006' - 'white' '007' - ) - - # Strip eventual "bg-" prefixes - 1=${1#bg-} - # Strip eventual "fg-" prefixes - 1=${1#fg-} - # Strip eventual "br" prefixes ("bright" colors) - 1=${1#br} - echo $codes[$1] - fi -} - -# Check if two colors are equal, even if one is specified as ANSI code. -function isSameColor() { - if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then - return 1 - fi - - local color1=$(getColorCode "$1") - local color2=$(getColorCode "$2") - - return $(( color1 != color2 )) -} - # Converts large memory values into a human-readable unit (e.g., bytes --> GB) printSizeHumanReadable() { typeset -F 2 size diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8804e5ca..f903efcd 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -29,6 +29,12 @@ source $(dirname "$0")/functions/icons.zsh source $(dirname "$0")/functions/utilities.zsh +################################################################ +# Source color functions +################################################################ + +source $(dirname "$0")/functions/colors.zsh + ################################################################ # Source VCS_INFO hooks / helper functions ################################################################ -- cgit v1.2.3 From 29693f957d237df0109acf66544a93e6f4ee4c33 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 4 Nov 2015 00:40:11 +0100 Subject: If the theme-file is linked, dereference that link and source the right functions. --- powerlevel9k.zsh-theme | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f903efcd..32a03b94 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -17,29 +17,37 @@ #zstyle ':vcs_info:*+*:*' debug true #set -o xtrace +# Check if filename is a symlink. +if [[ -L "$0" ]]; then + filename="$(realpath -P $0 2>/dev/null || readlink -f $0 2>/dev/null)" +else + filename="$0" +fi +script_location="$(dirname $filename)" + ################################################################ # Source icon functions ################################################################ -source $(dirname "$0")/functions/icons.zsh +source $script_location/functions/icons.zsh ################################################################ # Source utility functions ################################################################ -source $(dirname "$0")/functions/utilities.zsh +source $script_location/functions/utilities.zsh ################################################################ # Source color functions ################################################################ -source $(dirname "$0")/functions/colors.zsh +source $script_location/functions/colors.zsh ################################################################ # Source VCS_INFO hooks / helper functions ################################################################ -source $(dirname "$0")/functions/vcs.zsh +source $script_location/functions/vcs.zsh ################################################################ # Color Scheme -- cgit v1.2.3 From 538d8b8fa8b4fbfe4fdcab6e57867d1e6b434c5a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 7 Nov 2015 16:32:48 +0100 Subject: Bugfix for prezto: In prezto the theme gets called by function (via zstyle). In that case we hardcode the path to the theme as there seems no way to find the location so that we can source our other functions. --- powerlevel9k.zsh-theme | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 32a03b94..b35dafda 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -17,11 +17,23 @@ #zstyle ':vcs_info:*+*:*' debug true #set -o xtrace +# Check if the theme was called as a function. +if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then + # Script is a function! We assume this to happen only in + # prezto, as they use the zstyle-builtin to set the theme. + 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" +fi + # Check if filename is a symlink. -if [[ -L "$0" ]]; then +if [[ -L $0 ]]; then + # Script is a symlink filename="$(realpath -P $0 2>/dev/null || readlink -f $0 2>/dev/null)" -else +elif [[ -f $0 ]]; then + # Script is a file filename="$0" +else + print -P "%F{red}Script location could not be found!%f" + exit 1 fi script_location="$(dirname $filename)" -- cgit v1.2.3 From eef5286005422528cb2a941876ff35bbfe5c07da Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 11 Nov 2015 22:00:19 +0100 Subject: Issue #131: This fixes history-substring-search, home and end keys. --- powerlevel9k.zsh-theme | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index a9ce64b1..0d4b3e7c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -922,12 +922,26 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" function zle-line-init { powerlevel9k_prepare_prompts + if (( ${+terminfo[smkx]} )); then + printf '%s' ${terminfo[smkx]} + fi + zle reset-prompt + zle -R +} + +function zle-line-finish { + powerlevel9k_prepare_prompts + if (( ${+terminfo[rmkx]} )); then + printf '%s' ${terminfo[rmkx]} + fi zle reset-prompt + zle -R } function zle-keymap-select { powerlevel9k_prepare_prompts zle reset-prompt + zle -R } powerlevel9k_init() { @@ -954,6 +968,7 @@ powerlevel9k_init() { add-zsh-hook precmd powerlevel9k_prepare_prompts zle -N zle-line-init + zle -N zle-line-finish zle -N zle-keymap-select } -- cgit v1.2.3 From 81a4b3907de32b3dfb54fe6b626c1aa2b5faa13b Mon Sep 17 00:00:00 2001 From: Stéphane Dupille Date: Fri, 13 Nov 2015 12:06:03 +0100 Subject: Get terminal capabilities using a zsh builtin for portability --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0d4b3e7c..b039f0d7 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -947,7 +947,7 @@ function zle-keymap-select { powerlevel9k_init() { # Display a warning if the terminal does not support 256 colors local term_colors - term_colors=$(tput colors) + term_colors=$(echotc Co) if (( term_colors < 256 )); then print -P "%F{red}WARNING!%f Your terminal supports less than 256 colors!" print -P "You should put: %F{blue}export TERM=\"xterm-256color\"%f in your \~\/.zshrc" -- cgit v1.2.3 From 643555a30c9576838157e04d45632080472e1b8b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 15 Nov 2015 23:35:15 +0100 Subject: Huge performance improvement if you use `rvm` segment. Thanks to @rjorgenson for the hint. --- powerlevel9k.zsh-theme | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b4f993ec..9b0f31bd 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -492,10 +492,13 @@ prompt_rspec_stats() { # Ruby Version Manager information prompt_rvm() { - local rvm_prompt - rvm_prompt=$(rvm-prompt) - if [ "$rvm_prompt" != "" ]; then - "$1_prompt_segment" "$0" "240" "$DEFAULT_COLOR" "$rvm_prompt $(print_icon 'RUBY_ICON') " + local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') + [ "$gemset" != "" ] && gemset="@$gemset" + + local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') + + if [[ -n "$version$gemset" ]]; then + "$1_prompt_segment" "$0" "240" "$DEFAULT_COLOR" "$version$gemset $(print_icon 'RUBY_ICON') " fi } -- cgit v1.2.3 From 5d314bec8e6465feca3a757d4e8a9a626d322561 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 30 Sep 2015 20:12:47 +0200 Subject: Add segment for rust version. --- powerlevel9k.zsh-theme | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b4f993ec..982024f5 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -479,6 +479,15 @@ prompt_rbenv() { fi } +# 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\\\-]*$') + + if [[ -n "$rust_version" ]]; then + "$1_prompt_segment" "$0" "208" "$DEFAULT_COLOR" "$rust_version" + fi +} # RSpec test ratio prompt_rspec_stats() { if [[ (-d app && -d spec) ]]; then -- cgit v1.2.3 From c81863e23429aeadb70a89764c489d0728fd59c3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 1 Oct 2015 17:35:11 +0200 Subject: Add an Identifier to version. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 982024f5..b8a53822 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -485,7 +485,7 @@ prompt_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" "208" "$DEFAULT_COLOR" "$rust_version" + "$1_prompt_segment" "$0" "208" "$DEFAULT_COLOR" "Rust $rust_version" fi } # RSpec test ratio -- cgit v1.2.3 From ce7b99cdaf4459afb7d7043cae25e4f02489ba87 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 17 Nov 2015 01:39:49 +0100 Subject: Added a mechanism to make deprecated segments visible to the user. --- functions/utilities.zsh | 15 +++++++++++++++ powerlevel9k.zsh-theme | 8 ++++++++ 2 files changed, 23 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 80a38977..3c6a4d49 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -118,3 +118,18 @@ if [[ "$OS" == 'OSX' ]]; then SED_EXTENDED_REGEX_PARAMETER="-E" fi fi + +# Print a deprecation warning if an old segment is in use. +# Takes the name of an associative array that contains the +# deprecated segments as keys, the values contain the new +# segment names. +print_deprecation_warning() { + local -A raw_deprecated_segments=(${(kvP)1}) + + for key in ${(@k)raw_deprecated_segments}; do + if [[ -n "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[(r)$key]}" ]] || [[ -n "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[(r)$key]}" ]]; then + # segment is deprecated + print -P "%F{yellow}Warning!%f The '$key' segment is deprecated. Use '%F{blue}${raw_deprecated_segments[$key]}%f' instead. For more informations, have a look at the CHANGELOG.md." + fi + done +} diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0707276d..7f3af8a7 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -754,6 +754,14 @@ powerlevel9k_init() { print -P "You should put: %F{blue}export TERM=\"xterm-256color\"%f in your \~\/.zshrc" fi + typeset -Ah deprecated_segments + # old => new + deprecated_segments=( + 'longstatus' 'status' + ) + print_deprecation_warning deprecated_segments + + setopt prompt_subst setopt LOCAL_OPTIONS -- cgit v1.2.3 From f9957ca5592df0ab992d3750e18ee6f61b3e3002 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 17 Nov 2015 18:34:18 +0100 Subject: Used typeset to define the local array. This does the trick on linux. --- functions/utilities.zsh | 3 ++- powerlevel9k.zsh-theme | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 3c6a4d49..f855caf5 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -124,7 +124,8 @@ fi # deprecated segments as keys, the values contain the new # segment names. print_deprecation_warning() { - local -A raw_deprecated_segments=(${(kvP)1}) + typeset -AH raw_deprecated_segments + raw_deprecated_segments=(${(kvP@)1}) for key in ${(@k)raw_deprecated_segments}; do if [[ -n "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[(r)$key]}" ]] || [[ -n "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[(r)$key]}" ]]; then diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7f3af8a7..cdcb9a96 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -754,14 +754,14 @@ powerlevel9k_init() { print -P "You should put: %F{blue}export TERM=\"xterm-256color\"%f in your \~\/.zshrc" fi - typeset -Ah deprecated_segments + # Display a warning if deprecated segments are in use. + typeset -AH deprecated_segments # old => new deprecated_segments=( 'longstatus' 'status' ) print_deprecation_warning deprecated_segments - setopt prompt_subst setopt LOCAL_OPTIONS -- cgit v1.2.3 From 47eb8f10ac798cada32e91613bdcde8a44378a2f Mon Sep 17 00:00:00 2001 From: Matthías Páll Gissurarson Date: Tue, 17 Nov 2015 20:06:49 +0100 Subject: added variable to have rprompt on the newline --- powerlevel9k.zsh-theme | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b039f0d7..3fe2c708 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -901,14 +901,19 @@ powerlevel9k_prepare_prompts() { if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then PROMPT="$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%{%f%b%k%}$(build_left_prompt) $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" - # The right prompt should be on the same line as the first line of the left - # prompt. To do so, there is just a quite ugly workaround: Before zsh draws - # the RPROMPT, we advise it, to go one line up. At the end of RPROMPT, we - # advise it to go one line down. See: - # http://superuser.com/questions/357107/zsh-right-justify-in-ps1 - local LC_ALL="" LC_CTYPE="en_US.UTF-8" # Set the right locale to protect special characters - RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up - RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down + if [[ "$POWERLEVEL9K_RPROMPT_ON_NEWLINE" != true ]]; then + # The right prompt should be on the same line as the first line of the left + # prompt. To do so, there is just a quite ugly workaround: Before zsh draws + # the RPROMPT, we advise it, to go one line up. At the end of RPROMPT, we + # advise it to go one line down. See: + # http://superuser.com/questions/357107/zsh-right-justify-in-ps1 + local LC_ALL="" LC_CTYPE="en_US.UTF-8" # Set the right locale to protect special characters + RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up + RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down + else + RPROMPT_PREFIX='' + RPROMPT_SUFFIX='' + fi else PROMPT="%{%f%b%k%}$(build_left_prompt)" RPROMPT_PREFIX='' -- cgit v1.2.3 From 231cfda8090d352ca378ea23967a19e2884d672e Mon Sep 17 00:00:00 2001 From: Matthías Páll Gissurarson Date: Tue, 17 Nov 2015 21:18:31 +0100 Subject: added icon to be able to set the end of the prompt explicitly --- functions/icons.zsh | 3 +++ powerlevel9k.zsh-theme | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/icons.zsh b/functions/icons.zsh index fb2683b2..dd256b06 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -22,6 +22,7 @@ case $POWERLEVEL9K_MODE in icons=( LEFT_SEGMENT_SEPARATOR $'\UE0B0' #  RIGHT_SEGMENT_SEPARATOR $'\UE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  CARRIAGE_RETURN_ICON $'\U21B5' # ↵ @@ -72,6 +73,7 @@ case $POWERLEVEL9K_MODE in icons=( LEFT_SEGMENT_SEPARATOR $'\UE0B0' #  RIGHT_SEGMENT_SEPARATOR $'\UE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  CARRIAGE_RETURN_ICON $'\U21B5' # ↵ @@ -117,6 +119,7 @@ case $POWERLEVEL9K_MODE in icons=( LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace LEFT_SUBSEGMENT_SEPARATOR $'\UE0B1' #  RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  CARRIAGE_RETURN_ICON $'\U21B5' # ↵ diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index cdcb9a96..f9249da7 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -144,7 +144,7 @@ left_prompt_end() { else echo -n "%k" fi - echo -n "%f " + echo -n "%{%f%}$(print_icon 'LEFT_SEGMENT_END_SEPARATOR')" CURRENT_BG='' } -- cgit v1.2.3 From 36fa3f2277504c3092a2bcfa8725c7ea4cf11bf2 Mon Sep 17 00:00:00 2001 From: Matthías Páll Gissurarson Date: Wed, 18 Nov 2015 21:34:07 +0100 Subject: fix some issues with the battery segment --- powerlevel9k.zsh-theme | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d71a5cf0..bf5a1f38 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -213,10 +213,11 @@ prompt_battery() { # set default values of not specified in shell [[ -z $POWERLEVEL9K_BATTERY_CHARGING ]] && POWERLEVEL9K_BATTERY_CHARGING="yellow" [[ -z $POWERLEVEL9K_BATTERY_CHARGED ]] && POWERLEVEL9K_BATTERY_CHARGED="green" - [[ -z $POWERLEVEL9K_BATTERY_DISCONNECTED ]] && POWERLEVEL9K_BATTERY_DISCONNECTED="$DEFAULT_COLOR" + [[ -z $POWERLEVEL9K_BATTERY_DISCONNECTED ]] && POWERLEVEL9K_BATTERY_DISCONNECTED="$DEFAULT_COLOR_INVERTED" [[ -z $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && POWERLEVEL9K_BATTERY_LOW_THRESHOLD=10 [[ -z $POWERLEVEL9K_BATTERY_LOW_COLOR ]] && POWERLEVEL9K_BATTERY_LOW_COLOR="red" - [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local fg_color="$DEFAULT_COLOR" || local fg_color=$POWERLEVEL9K_BATTERY_FOREGROUND + [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local fg_color="" || local fg_color="%F{$POWERLEVEL9K_BATTERY_FOREGROUND}" + [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local conn="$DEFAULT_COLOR_INVERTED" || local conn="$POWERLEVEL9K_BATTERY_FOREGROUND" if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then # return if there is no battery on system @@ -240,10 +241,10 @@ prompt_battery() { [[ ! -z $max_capacity && ! -z $current_capacity ]] && local bat_percent=$(ruby -e "puts ($current_capacity.to_f / $max_capacity.to_f * 100).round.to_i") # logic for string output - [[ $charging =~ true && $connected =~ true ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGING}" && local remain=" ($tstring)" - [[ ! $charging =~ true && $connected =~ true ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGED}" && local remain="" + [[ $charging =~ true && $connected =~ true ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGING" && local remain=" ($tstring)" + [[ ! $charging =~ true && $connected =~ true ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGED" && local remain="" if [[ ! $connected =~ true ]]; then - [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="%F{$POWERLEVEL9K_BATTERY_LOW_COLOR}" || local conn="%F{$POWERLEVEL9K_BATTERY_DISCONNECTED}" + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local conn="$POWERLEVEL9K_BATTERY_DISCONNECTED" local remain=" ($tstring)" fi fi @@ -256,27 +257,26 @@ prompt_battery() { # return if no battery found [[ -z $bat ]] && return - [[ $(cat $bat/capacity) -gt 100 ]] && local bat_percent=100 || local bat_percent=$(cat $bat/capacity) [[ $(cat $bat/status) =~ Charging ]] && local connected=true - [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGED}" - [[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && local conn="%F{$POWERLEVEL9K_BATTERY_CHARGING}" - if [[ ! $connected =~ true ]]; then - [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="%F{$POWERLEVEL9K_BATTERY_LOW_COLOR}" || local conn="%F{$POWERLEVEL9K_BATTERY_DISCONNECTED}" + [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGED" + [[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGING" + if [[ -z $connected ]]; then + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local conn="$POWERLEVEL9K_BATTERY_DISCONNECTED" fi if [[ -f /usr/bin/acpi ]]; then local time_remaining=$(acpi | awk '{ print $5 }') if [[ $time_remaining =~ rate ]]; then local tstring="..." elif [[ $time_remaining =~ "[:digit:]+" ]]; then - local tstring=${(f)$(date -u -d @$(echo $time_remaining | sed s/://g) +%k:%M)} + local tstring=${(f)$(date -u -d "$(echo $time_remaining)" +%k:%M)} fi fi [[ ! -z $tstring ]] && local remain=" ($tstring)" fi # display prompt_segment - [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "black" "$DEFAULT_COLOR" "$conn$(print_icon 'BATTERY_ICON')%F{$fg_color} $bat_percent%%$remain" + [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "%F{$conn}$(print_icon 'BATTERY_ICON')$fg_color $bat_percent%%$remain%f" } # Context: user@hostname (who am I and where am I) -- cgit v1.2.3 From 0aaf99985754cc0759ca3b7e94bdee111d5a94f8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:04:58 +0100 Subject: For ZSH 5.0.8 `whence -v` tells also the path to the command. In that case we can use that information to get a proper path to the utility functions. --- powerlevel9k.zsh-theme | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 002267f4..727461d1 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -19,9 +19,15 @@ # Check if the theme was called as a function. if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then - # Script is a function! We assume this to happen only in - # prezto, as they use the zstyle-builtin to set the theme. - 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + autoload -U is-at-least + if is-at-least 5.0.8; then + # Try to find the correct path of the script. + 0=$(whence -v $0 | sed "s/$0 is a shell function from //") + else + # Script is a function! We assume this to happen only in + # prezto, as they use the zstyle-builtin to set the theme. + 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + fi fi # Check if filename is a symlink. -- cgit v1.2.3 From a0323b7e8075a8b59d671a48484117e5152bebf9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:26:50 +0100 Subject: The installation path of powerlevel9k is now configurable by setting the variable POWERLEVEL9K_INSTALLATION_PATH. The value must be set to the exact location of the powerlevel9k.zsh-theme file (including the file name). This has only effect if you load your theme as a function and your ZSH version is below 5.0.8. --- powerlevel9k.zsh-theme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 727461d1..29f9804c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -26,7 +26,9 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then else # Script is a function! We assume this to happen only in # prezto, as they use the zstyle-builtin to set the theme. - 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]] && POWERLEVEL9K_INSTALLATION_PATH="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + + 0=$POWERLEVEL9K_INSTALLATION_PATH fi fi -- cgit v1.2.3 From 727b3e501b9f534871ed3ec0d5d6dbca1344a5c5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:29:20 +0100 Subject: Now the script just returns instead of exiting with an errorcode. The reason for this is that users can't log in anymore if the specified a wrong path in POWERLEVEL9K_INSTALLATION_PATH and the script `exit`s. With `return` not the whole shell is terminated, so users get an ugly prompt, but are still able to modify .zshrc. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 29f9804c..f0cbd9f2 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -41,7 +41,7 @@ elif [[ -f $0 ]]; then filename="$0" else print -P "%F{red}Script location could not be found!%f" - exit 1 + return 1 fi script_location="$(dirname $filename)" -- cgit v1.2.3 From df51db14129bc8fb1fa90f9e8aa3ab653fbe247a Mon Sep 17 00:00:00 2001 From: Matthías Páll Gissurarson Date: Wed, 18 Nov 2015 23:45:22 +0100 Subject: added a segment to be able to display the result of a custom command. --- CHANGELOG.md | 4 ++++ README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ powerlevel9k.zsh-theme | 25 +++++++++++++++++++++-- 3 files changed, 81 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/CHANGELOG.md b/CHANGELOG.md index 933eceaa..8c21ea0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## v0.3.0 (next) +### New segment `custom_command` added + +A new segment that allows users to define a custom command was added. + ### `virtualenv` changes This segment now respects `VIRTUAL_ENV_DISABLE_PROMPT`. If this variable is set diff --git a/README.md b/README.md index 4d225d14..6a690bfd 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ The segments that are currently available are: * [aws](#aws) - The current AWS profile, if active. * [battery](#battery) - Current battery status. * [context](#context) - Your username and host. +* [custom_command](#custom_command) - A custom command to display the output of. * [dir](#dir) - Your current working directory. * **go_version** - Show the current GO version. * **history** - The command number for the current line. @@ -121,6 +122,59 @@ In addition to the above it supports standard _FOREGROUND value without affectin Supports both OS X and Linux(time remaining requires the acpi program on Linux) +##### custom_command + +The `custom_...` segment lets you add a custom command to your prompt, to e.g. display the wifi signal. You choose a name for the segment yourself, (here signal), and then set the appropriate variables, as so (based on the name you chose) + + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_signal) + POWERLEVEL9K_CUSTOM_SIGNAL="echo signal: \$(nmcli device wifi | grep yes | awk '{print \$8}')" + POWERLEVEL9K_CUSTOM_SIGNAL_BACKGROUND="blue" + POWERLEVEL9K_CUSTOM_SIGNAL_FOREGROUND="yellow" + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(aws status load ram) + +gives + +![simplesignal](http://i.imgur.com/SQmYVFL.png) + +Instead of defining the command inline (if it is kinda long or unreadable), one can also add a function to the .zshrc like: + + zsh_signal(){ + local signal=$(nmcli device wifi | grep yes | awk '{print $8}') + local color='%F{yellow}' + [[ $signal -gt 75 ]] && color='%F{green}' + [[ $signal -lt 50 ]] && color='%F{red}' + echo -n "%{$color%}\uf230 $signal%{%f%}" # \uf230 is  + } + +And then by changing the custom commands array (and rearranging a bit the prompt elements) to read: + + POWERLEVEL9K_CUSTOM_SIGNAL="zsh_signal" + +Then this updated command looks like: + +![signal](http://i.imgur.com/hviMATC.png) + +You can also have multiple custom commands. Say you have + + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery custom_signal dir vcs virtualenv custom_time ) + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(aws status load ram custom_docker) + + POWERLEVEL9K_CUSTOM_SIGNAL="zsh_signal" + POWERLEVEL9K_CUSTOM_SIGNAL_FOREGROUND="white" + POWERLEVEL9K_CUSTOM_SIGNAL_BACKGROUND="black" + + POWERLEVEL9K_CUSTOM_DOCKER='echo "\uf299 $(docker ps -a | grep Up | wc -l)"' # \uf299 is  + POWERLEVEL9K_CUSTOM_DOCKER_FOREGROUND="white" + POWERLEVEL9K_CUSTOM_DOCKER_BACKGROUND="blue" + + POWERLEVEL9K_CUSTOM_TIME='echo "$(date +%s)"' + POWERLEVEL9K_CUSTOM_TIME_FOREGROUND="black" + POWERLEVEL9K_CUSTOM_TIME_BACKGROUND="yellow" + + +Then you get: + +![](http://i.imgur.com/QGGBTqY.png) ##### context diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index cdcb9a96..abab9d8e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -208,6 +208,15 @@ prompt_aws() { fi } +# Custom: a way for the user to specify custom commands to run, +# and display the output of. +# +prompt_custom() { + local command=POWERLEVEL9K_CUSTOM_$2:u + + "$1_prompt_segment" "${0}_${2:u}" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" +} + prompt_battery() { icons[BATTERY_ICON]=$'\UE894' # set default values of not specified in shell @@ -681,7 +690,13 @@ build_left_prompt() { defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do - "prompt_$element" "left" + # Check if it is a custom command, otherwise interpet it as + # a prompt. + if [[ $element[0,7] =~ "custom_" ]]; then + "prompt_custom" "left" $element[8,-1] + else + "prompt_$element" "left" + fi done left_prompt_end @@ -692,7 +707,13 @@ build_right_prompt() { defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do - "prompt_$element" "right" + # Check if it is a custom command, otherwise interpet it as + # a prompt. + if [[ $element[0,7] =~ "custom_" ]]; then + "prompt_custom" "right" $element[8,-1] + else + "prompt_$element" "right" + fi done } -- cgit v1.2.3 From 351dc843204b983214e516142439383457926d84 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 23:20:38 +0100 Subject: Fix for the GO version. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 002267f4..2a791db5 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -317,7 +317,7 @@ prompt_dir() { # GO-prompt prompt_go_version() { local go_version - go_version=$(go version 2>&1 | grep -oe "^go[0-9.]*") + go_version=$(go version 2>&1 | sed -E "s/.*(go[0-9.]*).*/\1/") if [[ -n "$go_version" ]]; then "$1_prompt_segment" "$0" "green" "255" "$go_version" -- cgit v1.2.3 From 49a3a3e750fd20e7f01829209b1b5fbfbeeb4b41 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 22 Nov 2015 00:04:55 +0100 Subject: The `nvm` segment should use the standard node icon (rather than defining an own icon). --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 002267f4..371ac31e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -468,8 +468,8 @@ prompt_nvm() { local nvm_default=$(cat $NVM_DIR/alias/default) [[ -z "${node_version}" ]] && return [[ "$node_version" =~ "$nvm_default" ]] && return - NODE_ICON=$'\u2B22' # ⬢ - $1_prompt_segment "$0" "green" "011" "${node_version:1} $NODE_ICON" + + $1_prompt_segment "$0" "green" "011" "${node_version:1} $(print_icon 'NODE_ICON')" } # rbenv information -- cgit v1.2.3 From 4b636d226ede68bdd621cd382182959491bf747a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 22 Nov 2015 00:08:43 +0100 Subject: Renamed variable. --- powerlevel9k.zsh-theme | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 371ac31e..362077bb 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -395,11 +395,10 @@ prompt_load() { # Node version prompt_node_version() { - local nvm_prompt - nvm_prompt=$(node -v 2>/dev/null) - [[ -z "${nvm_prompt}" ]] && return + local node_version=$(node -v 2>/dev/null) + [[ -z "${node_version}" ]] && return - "$1_prompt_segment" "$0" "green" "white" "${nvm_prompt:1} $(print_icon 'NODE_ICON')" + "$1_prompt_segment" "$0" "green" "white" "${node_version:1} $(print_icon 'NODE_ICON')" } # print a little OS icon -- cgit v1.2.3 From 7774294113603e8fd4e3c6f1c1c6fb5aeae6cdb2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:09:37 +0100 Subject: Performance improvement by calculating the battery percentage with zsh. --- powerlevel9k.zsh-theme | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 002267f4..5b14647a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -238,7 +238,12 @@ prompt_battery() { local max_capacity=$(ioreg -n AppleSmartBattery | grep MaxCapacity | awk '{ print $5 }') local current_capacity=$(ioreg -n AppleSmartBattery | grep CurrentCapacity | awk '{ print $5 }') - [[ ! -z $max_capacity && ! -z $current_capacity ]] && local bat_percent=$(ruby -e "puts ($current_capacity.to_f / $max_capacity.to_f * 100).round.to_i") + if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then + typeset -F 2 current_capacity + current_capacity="$current_capacity"+0.00001 + typeset -i 10 bat_percent + bat_percent=$(( (current_capacity / max_capacity) * 100 )) + fi # logic for string output [[ $charging =~ true && $connected =~ true ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGING" && local remain=" ($tstring)" -- cgit v1.2.3 From c0efe9c342450b4d20488633a2e1bfd1e30ce7e0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:11:19 +0100 Subject: Performance improvement: Avoid aggregation of data over and over again by extracting a local variable. --- powerlevel9k.zsh-theme | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5b14647a..6fec74ca 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -220,23 +220,24 @@ prompt_battery() { [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local conn="$DEFAULT_COLOR_INVERTED" || local conn="$POWERLEVEL9K_BATTERY_FOREGROUND" if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then + local raw_data=$(ioreg -n AppleSmartBattery) # return if there is no battery on system - [[ -z $(ioreg -n AppleSmartBattery | grep MaxCapacity) ]] && return + [[ -z $(echo $raw_data | grep MaxCapacity) ]] && return # get charge status - [[ $(ioreg -n AppleSmartBattery | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]] && local connected=true - [[ $(ioreg -n AppleSmartBattery | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]] && local charging=true + [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]] && local connected=true + [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]] && local charging=true # convert time remaining from minutes to hours:minutes date string - local time_remaining=$(ioreg -n AppleSmartBattery | grep TimeRemaining | awk '{ print $5 }') + local time_remaining=$(echo $raw_data | grep TimeRemaining | awk '{ print $5 }') if [[ ! -z $time_remaining ]]; then # this value is set to a very high number when the system is calculating [[ $time_remaining -gt 10000 ]] && local tstring="..." || local tstring=${(f)$(date -u -r $(($time_remaining * 60)) +%k:%M)} fi # get charge values - local max_capacity=$(ioreg -n AppleSmartBattery | grep MaxCapacity | awk '{ print $5 }') - local current_capacity=$(ioreg -n AppleSmartBattery | grep CurrentCapacity | awk '{ print $5 }') + local max_capacity=$(echo $raw_data | grep MaxCapacity | awk '{ print $5 }') + local current_capacity=$(echo $raw_data | grep CurrentCapacity | awk '{ print $5 }') if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then typeset -F 2 current_capacity -- cgit v1.2.3 From b316089c6bca112c88f6030f4f5b70d4236f2dbc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:12:52 +0100 Subject: Make use of set_default method for better code readability. --- powerlevel9k.zsh-theme | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 6fec74ca..1f0069c3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -211,11 +211,11 @@ prompt_aws() { prompt_battery() { icons[BATTERY_ICON]=$'\UE894' # set default values of not specified in shell - [[ -z $POWERLEVEL9K_BATTERY_CHARGING ]] && POWERLEVEL9K_BATTERY_CHARGING="yellow" - [[ -z $POWERLEVEL9K_BATTERY_CHARGED ]] && POWERLEVEL9K_BATTERY_CHARGED="green" - [[ -z $POWERLEVEL9K_BATTERY_DISCONNECTED ]] && POWERLEVEL9K_BATTERY_DISCONNECTED="$DEFAULT_COLOR_INVERTED" - [[ -z $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && POWERLEVEL9K_BATTERY_LOW_THRESHOLD=10 - [[ -z $POWERLEVEL9K_BATTERY_LOW_COLOR ]] && POWERLEVEL9K_BATTERY_LOW_COLOR="red" + set_default POWERLEVEL9K_BATTERY_CHARGING "yellow" + set_default POWERLEVEL9K_BATTERY_CHARGED "green" + set_default POWERLEVEL9K_BATTERY_DISCONNECTED "$DEFAULT_COLOR_INVERTED" + set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 + set_default POWERLEVEL9K_BATTERY_LOW_COLOR "red" [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local fg_color="" || local fg_color="%F{$POWERLEVEL9K_BATTERY_FOREGROUND}" [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local conn="$DEFAULT_COLOR_INVERTED" || local conn="$POWERLEVEL9K_BATTERY_FOREGROUND" -- cgit v1.2.3 From 8d72b5eb123973f94e1188d697ca5e3e62d8269f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:42:15 +0100 Subject: Renamed variable "conn" to "icon_color" --- powerlevel9k.zsh-theme | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 1f0069c3..6faa6523 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -217,7 +217,7 @@ prompt_battery() { set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 set_default POWERLEVEL9K_BATTERY_LOW_COLOR "red" [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local fg_color="" || local fg_color="%F{$POWERLEVEL9K_BATTERY_FOREGROUND}" - [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local conn="$DEFAULT_COLOR_INVERTED" || local conn="$POWERLEVEL9K_BATTERY_FOREGROUND" + [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local icon_color="$DEFAULT_COLOR_INVERTED" || local icon_color="$POWERLEVEL9K_BATTERY_FOREGROUND" if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then local raw_data=$(ioreg -n AppleSmartBattery) @@ -247,10 +247,10 @@ prompt_battery() { fi # logic for string output - [[ $charging =~ true && $connected =~ true ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGING" && local remain=" ($tstring)" - [[ ! $charging =~ true && $connected =~ true ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGED" && local remain="" + [[ $charging =~ true && $connected =~ true ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGING" && local remain=" ($tstring)" + [[ ! $charging =~ true && $connected =~ true ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGED" && local remain="" if [[ ! $connected =~ true ]]; then - [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local conn="$POWERLEVEL9K_BATTERY_DISCONNECTED" + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local icon_color="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local icon_color="$POWERLEVEL9K_BATTERY_DISCONNECTED" local remain=" ($tstring)" fi fi @@ -265,10 +265,10 @@ prompt_battery() { [[ -z $bat ]] && return [[ $(cat $bat/capacity) -gt 100 ]] && local bat_percent=100 || local bat_percent=$(cat $bat/capacity) [[ $(cat $bat/status) =~ Charging ]] && local connected=true - [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGED" - [[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGING" + [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGED" + [[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGING" if [[ -z $connected ]]; then - [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local conn="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local conn="$POWERLEVEL9K_BATTERY_DISCONNECTED" + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local icon_color="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local icon_color="$POWERLEVEL9K_BATTERY_DISCONNECTED" fi if [[ -f /usr/bin/acpi ]]; then local time_remaining=$(acpi | awk '{ print $5 }') @@ -282,7 +282,7 @@ prompt_battery() { fi # display prompt_segment - [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "%F{$conn}$(print_icon 'BATTERY_ICON')$fg_color $bat_percent%%$remain%f" + [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "%F{$icon_color}$(print_icon 'BATTERY_ICON')$fg_color $bat_percent%%$remain%f" } # Context: user@hostname (who am I and where am I) -- cgit v1.2.3 From 239aa29a1287d58ad61e6b9ff342fb7a7f2bf31e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:48:59 +0100 Subject: Better use of test flags. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 6faa6523..7ce82e0a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -230,7 +230,7 @@ prompt_battery() { # convert time remaining from minutes to hours:minutes date string local time_remaining=$(echo $raw_data | grep TimeRemaining | awk '{ print $5 }') - if [[ ! -z $time_remaining ]]; then + if [[ -n $time_remaining ]]; then # this value is set to a very high number when the system is calculating [[ $time_remaining -gt 10000 ]] && local tstring="..." || local tstring=${(f)$(date -u -r $(($time_remaining * 60)) +%k:%M)} fi @@ -278,11 +278,11 @@ prompt_battery() { local tstring=${(f)$(date -u -d "$(echo $time_remaining)" +%k:%M)} fi fi - [[ ! -z $tstring ]] && local remain=" ($tstring)" + [[ -n $tstring ]] && local remain=" ($tstring)" fi # display prompt_segment - [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "%F{$icon_color}$(print_icon 'BATTERY_ICON')$fg_color $bat_percent%%$remain%f" + [[ -n $bat_percent ]] && "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "%F{$icon_color}$(print_icon 'BATTERY_ICON')$fg_color $bat_percent%%$remain%f" } # Context: user@hostname (who am I and where am I) -- cgit v1.2.3 From da2b8e342efa952dea4b664fac6179d75804a2b9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 18:10:09 +0100 Subject: Arithmetics in ZSH 101: If you want to calculate a percentage, multiply the numerator with 100 _before_ the devision. With that method there is no need for hacks to convert the numerator into a float. --- powerlevel9k.zsh-theme | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7ce82e0a..c1d1abf0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -240,10 +240,8 @@ prompt_battery() { local current_capacity=$(echo $raw_data | grep CurrentCapacity | awk '{ print $5 }') if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then - typeset -F 2 current_capacity - current_capacity="$current_capacity"+0.00001 typeset -i 10 bat_percent - bat_percent=$(( (current_capacity / max_capacity) * 100 )) + bat_percent=$(( (current_capacity * 100) / max_capacity )) fi # logic for string output -- cgit v1.2.3 From dad38b0592141fc4243fb8c67659a3a499f6cc4c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Nov 2015 02:36:37 +0100 Subject: Better code structure. --- powerlevel9k.zsh-theme | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c1d1abf0..989f04ce 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -224,10 +224,6 @@ prompt_battery() { # return if there is no battery on system [[ -z $(echo $raw_data | grep MaxCapacity) ]] && return - # get charge status - [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]] && local connected=true - [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]] && local charging=true - # convert time remaining from minutes to hours:minutes date string local time_remaining=$(echo $raw_data | grep TimeRemaining | awk '{ print $5 }') if [[ -n $time_remaining ]]; then @@ -244,12 +240,20 @@ prompt_battery() { bat_percent=$(( (current_capacity * 100) / max_capacity )) fi - # logic for string output - [[ $charging =~ true && $connected =~ true ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGING" && local remain=" ($tstring)" - [[ ! $charging =~ true && $connected =~ true ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGED" && local remain="" - if [[ ! $connected =~ true ]]; then + local remain="" + ## logic for string output + # Powerplug connected + if [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]]; then + # Battery is charging + if [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]]; then + icon_color="$POWERLEVEL9K_BATTERY_CHARGING" + remain=" ($tstring)" + else + icon_color="$POWERLEVEL9K_BATTERY_CHARGED" + fi + else [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local icon_color="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local icon_color="$POWERLEVEL9K_BATTERY_DISCONNECTED" - local remain=" ($tstring)" + remain=" ($tstring)" fi fi @@ -261,6 +265,7 @@ prompt_battery() { # return if no battery found [[ -z $bat ]] && return + [[ $(cat $bat/capacity) -gt 100 ]] && local bat_percent=100 || local bat_percent=$(cat $bat/capacity) [[ $(cat $bat/status) =~ Charging ]] && local connected=true [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGED" -- cgit v1.2.3 From c8137fcf1a8461fddb98ada19e03c40834287c21 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Nov 2015 18:17:04 +0100 Subject: Pre-Grep the raw data to save some memory and to avoid cluttering up the output of `setopt xtrace` too much. --- powerlevel9k.zsh-theme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 989f04ce..fb5e20d4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -220,7 +220,9 @@ prompt_battery() { [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local icon_color="$DEFAULT_COLOR_INVERTED" || local icon_color="$POWERLEVEL9K_BATTERY_FOREGROUND" if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then - local raw_data=$(ioreg -n AppleSmartBattery) + # Pre-Grep all needed informations to save some memory and + # as little pollution of the xtrace output as possible. + local raw_data=$(ioreg -n AppleSmartBattery | grep -E "MaxCapacity|TimeRemaining|CurrentCapacity|ExternalConnected|IsCharging") # return if there is no battery on system [[ -z $(echo $raw_data | grep MaxCapacity) ]] && return -- cgit v1.2.3 From 3437c7850cda86e85626e95216644f1fa420ddaa Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Nov 2015 18:31:22 +0100 Subject: Battery icon is already defined in the icons-array. --- powerlevel9k.zsh-theme | 1 - 1 file changed, 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index fb5e20d4..9eaebaae 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -209,7 +209,6 @@ prompt_aws() { } prompt_battery() { - icons[BATTERY_ICON]=$'\UE894' # set default values of not specified in shell set_default POWERLEVEL9K_BATTERY_CHARGING "yellow" set_default POWERLEVEL9K_BATTERY_CHARGED "green" -- cgit v1.2.3 From 323610cebf133ba998e5e5c964d2d41a547ba4b6 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Nov 2015 18:36:56 +0100 Subject: More structure to the battery segment: Now there is a concept of "states" that a battery can have. That makes the code much clearer and users could adjust the colors of these states as they want. --- powerlevel9k.zsh-theme | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 9eaebaae..ec447a47 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -209,14 +209,18 @@ prompt_aws() { } prompt_battery() { + # The battery can have different states. + # Default is "unknown" + local current_state="unknown" + typeset -AH battery_states + battery_states=( + 'low' 'red' + 'charging' 'yellow' + 'charged' 'green' + 'disconnected' "$DEFAULT_COLOR_INVERTED" + ) # set default values of not specified in shell - set_default POWERLEVEL9K_BATTERY_CHARGING "yellow" - set_default POWERLEVEL9K_BATTERY_CHARGED "green" - set_default POWERLEVEL9K_BATTERY_DISCONNECTED "$DEFAULT_COLOR_INVERTED" set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 - set_default POWERLEVEL9K_BATTERY_LOW_COLOR "red" - [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local fg_color="" || local fg_color="%F{$POWERLEVEL9K_BATTERY_FOREGROUND}" - [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local icon_color="$DEFAULT_COLOR_INVERTED" || local icon_color="$POWERLEVEL9K_BATTERY_FOREGROUND" if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then # Pre-Grep all needed informations to save some memory and @@ -247,13 +251,13 @@ prompt_battery() { if [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]]; then # Battery is charging if [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]]; then - icon_color="$POWERLEVEL9K_BATTERY_CHARGING" + current_state="charging" remain=" ($tstring)" else - icon_color="$POWERLEVEL9K_BATTERY_CHARGED" + current_state="charged" fi else - [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local icon_color="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local icon_color="$POWERLEVEL9K_BATTERY_DISCONNECTED" + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" remain=" ($tstring)" fi fi @@ -269,10 +273,10 @@ prompt_battery() { [[ $(cat $bat/capacity) -gt 100 ]] && local bat_percent=100 || local bat_percent=$(cat $bat/capacity) [[ $(cat $bat/status) =~ Charging ]] && local connected=true - [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGED" - [[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGING" + [[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && current_state="charged" + [[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && current_state="charging" if [[ -z $connected ]]; then - [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local icon_color="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local icon_color="$POWERLEVEL9K_BATTERY_DISCONNECTED" + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" fi if [[ -f /usr/bin/acpi ]]; then local time_remaining=$(acpi | awk '{ print $5 }') @@ -286,7 +290,7 @@ prompt_battery() { fi # display prompt_segment - [[ -n $bat_percent ]] && "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "%F{$icon_color}$(print_icon 'BATTERY_ICON')$fg_color $bat_percent%%$remain%f" + [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$(print_icon 'BATTERY_ICON') $bat_percent%%$remain" } # Context: user@hostname (who am I and where am I) -- cgit v1.2.3 From 23e2a5406718dfd9117de8b63825cf63ee195ff2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 25 Nov 2015 00:21:20 +0100 Subject: Added a verbose mode. --- powerlevel9k.zsh-theme | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ec447a47..76e75441 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -289,8 +289,14 @@ prompt_battery() { [[ -n $tstring ]] && local remain=" ($tstring)" fi + # prepare string + local message="$(print_icon 'BATTERY_ICON')" + if [[ "$POWERLEVEL9K_BATTERY_VERBOSE" == true ]]; then + message="$message $bat_percent%%$remain" + fi + # display prompt_segment - [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$(print_icon 'BATTERY_ICON') $bat_percent%%$remain" + [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" } # Context: user@hostname (who am I and where am I) -- cgit v1.2.3 From b8d7d1387e0a77ba4046db48c0fcad2c59773942 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 25 Nov 2015 00:26:10 +0100 Subject: By default: set verbose mode on. --- powerlevel9k.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 76e75441..595b233d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -291,6 +291,8 @@ prompt_battery() { # prepare string local message="$(print_icon 'BATTERY_ICON')" + # Default behavior: Be verbose! + set_default POWERLEVEL9K_BATTERY_VERBOSE true if [[ "$POWERLEVEL9K_BATTERY_VERBOSE" == true ]]; then message="$message $bat_percent%%$remain" fi -- cgit v1.2.3 From c10bac90ba55607fe19913d1e71571b83d8df6dc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 00:03:07 +0100 Subject: In Awesome-Mode either print a home-icon or a folder icon, depending in which directory the user is. --- functions/icons.zsh | 3 +++ powerlevel9k.zsh-theme | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/icons.zsh b/functions/icons.zsh index dd256b06..0cd6bb9d 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -44,6 +44,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON $'\UE271' #  SUNOS_ICON $'\U1F31E ' # 🌞 HOME_ICON $'\UE12C ' #  + FOLDER_ICON $'\UE818 ' #  NETWORK_ICON $'\UE1AD ' #  LOAD_ICON $'\UE190 ' #  #RAM_ICON $'\UE87D' #  @@ -95,6 +96,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON $'\UF17C' #  SUNOS_ICON $'\UF185 ' #  HOME_ICON $'\UF015 ' #  + FOLDER_ICON '' NETWORK_ICON $'\UF09E ' #  LOAD_ICON $'\UF080 ' #  RAM_ICON $'\UF0E4' #  @@ -141,6 +143,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON 'Lx' SUNOS_ICON 'Sun' HOME_ICON '' + FOLDER_ICON '' NETWORK_ICON 'IP' LOAD_ICON 'L' RAM_ICON 'RAM' diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 12659e5e..4c1aaa96 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -320,7 +320,14 @@ prompt_dir() { fi - "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$(print_icon 'HOME_ICON')$current_path" + local current_icon='' + if [[ "$current_path" == '~'* ]]; then + current_icon=$(print_icon 'HOME_ICON') + else + current_icon=$(print_icon 'FOLDER_ICON') + fi + + "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$current_icon$current_path" } # GO-prompt -- cgit v1.2.3 From 972e24ad4132694d3c366678eb942799d1cd09a1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:26:24 +0100 Subject: Added more checks to find the installation dir. Now we try to find prezto automatically and print a nice warning as a fallback. --- powerlevel9k.zsh-theme | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f0cbd9f2..dfada2e1 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -23,10 +23,16 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then if is-at-least 5.0.8; then # Try to find the correct path of the script. 0=$(whence -v $0 | sed "s/$0 is a shell function from //") + elif [[ -f "${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/init.zsh" ]]; then + # If there is an prezto installation, we assume that powerlevel9k is linked there. + 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" else - # Script is a function! We assume this to happen only in - # prezto, as they use the zstyle-builtin to set the theme. - [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]] && POWERLEVEL9K_INSTALLATION_PATH="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + # Fallback: specify an installation path! + if [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + print -P "%F{red}We could not locate the installation path of powerlevel9k.%f" + print -P "Please specify by setting %F{blue}POWERLEVEL9K_INSTALLATION_PATH%f (full path incl. file name) at the very beginning of your ~/.zshrc" + return 1 + fi 0=$POWERLEVEL9K_INSTALLATION_PATH fi -- cgit v1.2.3 From 46575182c78d441eacf928fd368a4c20b1aaa0b5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:33:33 +0100 Subject: Fallback mechanism is now more robust. If does not matter if the user specified a file or a directory in `POWERLEVEL9K_INSTALLATION_PATH`. --- powerlevel9k.zsh-theme | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dfada2e1..610b2cbe 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -32,6 +32,10 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then print -P "%F{red}We could not locate the installation path of powerlevel9k.%f" print -P "Please specify by setting %F{blue}POWERLEVEL9K_INSTALLATION_PATH%f (full path incl. file name) at the very beginning of your ~/.zshrc" return 1 + elif [[ -f "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + 0="$POWERLEVEL9K_INSTALLATION_PATH" + elif [[ -d "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + 0="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme" fi 0=$POWERLEVEL9K_INSTALLATION_PATH -- cgit v1.2.3 From b01588e2f96fdc0da8df8cef14895b1e22384da7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:56:26 +0100 Subject: File might be a symlink. --- powerlevel9k.zsh-theme | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 610b2cbe..624f7a57 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -32,9 +32,14 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then print -P "%F{red}We could not locate the installation path of powerlevel9k.%f" print -P "Please specify by setting %F{blue}POWERLEVEL9K_INSTALLATION_PATH%f (full path incl. file name) at the very beginning of your ~/.zshrc" return 1 + elif [[ -L "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + # Symlink + 0="$POWERLEVEL9K_INSTALLATION_PATH" elif [[ -f "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + # File 0="$POWERLEVEL9K_INSTALLATION_PATH" elif [[ -d "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + # Directory 0="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme" fi -- cgit v1.2.3 From 0dc36ee6148d0db99e3b580a7767e4f7b8f77c87 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 11:11:10 +0100 Subject: We need to always evaluate the path for the home/folder icon mechanism to work correctly. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4c1aaa96..47d6aa06 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -321,7 +321,7 @@ prompt_dir() { fi local current_icon='' - if [[ "$current_path" == '~'* ]]; then + if [[ $(print -P "%~") == '~'* ]]; then current_icon=$(print_icon 'HOME_ICON') else current_icon=$(print_icon 'FOLDER_ICON') -- cgit v1.2.3 From 8c71a28a77a3e2edebaaddd6245534f9f4514aaa Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 19:45:49 +0100 Subject: The script location should only be set once! --- powerlevel9k.zsh-theme | 2 -- 1 file changed, 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 624f7a57..bcdacd0e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -42,8 +42,6 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then # Directory 0="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme" fi - - 0=$POWERLEVEL9K_INSTALLATION_PATH fi fi -- cgit v1.2.3 From 5a4de1d2742e6e19a1ffb7ea8c418a923599391e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 13 Dec 2015 12:41:49 +0100 Subject: Split up the `status` segment into a `background_jobs`, `root_indicator` and `status` segment. This fixes #163 --- CHANGELOG.md | 6 ++++++ README.md | 11 ++++++----- powerlevel9k.zsh-theme | 35 ++++++++++++++++++++--------------- 3 files changed, 32 insertions(+), 20 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c21ea0e..66520d21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## v0.3.0 (next) +### `status` changes + +The `status` segment was split up into three segments. `background_jobs` prints +an icon if there are background jobs. `root_indicator` prints an icon if the user +is root. The `status` segment focuses now on the status only. + ### New segment `custom_command` added A new segment that allows users to define a custom command was added. diff --git a/README.md b/README.md index 6a690bfd..08728697 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ configuration is the default: The segments that are currently available are: * [aws](#aws) - The current AWS profile, if active. +* **background_jobs** - INdicator for background jobs. * [battery](#battery) - Current battery status. * [context](#context) - Your username and host. * [custom_command](#custom_command) - A custom command to display the output of. @@ -85,9 +86,10 @@ The segments that are currently available are: * **php_version** - Show the current PHP version. * [ram](#ram) - Show free RAM and used Swap. * [rbenv](#rbenv) - Ruby environment information (if one is active). +* **root_indicator** - An indicator if the user is root. * [rspec_stats](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. * **rust_version** - Display the current rust version. -* [status](#status) - The return code of the previous command, and status of background jobs. +* [status](#status) - The return code of the previous command. * [symphony2_tests](#symphony2_tests) - Show a ratio of test classes vs code classes for Symfony2. * **symphony2_version** - Show the current Symfony2 version, if you are in a Symfony2-Project dir. * [time](#time) - System time. @@ -222,10 +224,9 @@ See [Unit Test Ratios](#unit-test-ratios), below. ##### status -This segment shows the return code of the last command, and the presence of any -background jobs. By default, this segment will always print, but you can -customize it to only print if there is an error or a forked job by setting the -following variable in your `~/.zshrc`. +This segment shows the return code of the last command. By default, this +segment will always print, but you can customize it to only print if there +is an error by setting the following variable in your `~/.zshrc`. POWERLEVEL9K_STATUS_VERBOSE=false diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3d2d5d2c..d9f6af9b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -238,6 +238,13 @@ prompt_custom() { "$1_prompt_segment" "${0}_${2:u}" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" } +# print an icon, if there are background jobs +prompt_background_jobs() { + if [[ $(jobs -l | wc -l) -gt 0 ]]; then + "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "cyan" "$(print_icon 'BACKGROUND_JOBS_ICON')" + fi +} + prompt_battery() { # The battery can have different states. # Default is "unknown" @@ -537,6 +544,13 @@ prompt_rbenv() { fi } +# print an icon if user is root. +prompt_root_indicator() { + if [[ "$UID" -eq 0 ]]; then + "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "yellow" "$(print_icon 'ROOT_ICON')" + fi +} + # print Rust version number prompt_rust_version() { local rust_version @@ -572,26 +586,17 @@ prompt_rvm() { # Status: (return code, root status, background jobs) set_default POWERLEVEL9K_STATUS_VERBOSE true prompt_status() { - local symbols bg - symbols=() - if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then if [[ "$RETVAL" -ne 0 ]]; then - symbols+="%F{226}$RETVAL $(print_icon 'CARRIAGE_RETURN_ICON')%f" - bg="red" + "$1_prompt_segment" "$0_ERROR" "red" "226" "$RETVAL $(print_icon 'CARRIAGE_RETURN_ICON')" else - symbols+="%F{046}$(print_icon 'OK_ICON')%f" - bg="black" + "$1_prompt_segment" "$0_OK" "$DEFAULT_COLOR" "046" "$(print_icon 'OK_ICON')" fi else - [[ "$RETVAL" -ne 0 ]] && symbols+="%{%F{red}%}$(print_icon 'FAIL_ICON')%f" - bg="$DEFAULT_COLOR" + if [[ "$RETVAL" -ne 0 ]]; then + "$1_prompt_segment" "$0_ERROR" "$DEFAULT_COLOR" "red" "$(print_icon 'FAIL_ICON')" + fi fi - - [[ "$UID" -eq 0 ]] && symbols+="%{%F{yellow}%} $(print_icon 'ROOT_ICON')%f" - [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}$(print_icon 'BACKGROUND_JOBS_ICON')%f" - - [[ -n "$symbols" ]] && "$1_prompt_segment" "$0" "$bg" "white" "$symbols" } # Symfony2-PHPUnit test ratio @@ -753,7 +758,7 @@ build_left_prompt() { # Right prompt build_right_prompt() { - defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) + defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status background_jobs root_indicator history time) for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do # Check if it is a custom command, otherwise interpet it as -- cgit v1.2.3 From 21f80e4da711dd4d1e81e1f58887519cfc7a038c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:32:45 +0100 Subject: Removed trailing whitespaces. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3d2d5d2c..9842bfa9 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -782,7 +782,7 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down else - RPROMPT_PREFIX='' + RPROMPT_PREFIX='' RPROMPT_SUFFIX='' fi else @@ -838,7 +838,7 @@ powerlevel9k_init() { print_deprecation_warning deprecated_segments setopt prompt_subst - + setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS setopt PROMPT_CR PROMPT_PERCENT PROMPT_SUBST MULTIBYTE -- cgit v1.2.3 From 036433dd538f55d2950d40b0ca3068016877314f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:41:02 +0100 Subject: Segments now can have "visual identifiers" which are basically just special icons. --- powerlevel9k.zsh-theme | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 9842bfa9..4705a89b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -123,7 +123,8 @@ CURRENT_BG='NONE' # * $2: Background color # * $3: Foreground color # * $4: The segment content -# The latter three can be omitted, +# * $5: An identifying icon (must be a key of the icons array) +# The latter four can be omitted, set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " " left_prompt_segment() { # Overwrite given background-color by user defined variable for this segment. @@ -154,8 +155,16 @@ left_prompt_segment() { # First segment echo -n "%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi + + local visual_identifier + if [[ -n $5 ]]; then + visual_identifier="$(print_icon $5)" + # Add an whitespace if we print more than just the visual identifier + [[ -n $4 ]] && visual_identifier="$visual_identifier " + fi + + echo -n "$visual_identifier$4$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" CURRENT_BG=$2 - [[ -n $4 ]] && echo -n "$4$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" } # End the left prompt, closes the final segment. @@ -178,6 +187,7 @@ CURRENT_RIGHT_BG='NONE' # * $2: Background color # * $3: Foreground color # * $4: The segment content +# * $5: An identifying icon (must be a key of the icons array) # No ending for the right prompt segment is needed (unlike the left prompt, above). set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " " right_prompt_segment() { @@ -206,8 +216,16 @@ right_prompt_segment() { else echo -n "%F{$2}$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS" fi - [[ -n $4 ]] && echo -n "$4$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS%f" + local visual_identifier + if [[ -n $5 ]]; then + # Swap the spaces around an icon if the icon is displayed on the right side. + visual_identifier=$(print_icon $5 | sed -E "s/( *)([^ ]*)( *)/\3\2\1/") + # Add an whitespace if we print more than just the visual identifier + [[ -n $4 ]] && visual_identifier=" $visual_identifier" + fi + + echo -n "$4$visual_identifier$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS%f" CURRENT_RIGHT_BG=$2 } -- cgit v1.2.3 From 0c528461fb1e5f38e1d4ee32c696a6955f5bfaa0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:55:24 +0100 Subject: Allow users to overwrite the color for the visual identifier only. --- powerlevel9k.zsh-theme | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4705a89b..7c7b2d2e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -159,6 +159,10 @@ left_prompt_segment() { local visual_identifier if [[ -n $5 ]]; then visual_identifier="$(print_icon $5)" + # 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 $fg + visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" # Add an whitespace if we print more than just the visual identifier [[ -n $4 ]] && visual_identifier="$visual_identifier " fi @@ -221,6 +225,10 @@ right_prompt_segment() { if [[ -n $5 ]]; then # Swap the spaces around an icon if the icon is displayed on the right side. visual_identifier=$(print_icon $5 | sed -E "s/( *)([^ ]*)( *)/\3\2\1/") + # 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 $fg + visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" # Add an whitespace if we print more than just the visual identifier [[ -n $4 ]] && visual_identifier=" $visual_identifier" fi -- cgit v1.2.3 From 1194826ef4eb876edbf3cec427eca37eda976a02 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:55:55 +0100 Subject: Used the new "visual identifier" concept for the battery segment. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7c7b2d2e..7a06002a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -346,15 +346,15 @@ prompt_battery() { fi # prepare string - local message="$(print_icon 'BATTERY_ICON')" + local message # Default behavior: Be verbose! set_default POWERLEVEL9K_BATTERY_VERBOSE true if [[ "$POWERLEVEL9K_BATTERY_VERBOSE" == true ]]; then - message="$message $bat_percent%%$remain" + message="$bat_percent%%$remain" fi # display prompt_segment - [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" + [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON' } # Context: user@hostname (who am I and where am I) -- cgit v1.2.3 From e505c0698e12a8769ced7e0f0bc42c3b7df3210e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:57:24 +0100 Subject: Added the "visual identifier" concept to the `aws` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7a06002a..64427545 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -251,7 +251,7 @@ prompt_aws() { local aws_profile="$AWS_DEFAULT_PROFILE" if [[ -n "$aws_profile" ]]; then - "$1_prompt_segment" "$0" red white "$(print_icon 'AWS_ICON') $aws_profile" + "$1_prompt_segment" "$0" red white "$aws_profile" 'AWS_ICON' fi } -- cgit v1.2.3 From d5d5acb490e37d62db30a16fb434dce56c732c05 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:58:36 +0100 Subject: Added the "visual identifier" concept to the `dir` segment. --- powerlevel9k.zsh-theme | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 64427545..b0abe8c1 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -391,12 +391,10 @@ prompt_dir() { local current_icon='' if [[ $(print -P "%~") == '~'* ]]; then - current_icon=$(print_icon 'HOME_ICON') + "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_ICON' else - current_icon=$(print_icon 'FOLDER_ICON') + "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$current_path" 'FOLDER_ICON' fi - - "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$current_icon$current_path" } # GO-prompt -- cgit v1.2.3 From bb5cca9af7d678d5a70ea529e75ba740c0caa6b4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:59:39 +0100 Subject: Added the "visual identifier" concept to the `ip` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b0abe8c1..1258b0ec 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -449,7 +449,7 @@ prompt_ip() { fi fi - "$1_prompt_segment" "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip" + "$1_prompt_segment" "$0" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON' } prompt_load() { -- cgit v1.2.3 From 35b1cb5b8d7b4132d9b1da50600265b040e94308 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:01:34 +0100 Subject: Added the "visual identifier" concept to the `load` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 1258b0ec..d5e3b1e1 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -473,7 +473,7 @@ prompt_load() { FUNCTION_SUFFIX="_NORMAL" fi - "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min" + "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' } # Node version -- cgit v1.2.3 From fd0fcba5e9b14f27879c209ec056d23adc189026 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:02:55 +0100 Subject: Added the "visual identifier" concept to the `node_version` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d5e3b1e1..362cacb3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -481,7 +481,7 @@ prompt_node_version() { local node_version=$(node -v 2>/dev/null) [[ -z "${node_version}" ]] && return - "$1_prompt_segment" "$0" "green" "white" "${node_version:1} $(print_icon 'NODE_ICON')" + "$1_prompt_segment" "$0" "green" "white" "${node_version:1}" 'NODE_ICON' } # print a little OS icon -- cgit v1.2.3 From d514b077d09359860b9450da696e3377e5643740 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:05:42 +0100 Subject: Added the "visual identifier" concept to the `rvm` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 362cacb3..e3e135bb 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -589,7 +589,7 @@ prompt_rvm() { local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') if [[ -n "$version$gemset" ]]; then - "$1_prompt_segment" "$0" "240" "$DEFAULT_COLOR" "$version$gemset $(print_icon 'RUBY_ICON') " + "$1_prompt_segment" "$0" "240" "$DEFAULT_COLOR" "$version$gemset" 'RUBY_ICON' fi } -- cgit v1.2.3 From c5726bc548a4a8b82db480ec55ee04ceae31624e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:07:38 +0100 Subject: Added the "visual identifier" concept to the `todo` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e3e135bb..9b74cd87 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -668,7 +668,7 @@ prompt_todo() { if $(hash todo.sh 2>&-); then count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }') if [[ "$count" = <-> ]]; then - "$1_prompt_segment" "$0" "244" "$DEFAULT_COLOR" "$(print_icon 'TODO_ICON') $count" + "$1_prompt_segment" "$0" "244" "$DEFAULT_COLOR" "$count" 'TODO_ICON' fi fi } -- cgit v1.2.3 From 6f7d6f7259d33233288dca3b5657c89550023389 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:21:15 +0100 Subject: For left aligned segments start the foreground color after the visual identifier has been printed. --- powerlevel9k.zsh-theme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 9b74cd87..4657d3e5 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -142,7 +142,7 @@ left_prompt_segment() { [[ -n $3 ]] && fg="%F{$3}" || fg="%f" if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$2" "$CURRENT_BG"; then # Middle segment - echo -n "%{$bg%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "%{$bg%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" elif isSameColor "$CURRENT_BG" "$2"; then # Middle segment with same color as previous segment # We take the current foreground color as color for our @@ -150,10 +150,10 @@ left_prompt_segment() { # enough contrast. local complement [[ -n $3 ]] && complement=$3 || complement=$DEFAULT_COLOR - echo -n "%{$bg%F{$complement}%}$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "%{$bg%F{$complement}%}$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" else # First segment - echo -n "%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "%{$bg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi local visual_identifier @@ -167,7 +167,7 @@ left_prompt_segment() { [[ -n $4 ]] && visual_identifier="$visual_identifier " fi - echo -n "$visual_identifier$4$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "$visual_identifier%{$fg%}$4$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" CURRENT_BG=$2 } -- cgit v1.2.3 From 78d22ba309171889e79fa486b9f7aa882b4d8001 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:31:55 +0100 Subject: Interesting: We don't need to swap the whitespaces if the visual identifier should be rendered on the right side, because the terminal gets printed from left to right and the double width characters need their "print me right"-whitespaces on the right side anyways. --- powerlevel9k.zsh-theme | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4657d3e5..25a9f0e0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -223,8 +223,7 @@ right_prompt_segment() { local visual_identifier if [[ -n $5 ]]; then - # Swap the spaces around an icon if the icon is displayed on the right side. - visual_identifier=$(print_icon $5 | sed -E "s/( *)([^ ]*)( *)/\3\2\1/") + visual_identifier="$(print_icon $5)" # 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 $fg -- cgit v1.2.3 From 1d0f47fb976369ce56c294e278667aad5aa20335 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:20:11 +0100 Subject: Bugfix: the default should be a pure color, not a full ZSH color modifier. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 25a9f0e0..a90d18e7 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -161,7 +161,7 @@ left_prompt_segment() { visual_identifier="$(print_icon $5)" # 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 $fg + set_default $visual_identifier_color_variable $3 visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" # Add an whitespace if we print more than just the visual identifier [[ -n $4 ]] && visual_identifier="$visual_identifier " @@ -226,7 +226,7 @@ right_prompt_segment() { visual_identifier="$(print_icon $5)" # 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 $fg + set_default $visual_identifier_color_variable $3 visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" # Add an whitespace if we print more than just the visual identifier [[ -n $4 ]] && visual_identifier=" $visual_identifier" -- cgit v1.2.3 From 4fc59fd57c508ff47871a5efadb4b987b1864702 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:36:02 +0100 Subject: Added the "visual identifier" concept to the `node_version` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index a90d18e7..20cba35b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -550,7 +550,7 @@ prompt_nvm() { [[ -z "${node_version}" ]] && return [[ "$node_version" =~ "$nvm_default" ]] && return - $1_prompt_segment "$0" "green" "011" "${node_version:1} $(print_icon 'NODE_ICON')" + $1_prompt_segment "$0" "green" "011" "${node_version:1}" 'NODE_ICON' } # rbenv information -- cgit v1.2.3 From 409303f45db59aa31cf3df2427d2f6b43d5349e9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:36:57 +0100 Subject: Added the "visual identifier" concept to the `rbenv` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 20cba35b..b2f36df6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -556,7 +556,7 @@ prompt_nvm() { # rbenv information prompt_rbenv() { if [[ -n "$RBENV_VERSION" ]]; then - "$1_prompt_segment" "$0" "red" "$DEFAULT_COLOR" "$RBENV_VERSION" + "$1_prompt_segment" "$0" "red" "$DEFAULT_COLOR" "$RBENV_VERSION" 'RUBY_ICON' fi } -- cgit v1.2.3 From 056d4ff29ac1dbacc6be0d3b99160a493e47ab1c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:43:42 +0100 Subject: Only check for a user defined variable if we really have an visual identifier. --- powerlevel9k.zsh-theme | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b2f36df6..04e29a2d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -159,12 +159,14 @@ left_prompt_segment() { local visual_identifier if [[ -n $5 ]]; then visual_identifier="$(print_icon $5)" - # 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 $3 - visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" - # Add an whitespace if we print more than just the visual identifier - [[ -n $4 ]] && visual_identifier="$visual_identifier " + if [[ -n "$visual_identifier" ]]; then + # 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 $3 + visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" + # Add an whitespace if we print more than just the visual identifier + [[ -n $4 ]] && visual_identifier="$visual_identifier " + fi fi echo -n "$visual_identifier%{$fg%}$4$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" @@ -224,12 +226,14 @@ right_prompt_segment() { local visual_identifier if [[ -n $5 ]]; then visual_identifier="$(print_icon $5)" - # 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 $3 - visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" - # Add an whitespace if we print more than just the visual identifier - [[ -n $4 ]] && visual_identifier=" $visual_identifier" + if [[ -n "$visual_identifier" ]]; then + # 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 $3 + visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" + # Add an whitespace if we print more than just the visual identifier + [[ -n $4 ]] && visual_identifier=" $visual_identifier" + fi fi echo -n "$4$visual_identifier$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS%f" -- cgit v1.2.3 From cd5b4d0debac05a74131f06efa918172586865ec Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 03:21:24 +0100 Subject: Added the "state" concept to the `dir` segment. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 04e29a2d..df11bb5d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -394,9 +394,9 @@ prompt_dir() { local current_icon='' if [[ $(print -P "%~") == '~'* ]]; then - "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_ICON' + "$1_prompt_segment" "$0_HOME" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_ICON' else - "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$current_path" 'FOLDER_ICON' + "$1_prompt_segment" "$0_DEFAULT" "blue" "$DEFAULT_COLOR" "$current_path" 'FOLDER_ICON' fi } -- cgit v1.2.3 From ad2e4f0bcc6215afd1b598fcf75e4ab44eb4baca Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 16 Dec 2015 19:26:27 +0100 Subject: Added ability to join segments together. You always join a segment with the previous one. Just add "_joined" to the segment name in your `POWERLEVEL9K_LEFT_PROMPT_ELEMENTS`-array. Developers: Be aware that the order of parameters given to left/right_prompt_segment has changed! --- CHANGELOG.md | 6 ++ powerlevel9k.zsh-theme | 194 +++++++++++++++++++++++++++++-------------------- 2 files changed, 120 insertions(+), 80 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/CHANGELOG.md b/CHANGELOG.md index 66520d21..846cd221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## v0.3.0 (next) +### Added ability for "joined" segments + +You can now merge segments together by suffixing the segment name with "_joined". +For Developers: Be aware that the order of parameters in left/right_prompt_segment +has changed. Now a boolean parameter must be set as second parameter (true if joined). + ### `status` changes The `status` segment was split up into three segments. `background_jobs` prints diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d9f6af9b..01f565d9 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -120,42 +120,53 @@ CURRENT_BG='NONE' # Takes four arguments: # * $1: Name of the function that was orginally invoked (mandatory). # Necessary, to make the dynamic color-overwrite mechanism work. -# * $2: Background color -# * $3: Foreground color -# * $4: The segment content +# * $2: A flag if the segment should be joined with the previous one. +# * $3: Background color +# * $4: Foreground color +# * $5: The segment content # The latter three can be omitted, set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " " left_prompt_segment() { # Overwrite given background-color by user defined variable for this segment. local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_BACKGROUND local BG_COLOR_MODIFIER=${(P)BACKGROUND_USER_VARIABLE} - [[ -n $BG_COLOR_MODIFIER ]] && 2="$BG_COLOR_MODIFIER" + [[ -n $BG_COLOR_MODIFIER ]] && 3="$BG_COLOR_MODIFIER" # Overwrite given foreground-color by user defined variable for this segment. local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_FOREGROUND local FG_COLOR_MODIFIER=${(P)FOREGROUND_USER_VARIABLE} - [[ -n $FG_COLOR_MODIFIER ]] && 3="$FG_COLOR_MODIFIER" + [[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER" local bg fg - [[ -n $2 ]] && bg="%K{$2}" || bg="%k" - [[ -n $3 ]] && fg="%F{$3}" || fg="%f" - if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$2" "$CURRENT_BG"; then - # Middle segment - echo -n "%{$bg%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" - elif isSameColor "$CURRENT_BG" "$2"; then + [[ -n "$3" ]] && bg="%K{$3}" || bg="%k" + [[ -n "$4" ]] && fg="%F{$4}" || fg="%f" + + local joined=$2 + if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$3" "$CURRENT_BG"; then + echo -n "%{$bg%F{$CURRENT_BG}%}" + if [[ $joined == false ]]; then + # Middle segment + echo -n "$(print_icon 'LEFT_SEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + fi + elif isSameColor "$CURRENT_BG" "$3"; then # Middle segment with same color as previous segment # We take the current foreground color as color for our # subsegment (or the default color). This should have # enough contrast. local complement - [[ -n $3 ]] && complement=$3 || complement=$DEFAULT_COLOR - echo -n "%{$bg%F{$complement}%}$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + [[ -n "$4" ]] && complement="$4" || complement=$DEFAULT_COLOR + echo -n "%{$bg%F{$complement}%}" + if [[ $joined == false ]]; then + echo -n "$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + fi else # First segment echo -n "%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi - CURRENT_BG=$2 - [[ -n $4 ]] && echo -n "$4$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + + [[ -n "$5" ]] && echo -n "${5}${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" + + CURRENT_BG=$3 } # End the left prompt, closes the final segment. @@ -175,40 +186,51 @@ CURRENT_RIGHT_BG='NONE' # Takes four arguments: # * $1: Name of the function that was orginally invoked (mandatory). # Necessary, to make the dynamic color-overwrite mechanism work. -# * $2: Background color -# * $3: Foreground color -# * $4: The segment content +# * $2: A flag if the segment should be joined with the previous one. +# * $3: Background color +# * $4: Foreground color +# * $5: The segment content # No ending for the right prompt segment is needed (unlike the left prompt, above). set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " " right_prompt_segment() { # Overwrite given background-color by user defined variable for this segment. local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_BACKGROUND local BG_COLOR_MODIFIER=${(P)BACKGROUND_USER_VARIABLE} - [[ -n $BG_COLOR_MODIFIER ]] && 2="$BG_COLOR_MODIFIER" + [[ -n $BG_COLOR_MODIFIER ]] && 3="$BG_COLOR_MODIFIER" # Overwrite given foreground-color by user defined variable for this segment. local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_FOREGROUND local FG_COLOR_MODIFIER=${(P)FOREGROUND_USER_VARIABLE} - [[ -n $FG_COLOR_MODIFIER ]] && 3="$FG_COLOR_MODIFIER" + [[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER" local bg fg - [[ -n $2 ]] && bg="%K{$2}" || bg="%k" - [[ -n $3 ]] && fg="%F{$3}" || fg="%f" - - if isSameColor "$CURRENT_RIGHT_BG" "$2"; then - # Middle segment with same color as previous segment - # We take the current foreground color as color for our - # subsegment (or the default color). This should have - # enough contrast. - local complement - [[ -n $3 ]] && complement=$3 || complement=$DEFAULT_COLOR - echo -n "%F{$complement}$(print_icon 'RIGHT_SUBSEGMENT_SEPARATOR')%f%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS" - else - echo -n "%F{$2}$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS" + [[ -n "$3" ]] && bg="%K{$3}" || bg="%k" + [[ -n "$4" ]] && fg="%F{$4}" || fg="%f" + + local joined=$2 + # If CURRENT_RIGHT_BG is "NONE", we are the first right segment. + if [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]]; then + if isSameColor "$CURRENT_RIGHT_BG" "$3"; then + # Middle segment with same color as previous segment + # We take the current foreground color as color for our + # subsegment (or the default color). This should have + # enough contrast. + local complement + [[ -n "$4" ]] && complement="$4" || complement=$DEFAULT_COLOR + echo -n "%F{$complement}$(print_icon 'RIGHT_SUBSEGMENT_SEPARATOR')%f" + else + echo -n "%F{$3}$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f" + fi fi - [[ -n $4 ]] && echo -n "$4$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS%f" + echo -n "%{$bg%}%{$fg%}" - CURRENT_RIGHT_BG=$2 + # Print whitespace only if segment is not joined + [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]] && echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}" + + # Print segment content + [[ -n "$5" ]] && echo -n "${5}${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}%f" + + CURRENT_RIGHT_BG=$3 } ################################################################ @@ -225,7 +247,7 @@ prompt_aws() { local aws_profile="$AWS_DEFAULT_PROFILE" if [[ -n "$aws_profile" ]]; then - "$1_prompt_segment" "$0" red white "$(print_icon 'AWS_ICON') $aws_profile" + "$1_prompt_segment" "$0" "$2" red white "$(print_icon 'AWS_ICON') $aws_profile" fi } @@ -233,15 +255,15 @@ prompt_aws() { # and display the output of. # prompt_custom() { - local command=POWERLEVEL9K_CUSTOM_$2:u + local command=POWERLEVEL9K_CUSTOM_$3:u - "$1_prompt_segment" "${0}_${2:u}" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" + "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" } # print an icon, if there are background jobs prompt_background_jobs() { if [[ $(jobs -l | wc -l) -gt 0 ]]; then - "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "cyan" "$(print_icon 'BACKGROUND_JOBS_ICON')" + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "cyan" "$(print_icon 'BACKGROUND_JOBS_ICON')" fi } @@ -335,7 +357,7 @@ prompt_battery() { fi # display prompt_segment - [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" + [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" } # Context: user@hostname (who am I and where am I) @@ -344,9 +366,9 @@ prompt_context() { if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then if [[ $(print -P "%#") == '#' ]]; then # Shell runs as root - "$1_prompt_segment" "$0_ROOT" "$DEFAULT_COLOR" "yellow" "$USER@%m" + "$1_prompt_segment" "$0_ROOT" "$2" "$DEFAULT_COLOR" "yellow" "$USER@%m" else - "$1_prompt_segment" "$0_DEFAULT" "$DEFAULT_COLOR" "011" "$USER@%m" + "$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@%m" fi fi } @@ -377,7 +399,7 @@ prompt_dir() { current_icon=$(print_icon 'FOLDER_ICON') fi - "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$current_icon$current_path" + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$current_icon$current_path" } # GO-prompt @@ -386,13 +408,13 @@ prompt_go_version() { go_version=$(go version 2>&1 | sed -E "s/.*(go[0-9.]*).*/\1/") if [[ -n "$go_version" ]]; then - "$1_prompt_segment" "$0" "green" "255" "$go_version" + "$1_prompt_segment" "$0" "$2" "green" "255" "$go_version" fi } # Command number (in local history) prompt_history() { - "$1_prompt_segment" "$0" "244" "$DEFAULT_COLOR" '%h' + "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h' } prompt_icons_test() { @@ -401,7 +423,7 @@ prompt_icons_test() { # the next color has enough contrast to read. local random_color=$((RANDOM % 8)) local next_color=$((random_color+1)) - "$1_prompt_segment" "$0" "$random_color" "$next_color" "$key: ${icons[$key]}" + "$1_prompt_segment" "$0" "$2" "$random_color" "$next_color" "$key: ${icons[$key]}" done } @@ -432,7 +454,7 @@ prompt_ip() { fi fi - "$1_prompt_segment" "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip" + "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip" } prompt_load() { @@ -456,7 +478,7 @@ prompt_load() { FUNCTION_SUFFIX="_NORMAL" fi - "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min" + "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$2" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min" } # Node version @@ -464,12 +486,12 @@ prompt_node_version() { local node_version=$(node -v 2>/dev/null) [[ -z "${node_version}" ]] && return - "$1_prompt_segment" "$0" "green" "white" "${node_version:1} $(print_icon 'NODE_ICON')" + "$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1} $(print_icon 'NODE_ICON')" } # print a little OS icon prompt_os_icon() { - "$1_prompt_segment" "$0" "black" "255" "$OS_ICON" + "$1_prompt_segment" "$0" "$2" "black" "255" "$OS_ICON" } # print PHP version number @@ -478,7 +500,7 @@ prompt_php_version() { php_version=$(php -v 2>&1 | grep -oe "^PHP\s*[0-9.]*") if [[ -n "$php_version" ]]; then - "$1_prompt_segment" "$0" "013" "255" "$php_version" + "$1_prompt_segment" "$0" "$2" "013" "255" "$php_version" fi } @@ -523,7 +545,7 @@ prompt_ram() { esac done - "$1_prompt_segment" "$0" "yellow" "$DEFAULT_COLOR" "${rendition% }" + "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "${rendition% }" } # Node version from NVM @@ -534,20 +556,20 @@ prompt_nvm() { [[ -z "${node_version}" ]] && return [[ "$node_version" =~ "$nvm_default" ]] && return - $1_prompt_segment "$0" "green" "011" "${node_version:1} $(print_icon 'NODE_ICON')" + $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1} $(print_icon 'NODE_ICON')" } # rbenv information prompt_rbenv() { if [[ -n "$RBENV_VERSION" ]]; then - "$1_prompt_segment" "$0" "red" "$DEFAULT_COLOR" "$RBENV_VERSION" + "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$RBENV_VERSION" fi } # print an icon if user is root. prompt_root_indicator() { if [[ "$UID" -eq 0 ]]; then - "$1_prompt_segment" "$0" "$DEFAULT_COLOR" "yellow" "$(print_icon 'ROOT_ICON')" + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$(print_icon 'ROOT_ICON')" fi } @@ -557,7 +579,7 @@ prompt_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" "208" "$DEFAULT_COLOR" "Rust $rust_version" + "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "Rust $rust_version" fi } # RSpec test ratio @@ -567,7 +589,7 @@ prompt_rspec_stats() { code_amount=$(ls -1 app/**/*.rb | wc -l) tests_amount=$(ls -1 spec/**/*.rb | wc -l) - build_test_stats "$1" "$0" "$code_amount" "$tests_amount" "RSpec $(print_icon 'TEST_ICON')" + build_test_stats "$1" "$0" "$2" "$code_amount" "$tests_amount" "RSpec $(print_icon 'TEST_ICON')" fi } @@ -579,7 +601,7 @@ prompt_rvm() { local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') if [[ -n "$version$gemset" ]]; then - "$1_prompt_segment" "$0" "240" "$DEFAULT_COLOR" "$version$gemset $(print_icon 'RUBY_ICON') " + "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version$gemset $(print_icon 'RUBY_ICON') " fi } @@ -588,13 +610,13 @@ set_default POWERLEVEL9K_STATUS_VERBOSE true prompt_status() { if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then if [[ "$RETVAL" -ne 0 ]]; then - "$1_prompt_segment" "$0_ERROR" "red" "226" "$RETVAL $(print_icon 'CARRIAGE_RETURN_ICON')" + "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL $(print_icon 'CARRIAGE_RETURN_ICON')" else - "$1_prompt_segment" "$0_OK" "$DEFAULT_COLOR" "046" "$(print_icon 'OK_ICON')" + "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "046" "$(print_icon 'OK_ICON')" fi else if [[ "$RETVAL" -ne 0 ]]; then - "$1_prompt_segment" "$0_ERROR" "$DEFAULT_COLOR" "red" "$(print_icon 'FAIL_ICON')" + "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "$(print_icon 'FAIL_ICON')" fi fi } @@ -606,7 +628,7 @@ prompt_symfony2_tests() { code_amount=$(ls -1 src/**/*.php | grep -vc Tests) tests_amount=$(ls -1 src/**/*.php | grep -c Tests) - build_test_stats "$1" "$0" "$code_amount" "$tests_amount" "SF2 $(print_icon 'TEST_ICON')" + build_test_stats "$1" "$0" "$2" "$code_amount" "$tests_amount" "SF2 $(print_icon 'TEST_ICON')" fi } @@ -615,23 +637,23 @@ prompt_symfony2_version() { if [[ -f app/bootstrap.php.cache ]]; then local symfony2_version symfony2_version=$(grep " VERSION " app/bootstrap.php.cache | sed -e 's/[^.0-9]*//g') - "$1_prompt_segment" "$0" "240" "$DEFAULT_COLOR" "$(print_icon 'SYMFONY_ICON') $symfony2_version" + "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$(print_icon 'SYMFONY_ICON') $symfony2_version" fi } # Show a ratio of tests vs code build_test_stats() { - local code_amount="$3" - local tests_amount="$4"+0.00001 - local headline="$5" + local code_amount="$4" + local tests_amount="$5"+0.00001 + local headline="$6" # Set float precision to 2 digits: typeset -F 2 ratio local ratio=$(( (tests_amount/code_amount) * 100 )) - (( ratio >= 75 )) && "$1_prompt_segment" "${2}_GOOD" "cyan" "$DEFAULT_COLOR" "$headline: $ratio%%" - (( ratio >= 50 && ratio < 75 )) && "$1_prompt_segment" "$2_AVG" "yellow" "$DEFAULT_COLOR" "$headline: $ratio%%" - (( ratio < 50 )) && "$1_prompt_segment" "$2_BAD" "red" "$DEFAULT_COLOR" "$headline: $ratio%%" + (( ratio >= 75 )) && "$1_prompt_segment" "${2}_GOOD" "$3" "cyan" "$DEFAULT_COLOR" "$headline: $ratio%%" + (( ratio >= 50 && ratio < 75 )) && "$1_prompt_segment" "${2}_AVG" "$3" "yellow" "$DEFAULT_COLOR" "$headline: $ratio%%" + (( ratio < 50 )) && "$1_prompt_segment" "${2}_BAD" "red" "$3" "$DEFAULT_COLOR" "$headline: $ratio%%" } # System time @@ -641,7 +663,7 @@ prompt_time() { time_format="$POWERLEVEL9K_TIME_FORMAT" fi - "$1_prompt_segment" "$0" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$time_format" + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$time_format" } # todo.sh: shows the number of tasks in your todo.sh file @@ -649,7 +671,7 @@ prompt_todo() { if $(hash todo.sh 2>&-); then count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }') if [[ "$count" = <-> ]]; then - "$1_prompt_segment" "$0" "244" "$DEFAULT_COLOR" "$(print_icon 'TODO_ICON') $count" + "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" "$(print_icon 'TODO_ICON') $count" fi fi } @@ -702,9 +724,9 @@ prompt_vcs() { if [[ -n "$vcs_prompt" ]]; then if [[ "$VCS_WORKDIR_DIRTY" == true ]]; then - "$1_prompt_segment" "$0_MODIFIED" "yellow" "$DEFAULT_COLOR" + "$1_prompt_segment" "$0_MODIFIED" "$2" "yellow" "$DEFAULT_COLOR" else - "$1_prompt_segment" "$0" "green" "$DEFAULT_COLOR" + "$1_prompt_segment" "$0" "$2" "green" "$DEFAULT_COLOR" fi echo -n "$vcs_prompt " @@ -717,10 +739,10 @@ set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL" prompt_vi_mode() { case ${KEYMAP} in main|viins) - "$1_prompt_segment" "$0_INSERT" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING" + "$1_prompt_segment" "$0_INSERT" "$2" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING" ;; vicmd) - "$1_prompt_segment" "$0_NORMAL" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING" + "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING" ;; esac } @@ -731,7 +753,7 @@ prompt_vi_mode() { prompt_virtualenv() { local virtualenv_path="$VIRTUAL_ENV" if [[ -n "$virtualenv_path" && "$VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then - "$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "($(basename "$virtualenv_path"))" + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "($(basename "$virtualenv_path"))" fi } @@ -744,12 +766,18 @@ build_left_prompt() { defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do + # Check if the segment should be joined with the next one + local joined=false + if [[ ${element[-7,-1]} == '_joined' ]]; then + element="${element[0,-8]}" + joined=true + fi # Check if it is a custom command, otherwise interpet it as # a prompt. if [[ $element[0,7] =~ "custom_" ]]; then - "prompt_custom" "left" $element[8,-1] + "prompt_custom" "left" "$joined" $element[8,-1] else - "prompt_$element" "left" + "prompt_$element" "left" "$joined" fi done @@ -761,12 +789,18 @@ build_right_prompt() { defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status background_jobs root_indicator history time) for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do + # Check if the segment should be joined with the next one + local joined=false + if [[ ${element[-7,-1]} == '_joined' ]]; then + element="${element[0,-8]}" + joined=true + fi # Check if it is a custom command, otherwise interpet it as # a prompt. if [[ $element[0,7] =~ "custom_" ]]; then - "prompt_custom" "right" $element[8,-1] + "prompt_custom" "right" "$joined" $element[8,-1] else - "prompt_$element" "right" + "prompt_$element" "right" "$joined" fi done } -- cgit v1.2.3 From 0cb1c0ffdaf4fe84fa469d827aa4bae67dd89c08 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 10:48:11 +0100 Subject: Changed the order of default segments. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 01f565d9..98d54d96 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -766,7 +766,7 @@ build_left_prompt() { defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do - # Check if the segment should be joined with the next one + # Check if the segment should be joined with the previous one local joined=false if [[ ${element[-7,-1]} == '_joined' ]]; then element="${element[0,-8]}" @@ -786,10 +786,10 @@ build_left_prompt() { # Right prompt build_right_prompt() { - defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status background_jobs root_indicator history time) + defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time) for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do - # Check if the segment should be joined with the next one + # Check if the segment should be joined with the previous one local joined=false if [[ ${element[-7,-1]} == '_joined' ]]; then element="${element[0,-8]}" -- cgit v1.2.3 From 7ed0abebd690e4cf111582523f0279bbad6102bb Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 10:51:52 +0100 Subject: Little VCS segment cleanup. --- powerlevel9k.zsh-theme | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 98d54d96..cef789c2 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -724,12 +724,10 @@ prompt_vcs() { if [[ -n "$vcs_prompt" ]]; then if [[ "$VCS_WORKDIR_DIRTY" == true ]]; then - "$1_prompt_segment" "$0_MODIFIED" "$2" "yellow" "$DEFAULT_COLOR" + "$1_prompt_segment" "$0_MODIFIED" "$2" "yellow" "$DEFAULT_COLOR" "$vcs_prompt" else - "$1_prompt_segment" "$0" "$2" "green" "$DEFAULT_COLOR" + "$1_prompt_segment" "$0" "$2" "green" "$DEFAULT_COLOR" "$vcs_prompt" fi - - echo -n "$vcs_prompt " fi } -- cgit v1.2.3 From b738ba900c5cc4cf5fd116e775062172c72466df Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 18:17:06 +0100 Subject: Added the "visual identifiers" concept to the `ram` segment. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index df11bb5d..b3927158 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -520,7 +520,7 @@ prompt_ram() { base=K fi - rendition+="$(print_icon 'RAM_ICON') $(printSizeHumanReadable "$ramfree" $base) " + rendition+="$(printSizeHumanReadable "$ramfree" $base) " ;; swap_used) if [[ "$OS" == "OSX" ]]; then @@ -543,7 +543,7 @@ prompt_ram() { esac done - "$1_prompt_segment" "$0" "yellow" "$DEFAULT_COLOR" "${rendition% }" + "$1_prompt_segment" "$0" "yellow" "$DEFAULT_COLOR" "${rendition% }" 'RAM_ICON' } # Node version from NVM -- cgit v1.2.3 From 045f451e4e8bffc4a684bd5abf156193988e1220 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 18:22:34 +0100 Subject: Added the "visual identifier" concept to the `symfony2_tests` and `rspec_stats` segments. --- powerlevel9k.zsh-theme | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b3927158..e3cb647a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -580,7 +580,7 @@ prompt_rspec_stats() { code_amount=$(ls -1 app/**/*.rb | wc -l) tests_amount=$(ls -1 spec/**/*.rb | wc -l) - build_test_stats "$1" "$0" "$code_amount" "$tests_amount" "RSpec $(print_icon 'TEST_ICON')" + build_test_stats "$1" "$0" "$code_amount" "$tests_amount" "RSpec" 'TEST_ICON' fi } @@ -628,7 +628,7 @@ prompt_symfony2_tests() { code_amount=$(ls -1 src/**/*.php | grep -vc Tests) tests_amount=$(ls -1 src/**/*.php | grep -c Tests) - build_test_stats "$1" "$0" "$code_amount" "$tests_amount" "SF2 $(print_icon 'TEST_ICON')" + build_test_stats "$1" "$0" "$code_amount" "$tests_amount" "SF2" 'TEST_ICON' fi } @@ -651,9 +651,9 @@ build_test_stats() { typeset -F 2 ratio local ratio=$(( (tests_amount/code_amount) * 100 )) - (( ratio >= 75 )) && "$1_prompt_segment" "${2}_GOOD" "cyan" "$DEFAULT_COLOR" "$headline: $ratio%%" - (( ratio >= 50 && ratio < 75 )) && "$1_prompt_segment" "$2_AVG" "yellow" "$DEFAULT_COLOR" "$headline: $ratio%%" - (( ratio < 50 )) && "$1_prompt_segment" "$2_BAD" "red" "$DEFAULT_COLOR" "$headline: $ratio%%" + (( ratio >= 75 )) && "$1_prompt_segment" "${2}_GOOD" "cyan" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" + (( ratio >= 50 && ratio < 75 )) && "$1_prompt_segment" "$2_AVG" "yellow" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" + (( ratio < 50 )) && "$1_prompt_segment" "$2_BAD" "red" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" } # System time -- cgit v1.2.3 From 5cfd800585516ce2251cd4f4cf8f2e1dbadddc70 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 18:24:35 +0100 Subject: Added the "visual identifier" concept to the `symfony2_version` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e3cb647a..bf35967a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -637,7 +637,7 @@ prompt_symfony2_version() { if [[ -f app/bootstrap.php.cache ]]; then local symfony2_version symfony2_version=$(grep " VERSION " app/bootstrap.php.cache | sed -e 's/[^.0-9]*//g') - "$1_prompt_segment" "$0" "240" "$DEFAULT_COLOR" "$(print_icon 'SYMFONY_ICON') $symfony2_version" + "$1_prompt_segment" "$0" "240" "$DEFAULT_COLOR" "$symfony2_version" 'SYMFONY_ICON' fi } -- cgit v1.2.3 From ac4502ca1fafab54c07d22e4841d8c6c7aeffc95 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 18 Dec 2015 00:47:37 +0100 Subject: Added the "visual identifier" concept to the `vcs` segment. --- functions/icons.zsh | 8 ++++---- functions/vcs.zsh | 6 ++++++ powerlevel9k.zsh-theme | 11 +++++------ 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/icons.zsh b/functions/icons.zsh index 4ba4811e..b8e02efd 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -64,8 +64,8 @@ case $POWERLEVEL9K_MODE in VCS_COMMIT_ICON $'\UE821 ' #  VCS_BRANCH_ICON $'\UE220' #  VCS_REMOTE_BRANCH_ICON ' '$'\UE804 ' #  - VCS_GIT_ICON $'\UE20E ' #  - VCS_HG_ICON $'\UE1C3 ' #  + VCS_GIT_ICON $'\UE20E ' #  + VCS_HG_ICON $'\UE1C3 ' #  ) ;; 'awesome-fontconfig') @@ -111,8 +111,8 @@ case $POWERLEVEL9K_MODE in VCS_COMMIT_ICON $'\UF221 ' #  VCS_BRANCH_ICON $'\UF126' #  VCS_REMOTE_BRANCH_ICON ' '$'\UF204 ' #  - VCS_GIT_ICON $'\UF113 ' #  - VCS_HG_ICON $'\UF0C3 ' #  + VCS_GIT_ICON $'\UF113 ' #  + VCS_HG_ICON $'\UF0C3 ' #  ) ;; *) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 39d0fdae..49dccc18 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -78,6 +78,12 @@ function +vi-hg-bookmarks() { } function +vi-vcs-detect-changes() { + if [[ "${hook_com[vcs]}" == "git" ]]; then + vcs_visual_identifier='VCS_GIT_ICON' + elif [[ "${hook_com[vcs]}" == "hg" ]]; then + vcs_visual_identifier='VCS_HG_ICON' + fi + if [[ -n "${hook_com[staged]}" ]] || [[ -n "${hook_com[unstaged]}" ]]; then VCS_WORKDIR_DIRTY=true else diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index bf35967a..5e089521 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -696,8 +696,7 @@ prompt_vcs() { zstyle ':vcs_info:*' check-for-changes true VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%F{$POWERLEVEL9K_VCS_FOREGROUND}%b%c%u%m%f" - zstyle ':vcs_info:git*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_GIT_ICON')%f$VCS_DEFAULT_FORMAT" - zstyle ':vcs_info:hg*:*' formats "%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_HG_ICON')%f$VCS_DEFAULT_FORMAT" + zstyle ':vcs_info:*' formats "$VCS_DEFAULT_FORMAT" zstyle ':vcs_info:*' actionformats "%b %F{red}| %a%f" @@ -724,12 +723,12 @@ prompt_vcs() { if [[ -n "$vcs_prompt" ]]; then if [[ "$VCS_WORKDIR_DIRTY" == true ]]; then - "$1_prompt_segment" "$0_MODIFIED" "yellow" "$DEFAULT_COLOR" + # $vcs_visual_identifier gets set in +vi-vcs-detect-changes in functions/vcs.zsh, + # as we have there access to vcs_info internal hooks. + "$1_prompt_segment" "$0_MODIFIED" "yellow" "$DEFAULT_COLOR" "$vcs_prompt" "$vcs_visual_identifier" else - "$1_prompt_segment" "$0" "green" "$DEFAULT_COLOR" + "$1_prompt_segment" "$0" "green" "$DEFAULT_COLOR" "$vcs_prompt" "$vcs_visual_identifier" fi - - echo -n "$vcs_prompt " fi } -- cgit v1.2.3 From e9ef0429e4dedd7e6f399bfdeedec764d2431a77 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 29 Dec 2015 13:46:07 +0100 Subject: More consistent visual identifiers. Now even segments that just have an icon as content print these icons as visual identifiers. Some of these segments have a verbose mode. If this verbose mode is false, some print just the icon (like the battery segment), which didn't work correctly before this change. --- powerlevel9k.zsh-theme | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 19c5ea98..dfda23ae 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -178,7 +178,11 @@ left_prompt_segment() { fi fi - [[ -n "$5" ]] && echo -n "${visual_identifier}%{$fg%}${5}${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" + # Print the visual identifier + echo -n "${visual_identifier}" + # Print the content of the segment, if there is any + [[ -n "$5" ]] && echo -n "%{$fg%}${5}" + echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" CURRENT_BG=$3 } @@ -256,8 +260,10 @@ right_prompt_segment() { # Print whitespace only if segment is not joined or first right segment [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]] && echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}" - # Print segment content - [[ -n "$5" ]] && echo -n "${5}${visual_identifier}${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}%f" + # 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" CURRENT_RIGHT_BG=$3 } @@ -292,7 +298,7 @@ prompt_custom() { # print an icon, if there are background jobs prompt_background_jobs() { if [[ $(jobs -l | wc -l) -gt 0 ]]; then - "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "cyan" "$(print_icon 'BACKGROUND_JOBS_ICON')" + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "cyan" "" 'BACKGROUND_JOBS_ICON' fi } @@ -596,7 +602,7 @@ prompt_rbenv() { # print an icon if user is root. prompt_root_indicator() { if [[ "$UID" -eq 0 ]]; then - "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$(print_icon 'ROOT_ICON')" + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'ROOT_ICON' fi } @@ -637,13 +643,13 @@ set_default POWERLEVEL9K_STATUS_VERBOSE true prompt_status() { if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then if [[ "$RETVAL" -ne 0 ]]; then - "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL $(print_icon 'CARRIAGE_RETURN_ICON')" + "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL" 'CARRIAGE_RETURN_ICON' else - "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "046" "$(print_icon 'OK_ICON')" + "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "046" "" 'OK_ICON' fi else if [[ "$RETVAL" -ne 0 ]]; then - "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "$(print_icon 'FAIL_ICON')" + "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON' fi fi } -- cgit v1.2.3 From 2fdbd6158c78a0b1786d6a030629fe3a930fc46d Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Wed, 30 Dec 2015 15:49:23 +0100 Subject: added fishe-like shortening strategy --- powerlevel9k.zsh-theme | 3 +++ 1 file changed, 3 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 19c5ea98..eed524ae 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -414,6 +414,9 @@ prompt_dir() { truncate_from_right) current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g") ;; + truncate_fish_like) + current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1\//g") + ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; -- cgit v1.2.3 From f472ba7341615f17b279cc6859535e6e7668f637 Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Thu, 31 Dec 2015 15:57:56 +0100 Subject: added a new variable POWERLEVEL9K_SHORTEN_DELIMITER to specifiy the delimiter --- powerlevel9k.zsh-theme | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index eed524ae..7f578223 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -407,18 +407,23 @@ prompt_dir() { local current_path='%~' if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then + if [ -z "$POWERLEVEL9K_SHORTEN_DELIMITER" ] + then + POWERLEVEL9K_SHORTEN_DELIMITER=".." + elif [ "$POWERLEVEL9K_SHORTEN_DELIMITER" = false ] + then + POWERLEVEL9K_SHORTEN_DELIMITER="" + fi + case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g") + current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g") ;; truncate_from_right) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g") - ;; - truncate_fish_like) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1\//g") + current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\//g") ;; *) - current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; esac -- cgit v1.2.3 From 3441f750bf114bc68e519d9ab351373b54e83d7c Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Thu, 31 Dec 2015 19:04:26 +0100 Subject: used set_default-function instead --- powerlevel9k.zsh-theme | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7f578223..706c198a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -407,13 +407,7 @@ prompt_dir() { local current_path='%~' if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then - if [ -z "$POWERLEVEL9K_SHORTEN_DELIMITER" ] - then - POWERLEVEL9K_SHORTEN_DELIMITER=".." - elif [ "$POWERLEVEL9K_SHORTEN_DELIMITER" = false ] - then - POWERLEVEL9K_SHORTEN_DELIMITER="" - fi + set_default POWERLEVEL9K_SHORTEN_DELIMITER ".." case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) -- cgit v1.2.3 From 8dfca40eafa1bdb5e260dc029c285e24f01e619c Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Tue, 5 Jan 2016 13:56:07 -0800 Subject: Cleaning up comments. Also fixes #135. --- powerlevel9k.zsh-theme | 76 ++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 47cd467c..edd16582 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -8,7 +8,10 @@ ################################################################ ################################################################ -# Please see the README file located in the source repository for full docs. +# For basic documentation, please refer to the README.md in the top-level +# directory. For more detailed documentation, refer to the project wiki, hosted +# on Github: https://github.com/bhilburn/powerlevel9k/wiki +# # There are a lot of easy ways you can customize your prompt segments and # theming with simple variables defined in your `~/.zshrc`. ################################################################ @@ -17,7 +20,7 @@ #zstyle ':vcs_info:*+*:*' debug true #set -o xtrace -# Check if the theme was called as a function. +# Check if the theme was called as a function (e.g., from prezto) if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then autoload -U is-at-least if is-at-least 5.0.8; then @@ -45,7 +48,7 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then fi fi -# Check if filename is a symlink. +# If this theme is sourced as a symlink, we need to locate the true URL if [[ -L $0 ]]; then # Script is a symlink filename="$(realpath -P $0 2>/dev/null || readlink -f $0 2>/dev/null)" @@ -286,16 +289,15 @@ prompt_aws() { fi } -# Custom: a way for the user to specify custom commands to run, -# and display the output of. -# +# The 'custom` prompt provides a way for users to invoke commands and display +# the output in a segment. prompt_custom() { local command=POWERLEVEL9K_CUSTOM_$3:u "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" } -# print an icon, if there are background jobs +# Segment to indicate background jobs with an icon. prompt_background_jobs() { if [[ $(jobs -l | wc -l) -gt 0 ]]; then "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "cyan" "" 'BACKGROUND_JOBS_ICON' @@ -303,8 +305,7 @@ prompt_background_jobs() { } prompt_battery() { - # The battery can have different states. - # Default is "unknown" + # The battery can have four different states - default to 'unknown'. local current_state="unknown" typeset -AH battery_states battery_states=( @@ -313,24 +314,24 @@ prompt_battery() { 'charged' 'green' 'disconnected' "$DEFAULT_COLOR_INVERTED" ) - # set default values of not specified in shell + # Set default values if the user did not configure them set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then - # Pre-Grep all needed informations to save some memory and - # as little pollution of the xtrace output as possible. + # Pre-Grep as much information as possible to save some memory and + # avoid pollution of the xtrace output. local raw_data=$(ioreg -n AppleSmartBattery | grep -E "MaxCapacity|TimeRemaining|CurrentCapacity|ExternalConnected|IsCharging") # return if there is no battery on system [[ -z $(echo $raw_data | grep MaxCapacity) ]] && return - # convert time remaining from minutes to hours:minutes date string + # Convert time remaining from minutes to hours:minutes date string local time_remaining=$(echo $raw_data | grep TimeRemaining | awk '{ print $5 }') if [[ -n $time_remaining ]]; then # this value is set to a very high number when the system is calculating [[ $time_remaining -gt 10000 ]] && local tstring="..." || local tstring=${(f)$(date -u -r $(($time_remaining * 60)) +%k:%M)} fi - # get charge values + # Get charge values local max_capacity=$(echo $raw_data | grep MaxCapacity | awk '{ print $5 }') local current_capacity=$(echo $raw_data | grep CurrentCapacity | awk '{ print $5 }') @@ -340,8 +341,7 @@ prompt_battery() { fi local remain="" - ## logic for string output - # Powerplug connected + # Logic for string output if [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]]; then # Battery is charging if [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]]; then @@ -358,11 +358,11 @@ prompt_battery() { if [[ $OS =~ Linux ]]; then local sysp="/sys/class/power_supply" - # reported BAT0 or BAT1 depending on kernel version + # Reported BAT0 or BAT1 depending on kernel version [[ -a $sysp/BAT0 ]] && local bat=$sysp/BAT0 [[ -a $sysp/BAT1 ]] && local bat=$sysp/BAT1 - # return if no battery found + # Return if no battery found [[ -z $bat ]] && return [[ $(cat $bat/capacity) -gt 100 ]] && local bat_percent=100 || local bat_percent=$(cat $bat/capacity) @@ -383,7 +383,6 @@ prompt_battery() { [[ -n $tstring ]] && local remain=" ($tstring)" fi - # prepare string local message # Default behavior: Be verbose! set_default POWERLEVEL9K_BATTERY_VERBOSE true @@ -391,7 +390,7 @@ prompt_battery() { message="$bat_percent%%$remain" fi - # display prompt_segment + # Draw the prompt_segment [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON' } @@ -437,7 +436,7 @@ prompt_dir() { fi } -# GO-prompt +# GO prompt prompt_go_version() { local go_version go_version=$(go version 2>&1 | sed -E "s/.*(go[0-9.]*).*/\1/") @@ -524,6 +523,17 @@ prompt_node_version() { "$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1}" 'NODE_ICON' } +# Node version from NVM +# Only prints the segment if different than the default value +prompt_nvm() { + local node_version=$(nvm current) + local nvm_default=$(cat $NVM_DIR/alias/default) + [[ -z "${node_version}" ]] && return + [[ "$node_version" =~ "$nvm_default" ]] && return + + $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' +} + # print a little OS icon prompt_os_icon() { "$1_prompt_segment" "$0" "$2" "black" "255" "$OS_ICON" @@ -583,17 +593,6 @@ prompt_ram() { "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "${rendition% }" 'RAM_ICON' } -# Node version from NVM -# Only prints the segment if different than the default value -prompt_nvm() { - local node_version=$(nvm current) - local nvm_default=$(cat $NVM_DIR/alias/default) - [[ -z "${node_version}" ]] && return - [[ "$node_version" =~ "$nvm_default" ]] && return - - $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' -} - # rbenv information prompt_rbenv() { if [[ -n "$RBENV_VERSION" ]]; then @@ -601,14 +600,14 @@ prompt_rbenv() { fi } -# print an icon if user is root. +# Print an icon if user is root. prompt_root_indicator() { if [[ "$UID" -eq 0 ]]; then "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'ROOT_ICON' fi } -# print Rust version number +# 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\\\-]*$') @@ -711,7 +710,8 @@ prompt_todo() { fi } -# VCS segment: shows the state of your repository, if you are in a folder under version control +# VCS segment: shows the state of your repository, if you are in a folder under +# version control prompt_vcs() { autoload -Uz vcs_info @@ -898,8 +898,10 @@ powerlevel9k_init() { local term_colors term_colors=$(echotc Co) if (( term_colors < 256 )); then - print -P "%F{red}WARNING!%f Your terminal supports less than 256 colors!" - print -P "You should put: %F{blue}export TERM=\"xterm-256color\"%f in your \~\/.zshrc" + print -P "%F{red}WARNING!%f Your terminal appears to support less than 256 colors!" + print -P "If your terminal supports 256 colors, please export the appropriate environment variable" + print -P "_before_ loading this theme in your \~\/.zshrc. In most terminal emulators, putting" + print -P "%F{blue}export TERM=\"xterm-256color\"%f at the top of your \~\/.zshrc is sufficient." fi # Display a warning if deprecated segments are in use. -- cgit v1.2.3 From bbaa4a57f9f991552f1e528ae72cf9cae3900ecc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 7 Jan 2016 22:09:11 +0100 Subject: The foreground and background instructions are spaceless by default. No need to make them spaceless explicitly. --- powerlevel9k.zsh-theme | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index edd16582..efde41b3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -147,7 +147,7 @@ left_prompt_segment() { local joined=$2 if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$3" "$CURRENT_BG"; then - echo -n "%{$bg%F{$CURRENT_BG}%}" + echo -n "$bg%F{$CURRENT_BG}" if [[ $joined == false ]]; then # Middle segment echo -n "$(print_icon 'LEFT_SEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" @@ -159,13 +159,13 @@ left_prompt_segment() { # enough contrast. local complement [[ -n "$4" ]] && complement="$4" || complement=$DEFAULT_COLOR - echo -n "%{$bg%F{$complement}%}" + echo -n "$bg%F{$complement}" if [[ $joined == false ]]; then echo -n "$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi else # First segment - echo -n "%{$bg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "${bg}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi local visual_identifier @@ -184,7 +184,7 @@ left_prompt_segment() { # Print the visual identifier echo -n "${visual_identifier}" # Print the content of the segment, if there is any - [[ -n "$5" ]] && echo -n "%{$fg%}${5}" + [[ -n "$5" ]] && echo -n "${fg}${5}" echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" CURRENT_BG=$3 @@ -193,11 +193,11 @@ left_prompt_segment() { # End the left prompt, closes the final segment. left_prompt_end() { if [[ -n $CURRENT_BG ]]; then - echo -n "%{%k%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')" + echo -n "%k%F{$CURRENT_BG}$(print_icon 'LEFT_SEGMENT_SEPARATOR')" else echo -n "%k" fi - echo -n "%{%f%}$(print_icon 'LEFT_SEGMENT_END_SEPARATOR')" + echo -n "%f$(print_icon 'LEFT_SEGMENT_END_SEPARATOR')" CURRENT_BG='' } @@ -258,7 +258,7 @@ right_prompt_segment() { fi fi - echo -n "%{$bg%}%{$fg%}" + echo -n "${bg}${fg}" # Print whitespace only if segment is not joined or first right segment [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]] && echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}" @@ -843,7 +843,7 @@ powerlevel9k_prepare_prompts() { RETVAL=$? if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then - PROMPT="$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%{%f%b%k%}$(build_left_prompt) + PROMPT="$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt) $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" if [[ "$POWERLEVEL9K_RPROMPT_ON_NEWLINE" != true ]]; then # The right prompt should be on the same line as the first line of the left @@ -859,13 +859,13 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" RPROMPT_SUFFIX='' fi else - PROMPT="%{%f%b%k%}$(build_left_prompt)" + PROMPT="%f%b%k$(build_left_prompt)" RPROMPT_PREFIX='' RPROMPT_SUFFIX='' 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 } -- cgit v1.2.3 From d0a76d721cf948eea72e2d452909f346af250c3d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 8 Jan 2016 20:34:45 +0100 Subject: Sorted segments alphabetically. --- powerlevel9k.zsh-theme | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index efde41b3..b584edc9 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -289,14 +289,6 @@ prompt_aws() { fi } -# The 'custom` prompt provides a way for users to invoke commands and display -# the output in a segment. -prompt_custom() { - local command=POWERLEVEL9K_CUSTOM_$3:u - - "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" -} - # Segment to indicate background jobs with an icon. prompt_background_jobs() { if [[ $(jobs -l | wc -l) -gt 0 ]]; then @@ -407,6 +399,14 @@ prompt_context() { fi } +# The 'custom` prompt provides a way for users to invoke commands and display +# the output in a segment. +prompt_custom() { + local command=POWERLEVEL9K_CUSTOM_$3:u + + "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" +} + # Dir: current working directory prompt_dir() { local current_path='%~' -- cgit v1.2.3 From cdf08734dbd46ad110dbefc4ffe5ff5d5b948938 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 8 Jan 2016 20:42:06 +0100 Subject: Cleanup of the `load` segment. --- powerlevel9k.zsh-theme | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b584edc9..74b34a41 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -492,6 +492,14 @@ prompt_ip() { } prompt_load() { + # The load segment can have three different states + local current_state="unknown" + typeset -AH load_states + load_states=( + 'critical' 'red' + 'warning' 'yellow' + 'normal' 'green' + ) if [[ "$OS" == "OSX" ]]; then load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) else @@ -502,17 +510,14 @@ prompt_load() { load_avg_5min=${load_avg_5min//,/.} if [[ "$load_avg_5min" -gt 10 ]]; then - BACKGROUND_COLOR="red" - FUNCTION_SUFFIX="_CRITICAL" + current_state="critical" elif [[ "$load_avg_5min" -gt 3 ]]; then - BACKGROUND_COLOR="yellow" - FUNCTION_SUFFIX="_WARNING" + current_state="warning" else - BACKGROUND_COLOR="green" - FUNCTION_SUFFIX="_NORMAL" + current_state="normal" fi - "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$2" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' + "$1_prompt_segment" "${0}${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' } # Node version -- cgit v1.2.3 From 0b27bdc6f556fc854abb3ac4e1f2e03c6828762c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 8 Jan 2016 20:44:35 +0100 Subject: Comment cleanup. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 74b34a41..c01c9a9d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -644,7 +644,7 @@ prompt_rvm() { fi } -# Status: (return code, root status, background jobs) +# Status: return code if verbose, otherwise just an icon if an error occurred set_default POWERLEVEL9K_STATUS_VERBOSE true prompt_status() { if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then -- cgit v1.2.3 From 989a9b3b4b6cf1c254388f5e350a709a01097979 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 9 Jan 2016 16:25:15 +0100 Subject: Improved symlink dereferencing on OSX by calling a perl script. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index edd16582..0c0460a9 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -51,7 +51,7 @@ fi # If this theme is sourced as a symlink, we need to locate the true URL if [[ -L $0 ]]; then # Script is a symlink - filename="$(realpath -P $0 2>/dev/null || readlink -f $0 2>/dev/null)" + filename="$(realpath -P $0 2>/dev/null || readlink -f $0 2>/dev/null || perl -MCwd=abs_path -le 'print abs_path readlink(shift);' $0 2>/dev/null)" elif [[ -f $0 ]]; then # Script is a file filename="$0" -- cgit v1.2.3 From 9aeff8d43bd8ad95d913b21e68a5aa64036eda45 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Thu, 14 Jan 2016 11:05:26 -0700 Subject: added check for nvm command before running --- powerlevel9k.zsh-theme | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c01c9a9d..ab942d5b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -531,10 +531,12 @@ prompt_node_version() { # Node version from NVM # Only prints the segment if different than the default value prompt_nvm() { - local node_version=$(nvm current) - local nvm_default=$(cat $NVM_DIR/alias/default) - [[ -z "${node_version}" ]] && return - [[ "$node_version" =~ "$nvm_default" ]] && return + if [[ $(type nvm) =~ 'nvm is a shell function'* ]]; then + local node_version=$(nvm current) + local nvm_default=$(cat $NVM_DIR/alias/default) + [[ -z "${node_version}" ]] && return + [[ "$node_version" =~ "$nvm_default" ]] && return + fi $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' } -- cgit v1.2.3 From e29b3545bd4dc22f874347df9eb296e62105b94e Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Thu, 14 Jan 2016 11:07:11 -0700 Subject: fixed called to ioreg on OS X machines --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ab942d5b..451d1b6f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -312,7 +312,7 @@ prompt_battery() { if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then # Pre-Grep as much information as possible to save some memory and # avoid pollution of the xtrace output. - local raw_data=$(ioreg -n AppleSmartBattery | grep -E "MaxCapacity|TimeRemaining|CurrentCapacity|ExternalConnected|IsCharging") + local raw_data="$(ioreg -n AppleSmartBattery | grep -E "MaxCapacity|TimeRemaining|CurrentCapacity|ExternalConnected|IsCharging")" # return if there is no battery on system [[ -z $(echo $raw_data | grep MaxCapacity) ]] && return -- cgit v1.2.3 From 2fa7b1d08f55e71397f13f4e943491426b0e98c0 Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 14:09:39 -0700 Subject: don't output segment if node_version was not populated --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 451d1b6f..23e53221 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -538,7 +538,7 @@ prompt_nvm() { [[ "$node_version" =~ "$nvm_default" ]] && return fi - $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' + [[ -n "${node_version}" ]] && $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' } # print a little OS icon -- cgit v1.2.3 From 446f46473b2620bbe416488b68dd099be27f695a Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 16:16:27 -0700 Subject: reworked nvm check Now the prompt segment just returns without doing anything if nvm is not present. --- powerlevel9k.zsh-theme | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 23e53221..95849e99 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -531,14 +531,13 @@ prompt_node_version() { # Node version from NVM # Only prints the segment if different than the default value prompt_nvm() { - if [[ $(type nvm) =~ 'nvm is a shell function'* ]]; then - local node_version=$(nvm current) - local nvm_default=$(cat $NVM_DIR/alias/default) - [[ -z "${node_version}" ]] && return - [[ "$node_version" =~ "$nvm_default" ]] && return - fi + [[ $(type nvm) =~ 'nvm is a shell function'* ]] && return + local node_version=$(nvm current) + local nvm_default=$(cat $NVM_DIR/alias/default) + [[ -z "${node_version}" ]] && return + [[ "$node_version" =~ "$nvm_default" ]] && return - [[ -n "${node_version}" ]] && $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' + $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' } # print a little OS icon -- cgit v1.2.3 From 6f2f78b21fe597ad55e5f87360b68b4a812a7d19 Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 16:19:12 -0700 Subject: fixed conditional statement --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 95849e99..3e2beff0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -531,7 +531,7 @@ prompt_node_version() { # Node version from NVM # Only prints the segment if different than the default value prompt_nvm() { - [[ $(type nvm) =~ 'nvm is a shell function'* ]] && return + [[ ! $(type nvm) =~ 'nvm is a shell function'* ]] && return local node_version=$(nvm current) local nvm_default=$(cat $NVM_DIR/alias/default) [[ -z "${node_version}" ]] && return -- cgit v1.2.3 From cf921fb90c8d239f57391cf6ae459c3d6b6420bf Mon Sep 17 00:00:00 2001 From: Kayant Date: Fri, 15 Jan 2016 23:12:38 +0000 Subject: Add sub folder icon when in home subdirectories Big thanks to @dritter for guidance, @rjorgenson for great explanation. And @bhilburn for further guidance and encouragement. See http://i.imgur.com/2Vncypo.png for a presentation of how it looks. --- README.md | 2 ++ functions/icons.zsh | 4 +++- powerlevel9k.zsh-theme | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 9a5f7b12..520ee440 100644 --- a/README.md +++ b/README.md @@ -210,11 +210,13 @@ others whole directories. | `Compatible` | `Powerline` | `Awesome Powerline` | Situation |------------|-----------|-------------------|---------------------------- | None | None | ![home icon](https://cloud.githubusercontent.com/assets/1544760/12183451/40ec4016-b58f-11e5-9b9e-74e2b2f0b8b3.png) | Within Home folder | +| None | None | ![home sub_icon](https://cloud.githubusercontent.com/assets/1544760/12369315/8a5d762c-bbf5-11e5-8a20-ca1179f48d6c.png) | Within Home sub folder | | None | None | ![folder icon](https://cloud.githubusercontent.com/assets/1544760/12183452/40f79286-b58f-11e5-9b8c-ed1343a07b08.png) | Outside of home folder | To turn off these icons you could set these variables to an empty string. POWERLEVEL9K_HOME_ICON='' + POWERLEVEL9K_HOME_SUB_ICON='' POWERLEVEL9K_FOLDER_ICON='' ##### ip diff --git a/functions/icons.zsh b/functions/icons.zsh index a0171e69..6a9b044c 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -44,6 +44,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON $'\UE271' #  SUNOS_ICON $'\U1F31E ' # 🌞 HOME_ICON $'\UE12C' #  + HOME_SUB_ICON $'\UE18D' #  FOLDER_ICON $'\UE818' #  NETWORK_ICON $'\UE1AD' #  LOAD_ICON $'\UE190 ' #  @@ -96,6 +97,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON $'\UF17C' #  SUNOS_ICON $'\UF185 ' #  HOME_ICON $'\UF015' #  + HOME_SUB_ICON $'\UF07C' #  FOLDER_ICON $'\UF115' #  NETWORK_ICON $'\UF09E' #  LOAD_ICON $'\UF080 ' #  @@ -143,6 +145,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON 'Lx' SUNOS_ICON 'Sun' HOME_ICON '' + HOME_SUB_ICON '' FOLDER_ICON '' NETWORK_ICON 'IP' LOAD_ICON 'L' @@ -202,4 +205,3 @@ get_icon_names() { echo "POWERLEVEL9K_$key: ${icons[$key]}" done } - diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 119d31e2..c3b12759 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -429,8 +429,10 @@ prompt_dir() { fi local current_icon='' - if [[ $(print -P "%~") == '~'* ]]; then + if [[ $(print -P "%~") == '~' ]]; then "$1_prompt_segment" "$0_HOME" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_ICON' + elif [[ $(print -P "%~") == '~'* ]]; then + "$1_prompt_segment" "$0_HOME_SUBFOLDER" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_SUB_ICON' else "$1_prompt_segment" "$0_DEFAULT" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'FOLDER_ICON' fi -- cgit v1.2.3 From 37673977119273753c152a1472726c4d608f2b2c Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Fri, 15 Jan 2016 21:52:08 -0700 Subject: fixing segment call for new state implementation in prompt_load --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index a79548a5..500c7dc4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -519,7 +519,7 @@ prompt_load() { current_state="normal" fi - "$1_prompt_segment" "${0}${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' + "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' } # Node version -- cgit v1.2.3 From 01e4e8d324804e8048342a92a48ea1e40977d488 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 17 Jan 2016 01:02:03 +0100 Subject: Added "visual identifier" concept to `icons_test` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 500c7dc4..c8879dbc 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -459,7 +459,7 @@ prompt_icons_test() { # the next color has enough contrast to read. local random_color=$((RANDOM % 8)) local next_color=$((random_color+1)) - "$1_prompt_segment" "$0" "$2" "$random_color" "$next_color" "$key: ${icons[$key]}" + "$1_prompt_segment" "$0" "$2" "$random_color" "$next_color" "$key" "$key" done } -- cgit v1.2.3