From 2809000f9c11a932464810ff73ecbb6ac02d2952 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 20 Sep 2015 20:33:50 +0200 Subject: [PATCH 001/155] printHumanReadableSize should be able to process floats. --- powerlevel9k.zsh-theme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 From 43a6079d8396611e6d3693c1766b79b0356af65d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 20 Sep 2015 20:34:43 +0200 Subject: [PATCH 002/155] Ram as own prompt. --- powerlevel9k.zsh-theme | 56 +++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) 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) From 1a5edebae76586361258ab68cb3f26148dfe026e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 21 Sep 2015 18:27:03 +0200 Subject: [PATCH 003/155] Added a segment that shows the current GO version number. --- README.md | 1 + powerlevel9k.zsh-theme | 10 ++++++++++ 2 files changed, 11 insertions(+) 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' From f52a7f25701a42bda48be32e0649c86dd291fbb2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 26 Sep 2015 12:33:14 +0200 Subject: [PATCH 004/155] Corrected calculation of used swap under linux. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 6d24f93760d866feceda8750a115e19beb6250b1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 26 Sep 2015 12:51:08 +0200 Subject: [PATCH 005/155] Alphabetical order. --- powerlevel9k.zsh-theme | 87 +++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 43 deletions(-) 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 From 66b4194daf1970b7a000f9c3bdb2fdd34727af33 Mon Sep 17 00:00:00 2001 From: John Koelndorfer Date: Tue, 6 Oct 2015 10:20:52 -0500 Subject: [PATCH 006/155] 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(-) 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 From 0e37d8ef865daddd6af02ba78b4a3bb86fd5917e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 11 Oct 2015 16:18:27 +0200 Subject: [PATCH 007/155] 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(-) 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 From 20447a22c93c9fab1cd84b5882924c67771a4c61 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 11 Oct 2015 16:22:01 +0200 Subject: [PATCH 008/155] Removed unnecessary literal escape sequences. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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='' } From 6bf2869a1c8e509d1d0bb05ea05e179c48b9f7c4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 11 Oct 2015 19:41:52 +0200 Subject: [PATCH 009/155] 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(-) 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 From 2a1718d927c2805e68ed3bb5d92ccd0113a464a4 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:17:47 -0700 Subject: [PATCH 010/155] README: moving lots of information to the Wiki --- README.md | 317 +++++++++++++----------------------------------------- 1 file changed, 72 insertions(+), 245 deletions(-) diff --git a/README.md b/README.md index f0c37847..b56df188 100644 --- a/README.md +++ b/README.md @@ -92,149 +92,30 @@ varying terminal status indicators: ![](http://bhilburn.org/content/images/2014/12/powerlevel9k.png) ### Installation -There are two steps to start using this theme: +There are two installation steps to go from a lame terminal to a "Power Level +9000" terminal. Once you are done, you can optionally customize your prompt. -1. Install the Powerlevel9k theme. -2. Install Powerline-patched fonts. -3. [Optional] Configuration - -To get the most out of Powerlevel9k, you need to install both the theme as well -as Powerline-patched fonts, if you don't have them installed already. If you -cannot install Powerline-patched fonts for some reason, follow the instructions -below for a `compatible` install. +[Installation Instructions](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions) +1. [Install the Powerlevel9k Theme](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#step-1-install-powerlevel9k) +2. [Install Powerline-Patched Fonts](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#step-2-install-powerline-fonts) No configuration is necessary post-installation if you like the default -settings, but there is plenty of segment configuration available if you are -interested. +settings, but there are plenty of segment customization options available if you +are interested. -#### Step 1: Install Powerlevel9k -There are four ways to install and use the Powerlevel9k theme: vanilla ZSH, -Oh-My-Zsh, Prezto, and antigen. Do one of the following: - -##### Option 1: Install for Vanilla ZSH - -If you use just a vanilla ZSH install, simply clone this repository and -reference it in your `~/.zshrc`: - - $ git clone https://github.com/bhilburn/powerlevel9k.git - $ echo 'source powerlevel9k/powerlevel9k.zsh-theme' >> ~/.zshrc - -##### Option 2: Install for Oh-My-ZSH - -To install this theme for -[Oh-My-Zsh](https://github.com/robbyrussell/oh-my-zsh), clone this repository -into your OMZ `custom/themes` directory. - - $ cd ~/.oh-my-zsh/custom - $ git clone https://github.com/bhilburn/powerlevel9k.git themes/powerlevel9k - -You then need to select this theme in your `~/.zshrc`: - - ZSH_THEME="powerlevel9k/powerlevel9k" - -##### Option 3: Install for Prezto - -To install this theme for use in Prezto, clone this repository into your -[Prezto](https://github.com/sorin-ionescu/prezto) `prompt/external` directory. - - $ cd ~.zprezto/modules/prompt/external - $ git clone https://github.com/bhilburn/powerlevel9k.git - $ ln -s powerlevel9k/powerlevel9k.zsh-theme ../functions/prompt_powerlevel9k_setup - -You then need to select this theme in your `~/.zpreztorc`: - - zstyle ':prezto:module:prompt' theme 'powerlevel9k' - -##### Option 4: Install for antigen - -If you prefer [antigen](https://github.com/zsh-users/antigen), just add this -theme to the antigen config in your `~/.zshrc`: - - $ echo 'antigen theme bhilburn/powerlevel9k powerlevel9k' >> ~/.zshrc - $ echo 'antigen apply' >> ~/.zshrc - -Note that you should define any customizations before calling `antigen theme` -(i.e. setting the `POWERLEVEL9K_*` variables) in your `.zshrc`. - -#### Step 2: Install Powerline Fonts -Technically, you don't *have* to install Powerline fonts. If you are using -a font that has some of the basic glyphs we need, you can use the theme in -`compatible` mode - see the third option, below. - -To get the most out of theme, though, you'll want Powerline-patched fonts. There -are two varieties of these: 'Powerline Fonts' and 'Awesome Powerline -Fonts'. The latter includes additional glyphs that aren't required for a normal -install. - -Do one of the following: - -##### Option 1: Install Powerline Fonts - -You can find the [installation instructions for Powerline Fonts here] -(https://powerline.readthedocs.org/en/latest/installation/linux.html#fonts-installation). -You can also find the raw font files [in this Github -repository](https://github.com/powerline/fonts) if you want to manually install -them for your OS. - -After you have installed Powerline fonts, make the default font in your terminal -emulator the Powerline font you want to use. - -This is the default mode for `Powerlevel9k`, and no further configuration is -necessary. - -**N.B.:** If Powerlevel9k is not working properly, it is almost always the case -that the fonts were not properly installed, or you have not configured your -terminal to use a Powerline-patched font! - -##### Option 2: Install Awesome Powerline Fonts - -Alternatively, you can install [Awesome Powerline -Fonts](https://github.com/gabrielelana/awesome-terminal-fonts), which provide -a number of additional glyphs. - -You then need to indicate that you wish to use the additional glyphs by defining -the following in your `~/.zshrc`: - - POWERLEVEL9K_MODE='awesome-fontconfig' - -If you chose to use already patched fonts, use instead : - - POWERLEVEL9K_MODE='awesome-patched' - - -If you choose to make use of this, your prompt will look something like this: - -![](https://cloud.githubusercontent.com/assets/1544760/7959660/67612918-09fb-11e5-9ef2-2308363c3c51.png) - -Note that if you prefer flat segment transitions, you can use the following with -`Awesome Powerline Fonts` installed: - - POWERLEVEL9K_MODE='flat' - -Which looks like this: - -![](https://cloud.githubusercontent.com/assets/1544760/7981324/76d0eb5a-0aae-11e5-9608-d662123d0b0a.png) - -##### Option 3: Compatible Mode - -This option is best if you prefer not to install additional fonts. This option -will work out-of-the-box if your your terminal font supports the segment -separator characters `\uE0B0` (left segment separator) and `\uE0B2` (right -segment separator). - -All you need to do to in this case is install the `Powerlevel9k` theme itself, -as explained above, and then define the following in your `~/.zshrc`: - - POWERLEVEL9K_MODE='compatible' - -Note that depending on your terminal font, this may still not render -appropriately. This configuration should be used as a back-up. - -### Segment Customization +### Customization +#### Customizing Prompt Segments Customizing your prompt is easy! Select the segments you want to have displayed, -and then assign them to either the left or right prompt. The segments that are -currently available are: +and then assign them to either the left or right prompt by adding the following +variables to your `~/.zshrc`. If you don't customize this, the below +configuration is the default: + + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) + +#### Available Prompt Segments +The segments that are currently available are: * **aws** - The current AWS profile, if active (more info below) * **context** - Your username and host (more info below) @@ -255,13 +136,8 @@ currently available are: * **virtualenv** - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). * **vcs** - Information about this `git` or `hg` repository (if you are in one). -To specify which segments you want, just add the following variables to your -`~/.zshrc`. If you don't customize this, the below configuration is the default: - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) - POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) - -#### The AWS Profile Segment +##### aws If you would like to display the [current AWS profile](http://docs.aws.amazon.com/cli/latest/userguide/installing.html), add @@ -270,7 +146,7 @@ your `~/.zshrc`: export AWS_DEFAULT_PROFILE= -#### The 'context' Segment +##### context The `context` segment (user@host string) is conditional. This lets you enable it, but only display it if you are not your normal user or on a remote host (basically, only print it @@ -281,7 +157,7 @@ elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`: export DEFAULT_USER= -#### The 'dir' segment +##### dir The `dir` segment shows the current working directory. You can limit the output to a certain length: @@ -301,7 +177,7 @@ 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 others whole directories. -#### The 'ip' segment +##### ip This segment shows you your current internal IP address. It tries to examine all currently used network interfaces and prints the first address it finds. @@ -310,7 +186,24 @@ network interface by setting: POWERLEVEL9K_IP_INTERFACE="eth0" -#### The 'time' segment +##### rspec_tests + +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`. + + POWERLEVEL9K_STATUS_VERBOSE=false + +##### symphony2_tests + +See [Unit Test Ratios](#unit-test-ratios), below. + +##### time By default the time is show in 'H:M:S' format. If you want to change it, just set another format in your `~/.zshrc`. As an example, this is a reversed @@ -325,43 +218,7 @@ segment, as well: # Output time, date, and a symbol from the "Awesome Powerline Font" set POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}" -#### Showing Status - -Usually we display always the status, and in case a command failed, the return -code of the last executed program. In case you want to display the status only -if something special happend, you can set `POWERLEVEL9K_STATUS_VERBOSE=false` -in your `~/.zshrc`. - -#### Unit Test Ratios - -The `symfony2_tests` and `rspec_tests` segments both show a ratio of "real" -classes vs test classes in your source code. This is just a very simple ratio, -and does not show your code coverage or any sophisticated stats. All this does -is count your source files and test files, and calculate the ratio between them. -Just enough to give you a quick overview about the test situation of the project -you are dealing with. - -#### VI-Mode Indicator - -This Segment shows the current mode of your ZSH. If you want to use your ZSH in -VI-Mode, you need to configure it separatly in your `~/.zshrc`: - - # VI-Mode - # general activation - bindkey -v - - # set some nice hotkeys - bindkey '^P' up-history - bindkey '^N' down-history - bindkey '^?' backward-delete-char - bindkey '^h' backward-delete-char - bindkey '^w' backward-kill-word - bindkey '^r' history-incremental-search-backward - - # make it more responsive - export KEYTIMEOUT=1 - -#### The 'vcs' Segment +##### vcs By default, the `vcs` segment will provide quite a bit of information. If you would also like for it to display the current hash / changeset, simply define @@ -380,7 +237,7 @@ You can also disable the branch icon in your prompt by setting # Hide the branch icon POWERLEVEL9K_HIDE_BRANCH_ICON=true -##### Symbols +**vcs Symbols** The `vcs` segment uses various symbols to tell you the state of your repository. These symbols depend on your installed font and selected `POWERLEVEL9K_MODE` @@ -401,6 +258,36 @@ from the [Installation](#Installation) section above. | None | None | ![icon_git](https://cloud.githubusercontent.com/assets/1544760/7976092/b5909f80-0a76-11e5-9950-1438b9d72465.gif) | Repository is a git repository | None | None | ![icon_mercurial](https://cloud.githubusercontent.com/assets/1544760/7976090/b5908da6-0a76-11e5-8c91-452b6e73f631.gif) | Repository is a Mercurial repository +##### vi_mode + +This Segment shows the current mode of your ZSH. If you want to use your ZSH in +VI-Mode, you need to configure it separately in your `~/.zshrc`: + + # VI-Mode + # general activation + bindkey -v + + # set some nice hotkeys + bindkey '^P' up-history + bindkey '^N' down-history + bindkey '^?' backward-delete-char + bindkey '^h' backward-delete-char + bindkey '^w' backward-kill-word + bindkey '^r' history-incremental-search-backward + + # make it more responsive + export KEYTIMEOUT=1 + +#### Unit Test Ratios + +The `symfony2_tests` and `rspec_tests` segments both show a ratio of "real" +classes vs test classes in your source code. This is just a very simple ratio, +and does not show your code coverage or any sophisticated stats. All this does +is count your source files and test files, and calculate the ratio between them. +Just enough to give you a quick overview about the test situation of the project +you are dealing with. + + ### Styling You can configure the look and feel of your prompt easily with some built-in @@ -519,63 +406,3 @@ your prompt even further. These Segments are `context`, `vcs`, `rspec_stats`, # symfony2_tests for poor test coverage POWERLEVEL9K_SYMFONY2_TESTS_BAD_FOREGROUND='red' POWERLEVEL9K_SYMFONY2_TESTS_BAD_BACKGROUND='white' - -### Troubleshooting - -Here are some fixes to some common problems. - -#### Gaps Between Segments - -You can see this issue in the screenshot, below: - -![](http://bhilburn.org/content/images/2014/12/font_issue.png) - -Thankfully, this is easy to fix. This happens if you have successfully installed -Powerline fonts, but did not make a Powerline font the default font in your -terminal emulator (e.g., 'terminator', 'gnome-terminal', 'konsole', etc.,). - -#### Segment Colors are Wrong - -If the color display within your terminal seems off, it's possible you are using -a reduced color set. You can check this by invoking `echotc Co` in your -terminal, which should yield `256`. If you see something different, try setting -`xterm-256color` in your `~/.zshrc`: - - TERM=xterm-256color - -#### Strange Characters in prompt - -If your prompt shows strange character like this: - -![](https://cloud.githubusercontent.com/assets/1544760/9156161/e0e584e6-3ed0-11e5-897a-2318a8e32d35.png) - -it is most likely that you set `POWERLEVEL9K_MODE="awesome-patched"`, but -did not install an [awesome-font](https://github.com/gabrielelana/awesome-terminal-fonts). For most other modes, you need a [powerline-patched](https://github.com/powerline/fonts) font. - -### Meta - -#### Kudos - -This theme wouldn't have happened without inspiration from the original -[agnoster](https://github.com/agnoster/agnoster-zsh-theme) ZSH theme. - -Before creating this theme, I also tried [jeremyFreeAgent's -theme](https://github.com/jeremyFreeAgent/oh-my-zsh-powerline-theme) and -[maverick2000's theme, ZSH2000](https://github.com/maverick2000/zsh2000). - -#### Developing - -Documentation for developers is kept on the [Powerlevel9k Github -wiki](https://github.com/bhilburn/powerlevel9k/wiki/Developer's-Guide). - -#### Contributions / Bugs / Contact - -If you have any requests or bug reports, please use the tracker in this Github -repository. - -I'm happy to accept code contributions from anyone who has a bug fix, new -feature, or just a general improvement! Please submit your contribution as -a Github pull-request. - -If you would like to contact me directly, you can find my e-mail address on my -[Github profile page](https://github.com/bhilburn). From a4096b4c0610c21060aef68dfceee14ec758cdd9 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:22:05 -0700 Subject: [PATCH 011/155] README: Creating links for each segment section --- README.md | 78 +++++++++++++------------------------------------------ 1 file changed, 18 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index b56df188..0ff1f739 100644 --- a/README.md +++ b/README.md @@ -22,48 +22,6 @@ this theme focus on four primary goals: 4. Optimize the code for execution speed as much as possible. A snappy terminal is a happy terminal. - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [Features](#features) -- [Installation](#installation) - - [Step 1: Install Powerlevel9k](#step-1-install-powerlevel9k) - - [Option 1: Install for Vanilla ZSH](#option-1-install-for-vanilla-zsh) - - [Option 2: Install for Oh-My-ZSH](#option-2-install-for-oh-my-zsh) - - [Option 3: Install for Prezto](#option-3-install-for-prezto) - - [Option 4: Install for antigen](#option-4-install-for-antigen) - - [Step 2: Install Powerline Fonts](#step-2-install-powerline-fonts) - - [Option 1: Install Powerline Fonts](#option-1-install-powerline-fonts) - - [Option 2: Install Awesome Powerline Fonts](#option-2-install-awesome-powerline-fonts) - - [Option 3: Compatible Mode](#option-3-compatible-mode) -- [Segment Customization](#segment-customization) - - [The AWS Profile Segment](#the-aws-profile-segment) - - [The 'context' Segment](#the-context-segment) - - [The 'dir' segment](#the-dir-segment) - - [The 'ip' segment](#the-ip-segment) - - [The 'time' segment](#the-time-segment) - - [Unit Test Ratios](#unit-test-ratios) - - [The 'vcs' Segment](#the-vcs-segment) - - [Symbols](#symbols) -- [Styling](#styling) - - [Double-Lined Prompt](#double-lined-prompt) - - [Disable Right Prompt](#disable-right-prompt) - - [Light Color Theme](#light-color-theme) - - [Icon Customization](#icon-customization) - - [Segment Color Customization](#segment-color-customization) - - [Special Segment Colors](#special-segment-colors) -- [Troubleshooting](#troubleshooting) - - [Gaps Between Segments](#gaps-between-segments) - - [Segment Colors are Wrong](#segment-colors-are-wrong) - - [Strange Characters in prompt](#strange-characters-in-prompt) -- [Meta](#meta) - - [Kudos](#kudos) - - [Developing](#developing) - - [Contributions / Bugs / Contact](#contributions--bugs--contact) - - - ### Features * Supports `git` and `mercurial` repo information through ZSH's `VCS_INFO`: @@ -117,24 +75,24 @@ configuration is the default: #### Available Prompt Segments The segments that are currently available are: -* **aws** - The current AWS profile, if active (more info below) -* **context** - Your username and host (more info below) -* **dir** - Your current working directory. -* **history** - The command number for the current line. -* **ip** - Shows the current IP address. -* **load** - Your machines 5 minute load average and free RAM. -* **node_version** - Show the version number of the installed Node.js. -* **os_icon** - Display a nice little icon, depending on your operating system. -* **php_version** - Show the current PHP version. -* **rbenv** - Ruby environment information (if one is active). -* **rspec_stats** - Show a ratio of test classes vs code classes for RSpec. -* **status** - The return code of the previous command, and status of background jobs. -* **symfony2_tests** - Show a ratio of test classes vs code classes for Symfony2. -* **symfony2_version** - Show the current Symfony2 version, if you are in a Symfony2-Project dir. -* **time** - System time. -* **vi_mode** - Vi editing mode (NORMAL|INSERT). -* **virtualenv** - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). -* **vcs** - Information about this `git` or `hg` repository (if you are in one). +* [aws](#aws) - The current AWS profile, if active. +* [context](#context) - Your username and host. +* [dir](#dir) - Your current working directory. +* [history](#history) - The command number for the current line. +* [ip](#ip) - Shows the current IP address. +* [load](#load) - Your machines 5 minute load average and free RAM. +* [node_version](#node_version) - Show the version number of the installed Node.js. +* [os_icon](#os_icon) - Display a nice little icon, depending on your operating system. +* [php_version](#php_version) - Show the current PHP version. +* [rbenv](#rbenv) - Ruby environment information (if one is active). +* [rspec_stats](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. +* [status](#status) - The return code of the previous command, and status of background jobs. +* [symphony2_tests](#symphony2_tests) - Show a ratio of test classes vs code classes for Symfony2. +* [symphony2_version](#symphony2_version)- Show the current Symfony2 version, if you are in a Symfony2-Project dir. +* [time](#time) - System time. +* [vi_mode](#vi_mode)- Vi editing mode (NORMAL|INSERT). +* [virtualenv](#virtualenv) - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). +* [vcs](#vcs) - Information about this `git` or `hg` repository (if you are in one). ##### aws From cdaa2c830bb5cc5c6f28e6dc75c9ad690a56b806 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:26:04 -0700 Subject: [PATCH 012/155] README: Fixing some segment links --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0ff1f739..7add1dc9 100644 --- a/README.md +++ b/README.md @@ -78,20 +78,20 @@ The segments that are currently available are: * [aws](#aws) - The current AWS profile, if active. * [context](#context) - Your username and host. * [dir](#dir) - Your current working directory. -* [history](#history) - The command number for the current line. +* history - The command number for the current line. * [ip](#ip) - Shows the current IP address. -* [load](#load) - Your machines 5 minute load average and free RAM. -* [node_version](#node_version) - Show the version number of the installed Node.js. -* [os_icon](#os_icon) - Display a nice little icon, depending on your operating system. -* [php_version](#php_version) - Show the current PHP version. +* load - Your machines 5 minute load average and free RAM. +* node_version - Show the version number of the installed Node.js. +* os_icon - Display a nice little icon, depending on your operating system. +* php_version - Show the current PHP version. * [rbenv](#rbenv) - Ruby environment information (if one is active). * [rspec_stats](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. * [status](#status) - The return code of the previous command, and status of background jobs. * [symphony2_tests](#symphony2_tests) - Show a ratio of test classes vs code classes for Symfony2. -* [symphony2_version](#symphony2_version)- Show the current Symfony2 version, if you are in a Symfony2-Project dir. +* symphony2_version - Show the current Symfony2 version, if you are in a Symfony2-Project dir. * [time](#time) - System time. * [vi_mode](#vi_mode)- Vi editing mode (NORMAL|INSERT). -* [virtualenv](#virtualenv) - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). +* virtualenv - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). * [vcs](#vcs) - Information about this `git` or `hg` repository (if you are in one). @@ -144,7 +144,7 @@ network interface by setting: POWERLEVEL9K_IP_INTERFACE="eth0" -##### rspec_tests +##### rspec_stats See [Unit Test Ratios](#unit-test-ratios), below. @@ -238,7 +238,7 @@ VI-Mode, you need to configure it separately in your `~/.zshrc`: #### Unit Test Ratios -The `symfony2_tests` and `rspec_tests` segments both show a ratio of "real" +The `symfony2_tests` and `rspec_stats` segments both show a ratio of "real" classes vs test classes in your source code. This is just a very simple ratio, and does not show your code coverage or any sophisticated stats. All this does is count your source files and test files, and calculate the ratio between them. From b3c7fdf410f14cdbd828712ae325e1e895245e98 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:28:53 -0700 Subject: [PATCH 013/155] README: cleanup --- README.md | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 7add1dc9..96e62ebc 100644 --- a/README.md +++ b/README.md @@ -22,28 +22,6 @@ this theme focus on four primary goals: 4. Optimize the code for execution speed as much as possible. A snappy terminal is a happy terminal. -### Features - -* Supports `git` and `mercurial` repo information through ZSH's `VCS_INFO`: - * branch / tag name - * current action status (rebasing, merging, etc.,) - * being behind / ahead of your remote by some number of commits - * number of stashes (git only) - * conditionally shows remote tracking branch if the name differs from local - * current active bookmark (mercurial only) - * various working tree statuses (e.g., unstaged, staged, etc.,) -* Shows return-code of the last command if it is an error code -* Indicates background jobs with a gear icon -* Can conditionally display the `user@host` string when needed (e.g., SSH) -* Provides segment for command history (so you can `$ !` to re-run) -* Plenty of additional segments to choose from (e.g., AWS, ruby) -* Can be used as a single or double-lined prompt (see screenshots below) -* Several built-in color configurations to choose from - -**If you would like an OMZ theme that provides some of the same features but -doesn't require Powerline fonts, check out the sister font, -[hackersaurus](https://github.com/bhilburn/hackersaurus).** - Here is a detailed screenshot showing `powerlevel9k` with default settings and varying terminal status indicators: @@ -78,20 +56,20 @@ The segments that are currently available are: * [aws](#aws) - The current AWS profile, if active. * [context](#context) - Your username and host. * [dir](#dir) - Your current working directory. -* history - The command number for the current line. +* **history** - The command number for the current line. * [ip](#ip) - Shows the current IP address. -* load - Your machines 5 minute load average and free RAM. -* node_version - Show the version number of the installed Node.js. -* os_icon - Display a nice little icon, depending on your operating system. -* php_version - Show the current PHP version. +* **load** - Your machines 5 minute load average and free RAM. +* **node_version** - Show the version number of the installed Node.js. +* **os_icon** - Display a nice little icon, depending on your operating system. +* **php_version** - Show the current PHP version. * [rbenv](#rbenv) - Ruby environment information (if one is active). * [rspec_stats](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. * [status](#status) - The return code of the previous command, and status of background jobs. * [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. +* **symphony2_version** - Show the current Symfony2 version, if you are in a Symfony2-Project dir. * [time](#time) - System time. * [vi_mode](#vi_mode)- Vi editing mode (NORMAL|INSERT). -* virtualenv - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). +* **virtualenv** - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). * [vcs](#vcs) - Information about this `git` or `hg` repository (if you are in one). From 49427538d7dd82a98427056d8a5f46aadf0ac276 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:31:14 -0700 Subject: [PATCH 014/155] README: Fixing install instruction bullets --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 96e62ebc..14cffab5 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ There are two installation steps to go from a lame terminal to a "Power Level 9000" terminal. Once you are done, you can optionally customize your prompt. [Installation Instructions](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions) + 1. [Install the Powerlevel9k Theme](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#step-1-install-powerlevel9k) 2. [Install Powerline-Patched Fonts](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#step-2-install-powerline-fonts) From d592e047d311ac64119588222084f688b9b0cfb1 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:34:44 -0700 Subject: [PATCH 015/155] README: Adding ToC --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 14cffab5..279de81a 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,12 @@ varying terminal status indicators: ![](http://bhilburn.org/content/images/2014/12/powerlevel9k.png) +### Table of Contents + +1. (Installation)[#installation] +2. (Customization)[#customization] +3. (Styling)[#styling] + ### Installation There are two installation steps to go from a lame terminal to a "Power Level 9000" terminal. Once you are done, you can optionally customize your prompt. From b6d1cd109e0ce3f706ebbdacd5a306e3f91d8297 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:35:22 -0700 Subject: [PATCH 016/155] README: I'm good at markdown --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 279de81a..2871e744 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ varying terminal status indicators: ### Table of Contents -1. (Installation)[#installation] -2. (Customization)[#customization] -3. (Styling)[#styling] +1. [Installation](#installation) +2. [Customization](#customization) +3. [Styling](#styling) ### Installation There are two installation steps to go from a lame terminal to a "Power Level From 625b584ddd1d37b2cd42167e8f468e4040e081bb Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:49:12 -0700 Subject: [PATCH 017/155] README: Moving styling to the wiki --- README.md | 129 ++++-------------------------------------------------- 1 file changed, 8 insertions(+), 121 deletions(-) diff --git a/README.md b/README.md index 2871e744..b6a67797 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ varying terminal status indicators: 1. [Installation](#installation) 2. [Customization](#customization) -3. [Styling](#styling) +3. [Stylizing](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) +4. [Troubleshooting](https://github.com/bhilburn/powerlevel9k/wiki/Troubleshooting) ### Installation There are two installation steps to go from a lame terminal to a "Power Level @@ -48,6 +49,12 @@ are interested. ### Customization +#### Customizing Your Prompt +Be sure to check out the wiki page on the additional prompt customization +options, including color and icon settings: + +[Stylizing Your Prompt](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) + #### Customizing Prompt Segments Customizing your prompt is easy! Select the segments you want to have displayed, and then assign them to either the left or right prompt by adding the following @@ -229,123 +236,3 @@ and does not show your code coverage or any sophisticated stats. All this does is count your source files and test files, and calculate the ratio between them. Just enough to give you a quick overview about the test situation of the project you are dealing with. - - -### Styling - -You can configure the look and feel of your prompt easily with some built-in -options. - -#### Double-Lined Prompt - -By default, `powerlevel9k` is a single-lined prompt. If you would like to have -the segments display on one line, and print the command prompt below it, simply -define `POWERLEVEL9K_PROMPT_ON_NEWLINE` in your `~/.zshrc`: - - POWERLEVEL9K_PROMPT_ON_NEWLINE=true - -Here is what it looks like: - -![](http://bhilburn.org/content/images/2015/03/double-line.png) - -You can customize the icons used to draw the multiline prompt by setting the -following variables in your `~/.zshrc`: - - POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="↱" - POWERLEVEL9K_MULTILINE_SECOND_PROMPT_PREFIX="↳ " - -#### Disable Right Prompt - -If you do not want a right prompt, you can disable it by setting: - - POWERLEVEL9K_DISABLE_RPROMPT=true - -#### Light Color Theme - -If you prefer to use "light" colors, simply set `POWERLEVEL9K_COLOR_SCHEME` -to `light` in your `~/.zshrc`, and you're all set! - - POWERLEVEL9K_COLOR_SCHEME='light' - -The 'light' color scheme works well for ['Solarized -Light'](https://github.com/altercation/solarized) users. Check it out: - -![](http://bhilburn.org/content/images/2015/03/solarized-light.png) - -#### Icon Customization - -Each icon used can be customized too by specifying a variable named like -the icon and prefixed with 'POWERLEVEL9K'. If you want to use another icon -as segment separators, you can easily do that: - - POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR=$'\uE0B1' - POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR=$'\uE0B3' - -You could get a list of all icons defined in random colors, by adding the -special segment `icons_test` to your prompt: - - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(icons_test) - -This special prompt does not work on the right side, as it would be too long, -and ZSH hides it automatically. Also have in mind, that the output depends on -your `POWERLEVEL9K_MODE` settings. - -You can change any icon by setting a environment variable. To get a full list -of icons just type `get_icon_names` in your terminal. - -#### Segment Color Customization - -For each segment in your prompt, you can specify a foreground and background -color by setting them in your `~/.zshrc`. Use the segment names from the above -section `Segment Customization`. For example, to change the appearance of the -`time` segment, you would use: - - POWERLEVEL9K_TIME_FOREGROUND='red' - POWERLEVEL9K_TIME_BACKGROUND='blue' - -Note that you can also use a colorcode value. Example: - - POWERLEVEL9K_VCS_FOREGROUND='021' # Dark blue - -For a full list of supported colors, run the `spectrum_ls` program in your -terminal. - -#### Special Segment Colors - -Some segments have additional color options if you want to customize the look of -your prompt even further. These Segments are `context`, `vcs`, `rspec_stats`, -`symfony2_tests`: - - # Customizing `context` colors for root and non-root users - POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND="green" - POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND="cyan" - POWERLEVEL9K_CONTEXT_ROOT_BACKGROUND="red" - POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND="blue" - - # Advanced `vcs` color customization - POWERLEVEL9K_VCS_FOREGROUND='blue' - POWERLEVEL9K_VCS_DARK_FOREGROUND='black' - POWERLEVEL9K_VCS_BACKGROUND='green' - # If VCS changes are detected: - POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red' - POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='cyan' - - # rspec_stats for good test coverage - POWERLEVEL9K_RSPEC_STATS_GOOD_FOREGROUND='blue' - POWERLEVEL9K_RSPEC_STATS_GOOD_BACKGROUND='green' - # rspec_stats for average test coverage - POWERLEVEL9K_RSPEC_STATS_AVG_FOREGROUND='black' - POWERLEVEL9K_RSPEC_STATS_AVG_BACKGROUND='cyan' - # rspec_stats for poor test coverage - POWERLEVEL9K_RSPEC_STATS_BAD_FOREGROUND='red' - POWERLEVEL9K_RSPEC_STATS_BAD_BACKGROUND='white' - - # symfony2_tests for good test coverage - POWERLEVEL9K_SYMFONY2_TESTS_GOOD_FOREGROUND='blue' - POWERLEVEL9K_SYMFONY2_TESTS_GOOD_BACKGROUND='green' - # symfony2_tests for average test coverage - POWERLEVEL9K_SYMFONY2_TESTS_AVG_FOREGROUND='black' - POWERLEVEL9K_SYMFONY2_TESTS_AVG_BACKGROUND='cyan' - # symfony2_tests for poor test coverage - POWERLEVEL9K_SYMFONY2_TESTS_BAD_FOREGROUND='red' - POWERLEVEL9K_SYMFONY2_TESTS_BAD_BACKGROUND='white' From 5714581e1306a2f165af24364beb99ba279ae5de Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:53:17 -0700 Subject: [PATCH 018/155] README: Final cleanup --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b6a67797..04b34087 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ Look like a bad-ass. Impress everyone in 'Screenshot Your Desktop' threads. Use ![](http://bhilburn.org/content/images/2015/01/pl9k-improved.png) +You can check out some other users' configurations in our wiki: [Show Off Your +Config](https://github.com/bhilburn/powerlevel9k/wiki/Show-Off-Your-Config). + There are a number of Powerline ZSH themes available, now. The developers of this theme focus on four primary goals: @@ -22,8 +25,7 @@ this theme focus on four primary goals: 4. Optimize the code for execution speed as much as possible. A snappy terminal is a happy terminal. -Here is a detailed screenshot showing `powerlevel9k` with default settings and -varying terminal status indicators: +Here is a detailed screenshot showing `powerlevel9k` in action, with default settings. ![](http://bhilburn.org/content/images/2014/12/powerlevel9k.png) @@ -51,9 +53,7 @@ are interested. #### Customizing Your Prompt Be sure to check out the wiki page on the additional prompt customization -options, including color and icon settings: - -[Stylizing Your Prompt](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) +options, including color and icon settings: [Stylizing Your Prompt](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) #### Customizing Prompt Segments Customizing your prompt is easy! Select the segments you want to have displayed, From 0b6b6de8e108a0465f6c42b7c3992e3c2cbb19bb Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:57:18 -0700 Subject: [PATCH 019/155] README: Cleaning up ToC --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 04b34087..412aabae 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,11 @@ Here is a detailed screenshot showing `powerlevel9k` in action, with default set ### Table of Contents 1. [Installation](#installation) -2. [Customization](#customization) -3. [Stylizing](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) -4. [Troubleshooting](https://github.com/bhilburn/powerlevel9k/wiki/Troubleshooting) +2. [Customization](#prompt-customization) + 1. [Stylizing Your Prompt](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) + 2. [Customizing Prompt Segments](#customizing-prompt-segments) + 3. [Available Prompt Segments](#available-prompt-segments) +3. [Troubleshooting](https://github.com/bhilburn/powerlevel9k/wiki/Troubleshooting) ### Installation There are two installation steps to go from a lame terminal to a "Power Level @@ -49,9 +51,8 @@ No configuration is necessary post-installation if you like the default settings, but there are plenty of segment customization options available if you are interested. -### Customization +### Prompt Customization -#### Customizing Your Prompt Be sure to check out the wiki page on the additional prompt customization options, including color and icon settings: [Stylizing Your Prompt](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) From 9d8ab6f6677b6829a87939d770b45624470cc77c Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 14:58:51 -0700 Subject: [PATCH 020/155] README: Add link to Wiki at end of README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 412aabae..c6d7bd1c 100644 --- a/README.md +++ b/README.md @@ -237,3 +237,9 @@ and does not show your code coverage or any sophisticated stats. All this does is count your source files and test files, and calculate the ratio between them. Just enough to give you a quick overview about the test situation of the project you are dealing with. + +### Other + +Looking for more information? We put a lot of stuff in our Wiki! + +[Head to the Wiki](https://github.com/bhilburn/powerlevel9k/wiki) From 941379d71c7a11c1de042bc8cd4ef5b7ccc6a17c Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 12 Oct 2015 15:00:17 -0700 Subject: [PATCH 021/155] README: one more wiki link to ToC --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c6d7bd1c..4baf0629 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ Here is a detailed screenshot showing `powerlevel9k` in action, with default set 3. [Available Prompt Segments](#available-prompt-segments) 3. [Troubleshooting](https://github.com/bhilburn/powerlevel9k/wiki/Troubleshooting) +Be sure to also [check out the Wiki](https://github.com/bhilburn/powerlevel9k/wiki)! + ### Installation There are two installation steps to go from a lame terminal to a "Power Level 9000" terminal. Once you are done, you can optionally customize your prompt. From f7e1f64b4c0f44408bb06d7dec018768dd767c5b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 13 Oct 2015 23:42:46 +0200 Subject: [PATCH 022/155] Added handling for bright colors. --- powerlevel9k.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) 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 } From 7e6339ec2770bacc71ba83139330aec574f752f6 Mon Sep 17 00:00:00 2001 From: Alex LaFroscia Date: Mon, 12 Oct 2015 00:28:33 -0400 Subject: [PATCH 023/155] 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(+) 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 From d5ffa502e26b574577f523e22476f23ec4567083 Mon Sep 17 00:00:00 2001 From: Alex LaFroscia Date: Tue, 13 Oct 2015 19:17:08 -0400 Subject: [PATCH 024/155] Add note about NVM to the readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4baf0629..281f5b5a 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ The segments that are currently available are: * [ip](#ip) - Shows the current IP address. * **load** - Your machines 5 minute load average and free RAM. * **node_version** - Show the version number of the installed Node.js. +* **nvm** - Show the version of Node that is currently active, if it differs from the version used by NVM * **os_icon** - Display a nice little icon, depending on your operating system. * **php_version** - Show the current PHP version. * [rbenv](#rbenv) - Ruby environment information (if one is active). From 86b460f06bfb01f782026af806c2dc68f8925621 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 16 Oct 2015 20:16:31 +0200 Subject: [PATCH 025/155] vi_mode segement more customizable. --- README.md | 6 ++++++ powerlevel9k.zsh-theme | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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 } From b04fae917358882a0e0aabf387ed3eedf80b26e4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 16 Oct 2015 20:42:21 +0200 Subject: [PATCH 026/155] Made whitespaces between segment separators customizable. --- powerlevel9k.zsh-theme | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 } From ae035e537afe5435b05a45cb735d5d5d8e885e4b Mon Sep 17 00:00:00 2001 From: Parth Panchal Date: Sat, 17 Oct 2015 23:17:40 +0530 Subject: [PATCH 027/155] Fixes `VIRTUAL_ENV_DISABLE_PROMPT` condition --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From 5add0daad027fab254a7c2a322e636dd7dc982d2 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sat, 17 Oct 2015 11:30:55 -0700 Subject: [PATCH 028/155] added prompt segment for todo.txt task number --- README.md | 3 ++- powerlevel9k.zsh-theme | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 From 2a6be9dc40562d4c085593e42055ceda90ff6bcb Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sat, 17 Oct 2015 11:32:59 -0700 Subject: [PATCH 029/155] reverting unnoticed white space change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c5e6809..8252f6e5 100644 --- a/README.md +++ b/README.md @@ -128,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 From 95d8b62e656e6ccf8c2e6b42e9876c9bc4ba4bfd Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 17 Oct 2015 20:08:22 -0700 Subject: [PATCH 030/155] README: changing name of `todo.txt` segment to `todo` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8252f6e5..b8a2b628 100644 --- a/README.md +++ b/README.md @@ -85,7 +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. +* [todo](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). From ee8c59806edd8333608e223fd4b1ff38ecf81de9 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 17 Oct 2015 20:29:07 -0700 Subject: [PATCH 031/155] README: Updating the docs about `vi_mode` segment. --- README.md | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e5c506ae..220a6298 100644 --- a/README.md +++ b/README.md @@ -215,29 +215,17 @@ from the [Installation](#Installation) section above. ##### vi_mode -This Segment shows the current mode of your ZSH. If you want to use your ZSH in -VI-Mode, you need to configure it separately in your `~/.zshrc`: +This segment shows ZSH's current input mode. Note that this is only useful if +you are using the [ZSH Line Editor](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html) +(VI mode). You can enable this either by `.zshrc` configuration or using a plugin, like +[Oh-My-Zsh's vi-mode plugin](https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/vi-mode/vi-mode.plugin.zsh). - # VI-Mode - # general activation - bindkey -v +If you want to display a string other than "NORMAL" or "INSERT" in `command` and +`insert-mode`, you can do so by setting the following variables in your +`~/.zshrc`: - # set some nice hotkeys - bindkey '^P' up-history - bindkey '^N' down-history - bindkey '^?' backward-delete-char - bindkey '^h' backward-delete-char - bindkey '^w' backward-kill-word - bindkey '^r' history-incremental-search-backward - - # 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" + POWERLEVEL9K_VI_INSERT_MODE_STRING="INSERT" + POWERLEVEL9K_VI_COMMAND_MODE_STRING="NORMAL" #### Unit Test Ratios From 38bccd1340389a26b75e92878bf61d6753df4462 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 17 Oct 2015 21:45:00 -0700 Subject: [PATCH 032/155] README: Updating second image to use @natemccurdy awesome gif. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4baf0629..c445b62c 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ this theme focus on four primary goals: 4. Optimize the code for execution speed as much as possible. A snappy terminal is a happy terminal. -Here is a detailed screenshot showing `powerlevel9k` in action, with default settings. +Here is `powerlevel9k` in action, with [some simple settings](https://github.com/bhilburn/powerlevel9k/wiki/Show-Off-Your-Config#natemccurdys-configuration). -![](http://bhilburn.org/content/images/2014/12/powerlevel9k.png) +![](https://camo.githubusercontent.com/80ec23fda88d2f445906a3502690f22827336736/687474703a2f2f692e696d6775722e636f6d2f777942565a51792e676966) ### Table of Contents From 8e458e5e9acac0766f4319eb7494f033201978a9 Mon Sep 17 00:00:00 2001 From: Martin Pelikan Date: Sun, 18 Oct 2015 00:11:24 -0700 Subject: [PATCH 033/155] Fixes #122, SI prefixes should be evaluated as strings. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From acf5e97756a97c0feb12c38475266b0c079ca25f Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 10:55:37 -0700 Subject: [PATCH 034/155] added battery prompt segment usable on OS X systems --- README.md | 17 +++++++++++++++ powerlevel9k.zsh-theme | 47 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) 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 From 118008c402338b1693ee7db4120b0ff374e542c3 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 11:01:52 -0700 Subject: [PATCH 035/155] fixed output string color declaration --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From 2e406a5bdfcb33e72771f2290bd9d29e0eb7d497 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 11:05:37 -0700 Subject: [PATCH 036/155] editor automatically removed whitespace --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From fb6738967ea2e3202d4140c62962d5dd674be430 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 16:30:16 -0700 Subject: [PATCH 037/155] added Linux support to battery prompt segment --- README.md | 9 ++++---- powerlevel9k.zsh-theme | 52 +++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 20 deletions(-) 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 - - # display prompt_segment - [[ ! -z $bat_percent ]] && "$1_prompt_segment" "$0" "black" "$DEFAULT_COLOR" "$conn$(print_icon 'BATTERY_ICON')%F{$fg_color} $bat_percent%% $remain" fi + + 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) From 3b2971b344e668a57edd8f199dd9681fd0a2f734 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 16:32:20 -0700 Subject: [PATCH 038/155] erroneous whitespace commit undone --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb15d5ca..33b0fc85 100644 --- a/README.md +++ b/README.md @@ -147,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 From ff3f6b8e833946a8e98352ceb15e8eb5682e2b69 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 19:48:45 -0700 Subject: [PATCH 039/155] added time remaining support to battery segment on Linux --- README.md | 2 +- powerlevel9k.zsh-theme | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 From 3e828cbaa47227fde34624229018d90d4651a586 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sun, 18 Oct 2015 21:03:47 -0700 Subject: [PATCH 040/155] fixed some edge cases I ran into during usage of the linux segment --- powerlevel9k.zsh-theme | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 From 5addfdc9e08b3be1a2377b7f0c28f17ce8b8a4ab Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 19 Oct 2015 17:37:18 +0200 Subject: [PATCH 041/155] 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 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 From fa85a5158fa3d9ef84ecd3e94ab5deb805b735ab Mon Sep 17 00:00:00 2001 From: Daniel Gordon Date: Mon, 19 Oct 2015 13:02:24 -0500 Subject: [PATCH 042/155] 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(-) 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 From 09bd1f6182d38484e64b324b56c06039e8c67672 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 20 Oct 2015 00:37:17 +0200 Subject: [PATCH 043/155] Added documentation. --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a06b4857..dce45da7 100644 --- a/README.md +++ b/README.md @@ -75,11 +75,12 @@ The segments that are currently available are: * [dir](#dir) - Your current working directory. * **history** - The command number for the current line. * [ip](#ip) - Shows the current IP address. -* **load** - Your machines 5 minute load average and free RAM. +* **load** - Your machines 5 minute load average. * **node_version** - Show the version number of the installed Node.js. * **nvm** - Show the version of Node that is currently active, if it differs from the version used by NVM * **os_icon** - Display a nice little icon, depending on your operating system. * **php_version** - Show the current PHP version. +* [ram](#ram) - Show free RAM and used Swap. * [rbenv](#rbenv) - Ruby environment information (if one is active). * [rspec_stats](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. * [status](#status) - The return code of the previous command, and status of background jobs. @@ -154,6 +155,15 @@ following variable in your `~/.zshrc`. POWERLEVEL9K_STATUS_VERBOSE=false +##### ram + +By default this segment shows you free RAM and used Swap. If you want to show +only one value, you can specify `POWERLEVEL9K_RAM_ELEMENTS` and set it to either +`ram_free` or `swap_used`. Full example: + + # Show only used swap: + POWERLEVEL9K_RAM_ELEMENTS=(swap_used) + ##### symphony2_tests See [Unit Test Ratios](#unit-test-ratios), below. From fbd1b99babd5065b62b4b16a6e622dddc33838bc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 23 Oct 2015 23:39:50 +0200 Subject: [PATCH 044/155] Renamed "power-utilities.zsh" to just "utilities.zsh". --- functions/{power-utilities.zsh => utilities.zsh} | 0 powerlevel9k.zsh-theme | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename functions/{power-utilities.zsh => utilities.zsh} (100%) diff --git a/functions/power-utilities.zsh b/functions/utilities.zsh similarity index 100% rename from functions/power-utilities.zsh rename to functions/utilities.zsh 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 From d6584e13dac22ffa6318c9624aa76f60a3add7bf Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 23 Oct 2015 23:42:59 +0200 Subject: [PATCH 045/155] 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 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 From 2b8cb5b9a47c0e97a501a3e804dc7089619c1e9a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 24 Oct 2015 00:05:15 +0200 Subject: [PATCH 046/155] 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 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" From 0fa635275c99e66b14c972a8aa01cda7343035bf Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 24 Oct 2015 01:05:37 +0200 Subject: [PATCH 047/155] 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 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 ################################################################ From 29693f957d237df0109acf66544a93e6f4ee4c33 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 4 Nov 2015 00:40:11 +0100 Subject: [PATCH 048/155] 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(-) 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 From 3afbd5e9942f995e9f281a59e6ee146fff39ddde Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 4 Nov 2015 19:53:56 +0100 Subject: [PATCH 049/155] Added a CHANGELOG. --- CHANGELOG.md | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..733698cd --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,89 @@ +## v0.3.0 (next) + +### `virtualenv` changes + +This segment now respects `VIRTUAL_ENV_DISABLE_PROMPT`. If this variable is set +to `true`, the segments does not get rendered. + +### `load` changes + +The `load` segement was split and a new segment `ram` was extracted. This new +segment is able to show the free ram and used swap. + +### `vcs` changes + +This prompt uses the `VCS_INFO` subsystem by ZSH. From now on this subsystem +is only invoked if a `vcs` segment was configured. + +### New segment `battery` added + +A new segment that shows the battery status of your laptop was added. + +### New segment `go_version` added + +This segment shows the GO version. + +### New segment `nvm` added + +This segment shows your NodeJS version by using NVM (and if it is not 'default'). + +### New segment `todo` added + +This segment shows your ToDos from [todo.sh](http://todotxt.com/). + +## v0.2.0 + +### `longstatus` is now `status` + +The segments got merged together. To show the segment only if an error occurred, +set `POWERLEVEL9K_STATUS_VERBOSE=false` (this is the same behavior as the old +`status` segment. + +### Icon overriding mechanism added + +All icons can now be overridden by setting a variable named by the internal icon +name. You can get a full list of icon name by calling `get_icon_names`. + +### Same color segements get visual separator + +This separator can be controlled by setting `POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR` +or `POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR`. By default this separator is +printed in the foreground color. + +### `dir` segment has different strategies for truncation + +Now you can choose between `truncate_middle` or `truncate_from_right` by setting +`POWERLEVEL9K_SHORTEN_STRATEGY`. Default behavior is unchanged (truncate whole +directories). `POWERLEVEL9K_SHORTEN_DIR_LENGTH` can be used to influence how +much will be truncated (either direcories or chars). + +### New segment `ip` added + +This segment shows your internal IP address. You can define which interfaces IP +will be shown by specifying it via `POWERLEVEL9K_IP_INTERFACE`. + +### New segment `load` added + +This segment shows your computers 5min load average. + +### New segment `os_icon` added + +This segment shows a little indicator which OS you are running. + +### New segment `php_version` added + +This segment shows your PHP version. + +### New segment `vi_mode` added + +This segment gives you a hint in which VI-mode you currently are. This +segment requires a proper configured VI-mode. + +### Added the ability to have empty left or right prompts + +By setting the according variable to an empty array, the left or right +prompt will be empty. + +## v0.1.0 + +This is the first release From 538d8b8fa8b4fbfe4fdcab6e57867d1e6b434c5a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 7 Nov 2015 16:32:48 +0100 Subject: [PATCH 050/155] 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(-) 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)" From eef5286005422528cb2a941876ff35bbfe5c07da Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 11 Nov 2015 22:00:19 +0100 Subject: [PATCH 051/155] Issue #131: This fixes history-substring-search, home and end keys. --- powerlevel9k.zsh-theme | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 } From 81a4b3907de32b3dfb54fe6b626c1aa2b5faa13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Dupille?= Date: Fri, 13 Nov 2015 12:06:03 +0100 Subject: [PATCH 052/155] Get terminal capabilities using a zsh builtin for portability --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 643555a30c9576838157e04d45632080472e1b8b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 15 Nov 2015 23:35:15 +0100 Subject: [PATCH 053/155] 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(-) 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 } From 5d314bec8e6465feca3a757d4e8a9a626d322561 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 30 Sep 2015 20:12:47 +0200 Subject: [PATCH 054/155] Add segment for rust version. --- powerlevel9k.zsh-theme | 9 +++++++++ 1 file changed, 9 insertions(+) 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 From c81863e23429aeadb70a89764c489d0728fd59c3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 1 Oct 2015 17:35:11 +0200 Subject: [PATCH 055/155] Add an Identifier to version. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 37113bc120dc212ab8fd5cb300ad3d7b167527b9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 15 Nov 2015 23:53:10 +0100 Subject: [PATCH 056/155] Added documentation. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f811169e..4d225d14 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ The segments that are currently available are: * [ram](#ram) - Show free RAM and used Swap. * [rbenv](#rbenv) - Ruby environment information (if one is active). * [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. * [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. From ce7b99cdaf4459afb7d7043cae25e4f02489ba87 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 17 Nov 2015 01:39:49 +0100 Subject: [PATCH 057/155] Added a mechanism to make deprecated segments visible to the user. --- functions/utilities.zsh | 15 +++++++++++++++ powerlevel9k.zsh-theme | 8 ++++++++ 2 files changed, 23 insertions(+) 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 From 009b0e51a20ebcba7859cec1fdaecc695d20f005 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 17 Nov 2015 01:41:44 +0100 Subject: [PATCH 058/155] Added the new rust segment and the changes to the rvm-segment to changelog. --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 733698cd..933eceaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,12 @@ segment is able to show the free ram and used swap. This prompt uses the `VCS_INFO` subsystem by ZSH. From now on this subsystem is only invoked if a `vcs` segment was configured. +### `rvm` changes + +This segment now does not invoke RVM directly anymore. Instead, is relys on the +circumstance that RVM was invoked beforehand and just reads the environment +variables '$GEM_HOME' and '$MY_RUBY_HOME'. It also now displays the used gemset. + ### New segment `battery` added A new segment that shows the battery status of your laptop was added. @@ -31,6 +37,10 @@ This segment shows your NodeJS version by using NVM (and if it is not 'default') This segment shows your ToDos from [todo.sh](http://todotxt.com/). +### New segment `rust_version` added + +This segment shows your local rust version. + ## v0.2.0 ### `longstatus` is now `status` From f9957ca5592df0ab992d3750e18ee6f61b3e3002 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 17 Nov 2015 18:34:18 +0100 Subject: [PATCH 059/155] 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(-) 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 From 47eb8f10ac798cada32e91613bdcde8a44378a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=ADas=20P=C3=A1ll=20Gissurarson?= Date: Tue, 17 Nov 2015 20:06:49 +0100 Subject: [PATCH 060/155] added variable to have rprompt on the newline --- powerlevel9k.zsh-theme | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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='' From 231cfda8090d352ca378ea23967a19e2884d672e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=ADas=20P=C3=A1ll=20Gissurarson?= Date: Tue, 17 Nov 2015 21:18:31 +0100 Subject: [PATCH 061/155] 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(-) 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='' } From 36fa3f2277504c3092a2bcfa8725c7ea4cf11bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=ADas=20P=C3=A1ll=20Gissurarson?= Date: Wed, 18 Nov 2015 21:34:07 +0100 Subject: [PATCH 062/155] fix some issues with the battery segment --- powerlevel9k.zsh-theme | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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) From 0aaf99985754cc0759ca3b7e94bdee111d5a94f8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:04:58 +0100 Subject: [PATCH 063/155] 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(-) 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. From a0323b7e8075a8b59d671a48484117e5152bebf9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:26:50 +0100 Subject: [PATCH 064/155] 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(-) 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 From 727b3e501b9f534871ed3ec0d5d6dbca1344a5c5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:29:20 +0100 Subject: [PATCH 065/155] 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(-) 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)" From df51db14129bc8fb1fa90f9e8aa3ab653fbe247a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=ADas=20P=C3=A1ll=20Gissurarson?= Date: Wed, 18 Nov 2015 23:45:22 +0100 Subject: [PATCH 066/155] 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(-) 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 } From 351dc843204b983214e516142439383457926d84 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 23:20:38 +0100 Subject: [PATCH 067/155] Fix for the GO version. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 49a3a3e750fd20e7f01829209b1b5fbfbeeb4b41 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 22 Nov 2015 00:04:55 +0100 Subject: [PATCH 068/155] 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(-) 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 From 4b636d226ede68bdd621cd382182959491bf747a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 22 Nov 2015 00:08:43 +0100 Subject: [PATCH 069/155] Renamed variable. --- powerlevel9k.zsh-theme | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 From 7774294113603e8fd4e3c6f1c1c6fb5aeae6cdb2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:09:37 +0100 Subject: [PATCH 070/155] Performance improvement by calculating the battery percentage with zsh. --- powerlevel9k.zsh-theme | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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)" From c0efe9c342450b4d20488633a2e1bfd1e30ce7e0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:11:19 +0100 Subject: [PATCH 071/155] 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(-) 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 From b316089c6bca112c88f6030f4f5b70d4236f2dbc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:12:52 +0100 Subject: [PATCH 072/155] Make use of set_default method for better code readability. --- powerlevel9k.zsh-theme | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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" From 8d72b5eb123973f94e1188d697ca5e3e62d8269f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:42:15 +0100 Subject: [PATCH 073/155] Renamed variable "conn" to "icon_color" --- powerlevel9k.zsh-theme | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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) From 239aa29a1287d58ad61e6b9ff342fb7a7f2bf31e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 00:48:59 +0100 Subject: [PATCH 074/155] Better use of test flags. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) From da2b8e342efa952dea4b664fac6179d75804a2b9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 18:10:09 +0100 Subject: [PATCH 075/155] 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(-) 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 From dad38b0592141fc4243fb8c67659a3a499f6cc4c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Nov 2015 02:36:37 +0100 Subject: [PATCH 076/155] Better code structure. --- powerlevel9k.zsh-theme | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) 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" From c8137fcf1a8461fddb98ada19e03c40834287c21 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Nov 2015 18:17:04 +0100 Subject: [PATCH 077/155] 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(-) 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 From 3437c7850cda86e85626e95216644f1fa420ddaa Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Nov 2015 18:31:22 +0100 Subject: [PATCH 078/155] Battery icon is already defined in the icons-array. --- powerlevel9k.zsh-theme | 1 - 1 file changed, 1 deletion(-) 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" From 323610cebf133ba998e5e5c964d2d41a547ba4b6 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Nov 2015 18:36:56 +0100 Subject: [PATCH 079/155] 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(-) 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) From 23e2a5406718dfd9117de8b63825cf63ee195ff2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 25 Nov 2015 00:21:20 +0100 Subject: [PATCH 080/155] Added a verbose mode. --- powerlevel9k.zsh-theme | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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) From b8d7d1387e0a77ba4046db48c0fcad2c59773942 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 25 Nov 2015 00:26:10 +0100 Subject: [PATCH 081/155] By default: set verbose mode on. --- powerlevel9k.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) 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 From c10bac90ba55607fe19913d1e71571b83d8df6dc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 00:03:07 +0100 Subject: [PATCH 082/155] 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(-) 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 From 972e24ad4132694d3c366678eb942799d1cd09a1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:26:24 +0100 Subject: [PATCH 083/155] 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(-) 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 From 46575182c78d441eacf928fd368a4c20b1aaa0b5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:33:33 +0100 Subject: [PATCH 084/155] 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(+) 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 From b01588e2f96fdc0da8df8cef14895b1e22384da7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:56:26 +0100 Subject: [PATCH 085/155] File might be a symlink. --- powerlevel9k.zsh-theme | 5 +++++ 1 file changed, 5 insertions(+) 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 From a09a4b8dd52511507092c3daf11438b501bd8a1c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 10:57:50 +0100 Subject: [PATCH 086/155] Added a folder icon for "awesome-fontconfig" mode. Thx to @tritlo --- functions/icons.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index 0cd6bb9d..fcf08163 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -96,7 +96,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON $'\UF17C' #  SUNOS_ICON $'\UF185 ' #  HOME_ICON $'\UF015 ' #  - FOLDER_ICON '' + FOLDER_ICON $'\UF115 ' #  NETWORK_ICON $'\UF09E ' #  LOAD_ICON $'\UF080 ' #  RAM_ICON $'\UF0E4' #  From 0dc36ee6148d0db99e3b580a7767e4f7b8f77c87 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 11:11:10 +0100 Subject: [PATCH 087/155] 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(-) 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') From 8c71a28a77a3e2edebaaddd6245534f9f4514aaa Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 19:45:49 +0100 Subject: [PATCH 088/155] The script location should only be set once! --- powerlevel9k.zsh-theme | 2 -- 1 file changed, 2 deletions(-) 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 From 5a4de1d2742e6e19a1ffb7ea8c418a923599391e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 13 Dec 2015 12:41:49 +0100 Subject: [PATCH 089/155] 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(-) 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 From 71510361984568408f8dc87251c1a9e2abdddef2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:31:09 +0100 Subject: [PATCH 090/155] Removed unecessary variable. --- functions/icons.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index fcf08163..48396ff5 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -190,9 +190,8 @@ fi 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" + echo -n "${(P)ICON_USER_VARIABLE}" else echo -n "${icons[$icon_name]}" fi From 21f80e4da711dd4d1e81e1f58887519cfc7a038c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:32:45 +0100 Subject: [PATCH 091/155] Removed trailing whitespaces. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 036433dd538f55d2950d40b0ca3068016877314f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:41:02 +0100 Subject: [PATCH 092/155] Segments now can have "visual identifiers" which are basically just special icons. --- powerlevel9k.zsh-theme | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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 } From 0c528461fb1e5f38e1d4ee32c696a6955f5bfaa0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:55:24 +0100 Subject: [PATCH 093/155] Allow users to overwrite the color for the visual identifier only. --- powerlevel9k.zsh-theme | 8 ++++++++ 1 file changed, 8 insertions(+) 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 From 1194826ef4eb876edbf3cec427eca37eda976a02 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:55:55 +0100 Subject: [PATCH 094/155] Used the new "visual identifier" concept for the battery segment. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) From e505c0698e12a8769ced7e0f0bc42c3b7df3210e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:57:24 +0100 Subject: [PATCH 095/155] Added the "visual identifier" concept to the `aws` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From d5d5acb490e37d62db30a16fb434dce56c732c05 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:58:36 +0100 Subject: [PATCH 096/155] Added the "visual identifier" concept to the `dir` segment. --- powerlevel9k.zsh-theme | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 From bb5cca9af7d678d5a70ea529e75ba740c0caa6b4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 00:59:39 +0100 Subject: [PATCH 097/155] Added the "visual identifier" concept to the `ip` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() { From 35b1cb5b8d7b4132d9b1da50600265b040e94308 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:01:34 +0100 Subject: [PATCH 098/155] Added the "visual identifier" concept to the `load` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From fd0fcba5e9b14f27879c209ec056d23adc189026 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:02:55 +0100 Subject: [PATCH 099/155] Added the "visual identifier" concept to the `node_version` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From d514b077d09359860b9450da696e3377e5643740 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:05:42 +0100 Subject: [PATCH 100/155] Added the "visual identifier" concept to the `rvm` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From c5726bc548a4a8b82db480ec55ee04ceae31624e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:07:38 +0100 Subject: [PATCH 101/155] Added the "visual identifier" concept to the `todo` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From 6f7d6f7259d33233288dca3b5657c89550023389 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:21:15 +0100 Subject: [PATCH 102/155] 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(-) 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 } From 78d22ba309171889e79fa486b9f7aa882b4d8001 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 01:31:55 +0100 Subject: [PATCH 103/155] 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(-) 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 From 1d0f47fb976369ce56c294e278667aad5aa20335 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:20:11 +0100 Subject: [PATCH 104/155] 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(-) 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" From 46aafc797a21926734d5c40c56d68e55c8c845e3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:34:23 +0100 Subject: [PATCH 105/155] Some icons are visual identifiers now, so they shouldn't control the margin to the text (which is whitespace). --- functions/icons.zsh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index 48396ff5..4ba4811e 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -43,9 +43,9 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON $'\U1F608 ' # 😈 LINUX_ICON $'\UE271' #  SUNOS_ICON $'\U1F31E ' # 🌞 - HOME_ICON $'\UE12C ' #  - FOLDER_ICON $'\UE818 ' #  - NETWORK_ICON $'\UE1AD ' #  + HOME_ICON $'\UE12C' #  + FOLDER_ICON $'\UE818' #  + NETWORK_ICON $'\UE1AD' #  LOAD_ICON $'\UE190 ' #  #RAM_ICON $'\UE87D' #  RAM_ICON $'\UE1E2 ' #  @@ -95,9 +95,9 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON $'\U1F608 ' # 😈 LINUX_ICON $'\UF17C' #  SUNOS_ICON $'\UF185 ' #  - HOME_ICON $'\UF015 ' #  - FOLDER_ICON $'\UF115 ' #  - NETWORK_ICON $'\UF09E ' #  + HOME_ICON $'\UF015' #  + FOLDER_ICON $'\UF115' #  + NETWORK_ICON $'\UF09E' #  LOAD_ICON $'\UF080 ' #  RAM_ICON $'\UF0E4' #  VCS_UNTRACKED_ICON $'\UF059' #  From 4fc59fd57c508ff47871a5efadb4b987b1864702 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:36:02 +0100 Subject: [PATCH 106/155] Added the "visual identifier" concept to the `node_version` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 409303f45db59aa31cf3df2427d2f6b43d5349e9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:36:57 +0100 Subject: [PATCH 107/155] Added the "visual identifier" concept to the `rbenv` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From 056d4ff29ac1dbacc6be0d3b99160a493e47ab1c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 02:43:42 +0100 Subject: [PATCH 108/155] 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(-) 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" From cd5b4d0debac05a74131f06efa918172586865ec Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 15 Dec 2015 03:21:24 +0100 Subject: [PATCH 109/155] Added the "state" concept to the `dir` segment. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 } From ad2e4f0bcc6215afd1b598fcf75e4ab44eb4baca Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 16 Dec 2015 19:26:27 +0100 Subject: [PATCH 110/155] 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 | 192 ++++++++++++++++++++++++----------------- 2 files changed, 119 insertions(+), 79 deletions(-) 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" + [[ -n "$3" ]] && bg="%K{$3}" || bg="%k" + [[ -n "$4" ]] && fg="%F{$4}" || 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" + 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 } From 33d20cb7f24c7af0158152664fd3c73332c78669 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 16 Dec 2015 20:19:50 +0100 Subject: [PATCH 111/155] Added changelog. --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c21ea0e..a13ec3ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## v0.3.0 (next) +### Introduced "visual identifiers" to the segments + +Now almost every segment can have a visual identifier, which is an +icon whose color could be adjusted by users. + ### New segment `custom_command` added A new segment that allows users to define a custom command was added. From ffa9336144870a65c9272cb14a1c9e279077ada2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 16 Dec 2015 20:20:16 +0100 Subject: [PATCH 112/155] Remove trailing whitespaces from CHANGELOG. --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a13ec3ee..a461d2d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ 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 +This segment now respects `VIRTUAL_ENV_DISABLE_PROMPT`. If this variable is set to `true`, the segments does not get rendered. ### `load` changes @@ -22,7 +22,7 @@ segment is able to show the free ram and used swap. ### `vcs` changes This prompt uses the `VCS_INFO` subsystem by ZSH. From now on this subsystem -is only invoked if a `vcs` segment was configured. +is only invoked if a `vcs` segment was configured. ### `rvm` changes From bd5955221ed2b200853fe8da1aa2ba3b0dc4c5f3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 16 Dec 2015 22:23:47 +0100 Subject: [PATCH 113/155] Removed trailing whitespace. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a690bfd..cba6a73a 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,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 From f73de77c2e51d6efe441cea4b8b32445a66b751e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 10:40:15 +0100 Subject: [PATCH 114/155] Typo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 08728697..a68a3152 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. -* **background_jobs** - INdicator for background jobs. +* **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. From 0cb1c0ffdaf4fe84fa469d827aa4bae67dd89c08 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 10:48:11 +0100 Subject: [PATCH 115/155] Changed the order of default segments. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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]}" From 7ed0abebd690e4cf111582523f0279bbad6102bb Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 10:51:52 +0100 Subject: [PATCH 116/155] Little VCS segment cleanup. --- powerlevel9k.zsh-theme | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 } From b738ba900c5cc4cf5fd116e775062172c72466df Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 18:17:06 +0100 Subject: [PATCH 117/155] Added the "visual identifiers" concept to the `ram` segment. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 045f451e4e8bffc4a684bd5abf156193988e1220 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 18:22:34 +0100 Subject: [PATCH 118/155] Added the "visual identifier" concept to the `symfony2_tests` and `rspec_stats` segments. --- powerlevel9k.zsh-theme | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 From 5cfd800585516ce2251cd4f4cf8f2e1dbadddc70 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 17 Dec 2015 18:24:35 +0100 Subject: [PATCH 119/155] Added the "visual identifier" concept to the `symfony2_version` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From ac4502ca1fafab54c07d22e4841d8c6c7aeffc95 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 18 Dec 2015 00:47:37 +0100 Subject: [PATCH 120/155] 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(-) 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 } From e9ef0429e4dedd7e6f399bfdeedec764d2431a77 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 29 Dec 2015 13:46:07 +0100 Subject: [PATCH 121/155] 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(-) 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 } From 2fdbd6158c78a0b1786d6a030629fe3a930fc46d Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Wed, 30 Dec 2015 15:49:23 +0100 Subject: [PATCH 122/155] added fishe-like shortening strategy --- powerlevel9k.zsh-theme | 3 +++ 1 file changed, 3 insertions(+) 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" ;; From f472ba7341615f17b279cc6859535e6e7668f637 Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Thu, 31 Dec 2015 15:57:56 +0100 Subject: [PATCH 123/155] added a new variable POWERLEVEL9K_SHORTEN_DELIMITER to specifiy the delimiter --- powerlevel9k.zsh-theme | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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 From 3441f750bf114bc68e519d9ab351373b54e83d7c Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Thu, 31 Dec 2015 19:04:26 +0100 Subject: [PATCH 124/155] used set_default-function instead --- powerlevel9k.zsh-theme | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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) From a7bedd5320f0d6fba5d4179aace5ead1f42c459d Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Mon, 4 Jan 2016 19:00:02 +0100 Subject: [PATCH 125/155] added documentation --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index c611c5d9..e92f29ae 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,20 @@ To change the way how the current working directory is truncated, just set: POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" # default behaviour is to truncate whole directories +You can also change the delimiter (the dots in between) which is used to truncate the working directory. This setting is optional. The default are 2 dots. + + # set the delimiter to an empty string to hide it + POWERLEVEL9K_SHORTEN_DELIMITER="" + # or set it to anything else you want (e.g. 3 dots) + POWERLEVEL9K_SHORTEN_DELIMITER="..." + +With this you could achive the truncate behaviour of the fish shell. Which turncates `/usr/share/plasma` to `/u/s/plasma` + + POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 + POWERLEVEL9K_SHORTEN_DELIMITER="" + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" + + 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 others whole directories. From e7e11d5ec87f30323d065100c1e8fdb4a98c3aba Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Mon, 4 Jan 2016 19:26:25 +0100 Subject: [PATCH 126/155] fixed documentation --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e92f29ae..a6b69bff 100644 --- a/README.md +++ b/README.md @@ -207,17 +207,16 @@ To change the way how the current working directory is truncated, just set: You can also change the delimiter (the dots in between) which is used to truncate the working directory. This setting is optional. The default are 2 dots. - # set the delimiter to an empty string to hide it + # set the delimiter to an empty string to hide it POWERLEVEL9K_SHORTEN_DELIMITER="" # or set it to anything else you want (e.g. 3 dots) POWERLEVEL9K_SHORTEN_DELIMITER="..." With this you could achive the truncate behaviour of the fish shell. Which turncates `/usr/share/plasma` to `/u/s/plasma` - POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 - POWERLEVEL9K_SHORTEN_DELIMITER="" - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" - + POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 + POWERLEVEL9K_SHORTEN_DELIMITER="" + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" 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 From 8dfca40eafa1bdb5e260dc029c285e24f01e619c Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Tue, 5 Jan 2016 13:56:07 -0800 Subject: [PATCH 127/155] Cleaning up comments. Also fixes #135. --- powerlevel9k.zsh-theme | 76 ++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 37 deletions(-) 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. From bb7fca653b522708eb2bb68e18f1e1d5e68d242f Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Tue, 5 Jan 2016 15:18:46 -0800 Subject: [PATCH 128/155] README: Cleaning some things up. --- README.md | 54 +++++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index a6b69bff..e39722b2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ ZSH, [Oh-My-Zsh](https://github.com/robbyrussell/oh-my-zsh), or [Prezto](https://github.com/sorin-ionescu/prezto), and can also be installed using [antigen](https://github.com/zsh-users/antigen). -Look like a bad-ass. Impress everyone in 'Screenshot Your Desktop' threads. Use powerlevel9k. +Be a badass. Get more out of your terminal. Impress everyone in 'Screenshot Your +Desktop' threads. Use powerlevel9k. ![](http://bhilburn.org/content/images/2015/01/pl9k-improved.png) @@ -126,7 +127,10 @@ 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) +The `custom_...` segment allows you to turn the output of a custom command into +a prompt segment. As an example, if you wanted to create a custom segment to +display your WiFi signal strength, you might define a custom segment called +`custom_signal` like this: 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}')" @@ -134,11 +138,8 @@ The `custom_...` segment lets you add a custom command to your prompt, to e.g. d 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: +Instead of writing out the command in-line within the environment variable, you +can also add it as a function in your `.zshrc`: zsh_signal(){ local signal=$(nmcli device wifi | grep yes | awk '{print $8}') @@ -148,41 +149,23 @@ Instead of defining the command inline (if it is kinda long or unreadable), one 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: +You would then invoke the function in your custom segment: POWERLEVEL9K_CUSTOM_SIGNAL="zsh_signal" -Then this updated command looks like: +The command, above, gives you the wireless signal segment shown below: ![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) +You can define as many custom segments as you wish. If you think you have +a segment that others would find useful, please consider upstreaming it to the +main theme distribution so that everyone can use it! ##### context -The `context` segment (user@host string) is conditional. This lets you enable it, but only display -it if you are not your normal user or on a remote host (basically, only print it -when it's likely you need it). +The `context` segment (user@host string) is conditional. This lets you enable +it, but only display it if you are not your normal user or on a remote host +(basically, only print it when it's likely you need it). To use this feature, make sure the `context` segment is enabled in your prompt elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`: @@ -205,14 +188,15 @@ To change the way how the current working directory is truncated, just set: POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" # default behaviour is to truncate whole directories -You can also change the delimiter (the dots in between) which is used to truncate the working directory. This setting is optional. The default are 2 dots. +You can also change the delimiter (the dots in between text) from 2 dots to something custom: # set the delimiter to an empty string to hide it POWERLEVEL9K_SHORTEN_DELIMITER="" # or set it to anything else you want (e.g. 3 dots) POWERLEVEL9K_SHORTEN_DELIMITER="..." -With this you could achive the truncate behaviour of the fish shell. Which turncates `/usr/share/plasma` to `/u/s/plasma` +For example, if you wanted the truncation behavior of the `fish` shell, which +truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 POWERLEVEL9K_SHORTEN_DELIMITER="" From 1ec2919ff5aa366695ace6ed00646c452b9b83b3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 6 Jan 2016 19:09:05 +0100 Subject: [PATCH 129/155] Added an explanation for the "home" and "folder" icons. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index e39722b2..c402afad 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,16 @@ 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 others whole directories. +You can even show icons if your are within your homefolder or outside of it +by setting: + + # Greek "alpha" sign + POWERLEVEL9K_HOME_ICON='\u03B1' + # Greek capital "omega" sign + POWERLEVEL9K_FOLDER_ICON='\u03A9' + +To turn off these icons you could set these variables to an empty string. + ##### ip This segment shows you your current internal IP address. It tries to examine From bbaa4a57f9f991552f1e528ae72cf9cae3900ecc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 7 Jan 2016 22:09:11 +0100 Subject: [PATCH 130/155] 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(-) 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 } From b9cb32f4a7cacc16fb0ab039a5fa91f6dd4b8d9d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 7 Jan 2016 22:17:21 +0100 Subject: [PATCH 131/155] Removed whitespace before git tag. --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 49dccc18..4a0a7ead 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -52,7 +52,7 @@ 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" + [[ -n "${tag}" ]] && hook_com[branch]="%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_TAG_ICON')${tag}%f" } # Show count of stashed changes From c8ce2264982018a9f576d416c997424b5c330c71 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 7 Jan 2016 22:49:18 +0100 Subject: [PATCH 132/155] Clearer explanation for the home and folder icons. --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c402afad..9a5f7b12 100644 --- a/README.md +++ b/README.md @@ -206,16 +206,17 @@ 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 others whole directories. -You can even show icons if your are within your homefolder or outside of it -by setting: - # Greek "alpha" sign - POWERLEVEL9K_HOME_ICON='\u03B1' - # Greek capital "omega" sign - POWERLEVEL9K_FOLDER_ICON='\u03A9' +| `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 | ![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_FOLDER_ICON='' + ##### ip This segment shows you your current internal IP address. It tries to examine From 63c2bc6541a51058b8ce728c3f4d0ef30632aa07 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 8 Jan 2016 20:24:40 +0100 Subject: [PATCH 133/155] Added changelog entries. --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65a04de0..abf3f770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,31 @@ 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). +### `dir` changes + +This segment now has "state", which means you now can change the colors seperatly +depending if you are in your homefolder or not. +Your variables for that should now look like: +```zsh +POWERLEVEL9K_DIR_HOME_BACKGROUND='green' +POWERLEVEL9K_DIR_HOME_FOREGROUND='cyan' +POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red' +POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='yellow' +``` + ### `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. +The `status` segment also now has "state". If you want to overwrite the colors, +you have to add the state to your variables: +```zsh +POWERLEVEL9K_STATUS_ERROR_BACKGROUND='green' +POWERLEVEL9K_STATUS_ERROR_FOREGROUND='cyan' +POWERLEVEL9K_STATUS_OK_BACKGROUND='red' +POWERLEVEL9K_STATUS_OK_FOREGROUND='yellow' +``` ### New segment `custom_command` added From f2b48d4f323f58f522355cd67777f3bc16ee826e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 8 Jan 2016 20:32:14 +0100 Subject: [PATCH 134/155] Removed the "next"-tag. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abf3f770..8cfaa1d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## v0.3.0 (next) +## v0.3.0 ### Introduced "visual identifiers" to the segments From d0a76d721cf948eea72e2d452909f346af250c3d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 8 Jan 2016 20:34:45 +0100 Subject: [PATCH 135/155] Sorted segments alphabetically. --- powerlevel9k.zsh-theme | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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='%~' From cdf08734dbd46ad110dbefc4ffe5ff5d5b948938 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 8 Jan 2016 20:42:06 +0100 Subject: [PATCH 136/155] Cleanup of the `load` segment. --- powerlevel9k.zsh-theme | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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 From 0b27bdc6f556fc854abb3ac4e1f2e03c6828762c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 8 Jan 2016 20:44:35 +0100 Subject: [PATCH 137/155] Comment cleanup. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 989a9b3b4b6cf1c254388f5e350a709a01097979 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 9 Jan 2016 16:25:15 +0100 Subject: [PATCH 138/155] Improved symlink dereferencing on OSX by calling a perl script. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 31c78b5e47eb2f2343171635b384bb7f93d4c90e Mon Sep 17 00:00:00 2001 From: MrTuxHdb Date: Wed, 13 Jan 2016 00:51:51 +0700 Subject: [PATCH 139/155] [FIX] RUBY_ICON should be $'\UF219' --- functions/icons.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index b8e02efd..a0171e69 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -79,7 +79,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  CARRIAGE_RETURN_ICON $'\U21B5' # ↵ ROOT_ICON $'\uF201' #  - RUBY_ICON $'\UF247' #  + RUBY_ICON $'\UF219' #  AWS_ICON $'\UF296' #  BACKGROUND_JOBS_ICON $'\UF013 ' #  TEST_ICON $'\UF291' #  From 9aeff8d43bd8ad95d913b21e68a5aa64036eda45 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Thu, 14 Jan 2016 11:05:26 -0700 Subject: [PATCH 140/155] added check for nvm command before running --- powerlevel9k.zsh-theme | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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' } From e29b3545bd4dc22f874347df9eb296e62105b94e Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Thu, 14 Jan 2016 11:07:11 -0700 Subject: [PATCH 141/155] fixed called to ioreg on OS X machines --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From a97fa07cc5851116e633bdb38b632bde4e51818f Mon Sep 17 00:00:00 2001 From: MrTuxHdb Date: Wed, 13 Jan 2016 00:51:51 +0700 Subject: [PATCH 142/155] [FIX] RUBY_ICON should be $'\UF219' --- functions/icons.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index b8e02efd..a0171e69 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -79,7 +79,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  CARRIAGE_RETURN_ICON $'\U21B5' # ↵ ROOT_ICON $'\uF201' #  - RUBY_ICON $'\UF247' #  + RUBY_ICON $'\UF219' #  AWS_ICON $'\UF296' #  BACKGROUND_JOBS_ICON $'\UF013 ' #  TEST_ICON $'\UF291' #  From 2fa7b1d08f55e71397f13f4e943491426b0e98c0 Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 14:09:39 -0700 Subject: [PATCH 143/155] don't output segment if node_version was not populated --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 446f46473b2620bbe416488b68dd099be27f695a Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 16:16:27 -0700 Subject: [PATCH 144/155] 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(-) 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 From 6f2f78b21fe597ad55e5f87360b68b4a812a7d19 Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 16:19:12 -0700 Subject: [PATCH 145/155] fixed conditional statement --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From cf921fb90c8d239f57391cf6ae459c3d6b6420bf Mon Sep 17 00:00:00 2001 From: Kayant Date: Fri, 15 Jan 2016 23:12:38 +0000 Subject: [PATCH 146/155] 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(-) 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 From 37673977119273753c152a1472726c4d608f2b2c Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Fri, 15 Jan 2016 21:52:08 -0700 Subject: [PATCH 147/155] fixing segment call for new state implementation in prompt_load --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 701053aa73cbcfd39d890e7cdb1219c19e2af9ce Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 17 Jan 2016 01:01:39 +0100 Subject: [PATCH 148/155] Improved dir icon descriptions. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 520ee440..7e250bf7 100644 --- a/README.md +++ b/README.md @@ -209,9 +209,9 @@ 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 | +| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183451/40ec4016-b58f-11e5-9b9e-74e2b2f0b8b3.png) | At the root of your home folder | +| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12369315/8a5d762c-bbf5-11e5-8a20-ca1179f48d6c.png) | Within a subfolder of your home directory | +| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183452/40f79286-b58f-11e5-9b8c-ed1343a07b08.png) | Outside of your home folder | To turn off these icons you could set these variables to an empty string. From 01e4e8d324804e8048342a92a48ea1e40977d488 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 17 Jan 2016 01:02:03 +0100 Subject: [PATCH 149/155] Added "visual identifier" concept to `icons_test` segment. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From f1486620e742e8e8ff843cb65eea42d320752c0e Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Sat, 16 Jan 2016 18:03:31 -0700 Subject: [PATCH 150/155] added space to end of RVM icon --- functions/icons.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index 6a9b044c..aad62dc1 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -27,7 +27,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  CARRIAGE_RETURN_ICON $'\U21B5' # ↵ ROOT_ICON $'\UE801' #  - RUBY_ICON $'\UE847' #  + RUBY_ICON $'\UE847 ' #  AWS_ICON $'\UE895' #  BACKGROUND_JOBS_ICON $'\UE82F ' #  TEST_ICON $'\UE891' #  @@ -80,7 +80,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\UE0B3' #  CARRIAGE_RETURN_ICON $'\U21B5' # ↵ ROOT_ICON $'\uF201' #  - RUBY_ICON $'\UF219' #  + RUBY_ICON $'\UF219 ' #  AWS_ICON $'\UF296' #  BACKGROUND_JOBS_ICON $'\UF013 ' #  TEST_ICON $'\UF291' #  From 8a3c16ae244adb3e0acc10ed1fe9e91b68833949 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 16 Jan 2016 19:56:27 -0800 Subject: [PATCH 151/155] README: Trying out tables to describe variables. --- README.md | 196 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 101 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 7e250bf7..cc7becb4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ZSH, [Oh-My-Zsh](https://github.com/robbyrussell/oh-my-zsh), or [Prezto](https://github.com/sorin-ionescu/prezto), and can also be installed using [antigen](https://github.com/zsh-users/antigen). -Be a badass. Get more out of your terminal. Impress everyone in 'Screenshot Your +Get more out of your terminal. Be a badass. Impress everyone in 'Screenshot Your Desktop' threads. Use powerlevel9k. ![](http://bhilburn.org/content/images/2015/01/pl9k-improved.png) @@ -62,8 +62,16 @@ options, including color and icon settings: [Stylizing Your Prompt](https://gith #### Customizing Prompt Segments Customizing your prompt is easy! Select the segments you want to have displayed, and then assign them to either the left or right prompt by adding the following -variables to your `~/.zshrc`. If you don't customize this, the below -configuration is the default: +variables to your `~/.zshrc`. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_LEFT_PROMPT_ELEMENTS`|`(context dir rbenv vcs)`|Segment list for left prompt| +|`POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS`|`(status history time)`|Segment list for right prompt| + + +So if you wanted to set these variables manually, you would put the following in +your `~/.zshrc`: POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) @@ -107,41 +115,46 @@ profile](http://docs.aws.amazon.com/cli/latest/userguide/installing.html), add the `aws` segment to one of the prompts, and define `AWS_DEFAULT_PROFILE` in your `~/.zshrc`: - export AWS_DEFAULT_PROFILE= +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`AWS_DEFAULT_PROFILE`|None|Your AWS profile name| ##### battery -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. +This segment will display your current battery status (fails gracefully on +systems without a battery). It is supported on both OSX and Linux (note that it +requires `acpi` on Linux). - POWERLEVEL9K_BATTERY_CHARGING="yellow" - POWERLEVEL9K_BATTERY_CHARGED="green" - POWERLEVEL9K_BATTERY_DISCONNECTED=$DEFAULT_COLOR - POWERLEVEL9K_BATTERY_LOW_THRESHOLD=10 - POWERLEVEL9K_BATTERY_LOW_COLOR="red" +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_BATTERY_CHARGING`|`"yellow"`|Color to indicate a charging battery.| +|`POWERLEVEL9K_BATTERY_CHARGED`|`"green"`|Color to indicate a charged battery.| +|`POWERLEVEL9K_BATTERY_DISCONNECTED`|`$DEFAULT_COLOR`|Color to indicate absence of battery.| +|`POWERLEVEL9K_BATTERY_LOW_THRESHOLD`|`10`|Threshold to consider battery level critical.| +|`POWERLEVEL9K_BATTERY_LOW_COLOR`|`"red"`|Color to indicate critically low charge level.| -In addition to the above it supports standard _FOREGROUND value without affecting the icon color - -Supports both OS X and Linux(time remaining requires the acpi program on Linux) +Note that you can [modify the `_FOREGROUND` +color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization) +without affecting the icon color. ##### custom_command The `custom_...` segment allows you to turn the output of a custom command into a prompt segment. As an example, if you wanted to create a custom segment to display your WiFi signal strength, you might define a custom segment called -`custom_signal` like this: +`custom_wifi_signal` like this: - 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) + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) + POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="echo signal: \$(nmcli device wifi | grep yes | awk '{print \$8}')" + POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_BACKGROUND="blue" + POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_FOREGROUND="yellow" -Instead of writing out the command in-line within the environment variable, you -can also add it as a function in your `.zshrc`: +If you prefer, you can also define the function in your `.zshrc` rather than +putting it in-line with the variable export, as shown above. Just don't forget +to invoke your function from your segment! Example code that achieves the same +result as the above: - zsh_signal(){ + zsh_wifi_signal(){ local signal=$(nmcli device wifi | grep yes | awk '{print $8}') local color='%F{yellow}' [[ $signal -gt 75 ]] && color='%F{green}' @@ -149,9 +162,8 @@ can also add it as a function in your `.zshrc`: echo -n "%{$color%}\uf230 $signal%{%f%}" # \uf230 is  } -You would then invoke the function in your custom segment: - - POWERLEVEL9K_CUSTOM_SIGNAL="zsh_signal" + POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="zsh_wifi_signal" + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) The command, above, gives you the wireless signal segment shown below: @@ -170,42 +182,14 @@ it, but only display it if you are not your normal user or on a remote host To use this feature, make sure the `context` segment is enabled in your prompt elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`: - export DEFAULT_USER= +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`DEFAULT_USER`|None|Username to consider a "default context" (you can also use `$USER`)| ##### dir -The `dir` segment shows the current working directory. You can limit the output -to a certain length: - - # Limit to the last two folders - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - -To change the way how the current working directory is truncated, just set: - - # truncate the middle part - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_middle" - # truncate from right, leaving the first X characters untouched - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" - # default behaviour is to truncate whole directories - -You can also change the delimiter (the dots in between text) from 2 dots to something custom: - - # set the delimiter to an empty string to hide it - POWERLEVEL9K_SHORTEN_DELIMITER="" - # or set it to anything else you want (e.g. 3 dots) - POWERLEVEL9K_SHORTEN_DELIMITER="..." - -For example, if you wanted the truncation behavior of the `fish` shell, which -truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: - - POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 - POWERLEVEL9K_SHORTEN_DELIMITER="" - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" - -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 -others whole directories. - +The `dir` segment shows the current working directory. When using the "Awesome +Powerline" fonts, there are additional glyphs, as well: | `Compatible` | `Powerline` | `Awesome Powerline` | Situation |------------|-----------|-------------------|---------------------------- @@ -219,6 +203,35 @@ To turn off these icons you could set these variables to an empty string. POWERLEVEL9K_HOME_SUB_ICON='' POWERLEVEL9K_FOLDER_ICON='' +You can limit the output to a certain length by truncating long paths. +Customizations available are: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_SHORTEN_DIR_LENGTH`|`2`|If your shorten strategy, below, is +entire directories, this field determines how many directories to leave at the +end. If your shorten strategy is by character count, this field determines how +many characters to allow per directory string.| +|`POWERLEVEL9K_SHORTEN_STRATEGY`|None|How the directory strings should be +truncated. By default, it will truncate whole directories. Other options are +`truncate_middle`, which leaves the start and end of the directory strings, and +`truncate_from_right`, which cuts starting from the end of the string.| +|`POWERLEVEL9K_SHORTEN_DELIMITER`|`..`|Delimiter to replace strings with +indicating truncation. This can be any string you choose, including an empty +string if you wish to have no delimiter.| + +For example, if you wanted the truncation behavior of the `fish` shell, which +truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: + + POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 + POWERLEVEL9K_SHORTEN_DELIMITER="" + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" + +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 +others whole directories. + + ##### ip This segment shows you your current internal IP address. It tries to examine @@ -226,7 +239,9 @@ all currently used network interfaces and prints the first address it finds. In the case that this is not the right IP address you can specify the correct network interface by setting: - POWERLEVEL9K_IP_INTERFACE="eth0" +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_IP_INTERFACE`|None|The NIC for which you wish to display the IP address. Example: `eth0`.| ##### rspec_stats @@ -234,20 +249,19 @@ See [Unit Test Ratios](#unit-test-ratios), below. ##### status -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`. +This segment shows the return code of the last command. - POWERLEVEL9K_STATUS_VERBOSE=false +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to hide this +segment when the last command completed successfully.| ##### ram -By default this segment shows you free RAM and used Swap. If you want to show -only one value, you can specify `POWERLEVEL9K_RAM_ELEMENTS` and set it to either -`ram_free` or `swap_used`. Full example: - - # Show only used swap: - POWERLEVEL9K_RAM_ELEMENTS=(swap_used) +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_RAM_ELEMENTS`|Both|Specify `ram_free` or `swap_used` to only show +one or the other rather than both.| ##### symphony2_tests @@ -255,9 +269,11 @@ See [Unit Test Ratios](#unit-test-ratios), below. ##### time -By default the time is show in 'H:M:S' format. If you want to change it, -just set another format in your `~/.zshrc`. As an example, this is a reversed -time format: +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_TIME_FORMAT`|`'H:M:S'`|ZSH time format to use in this segment.| + +As an example, if you wanted a reversed time format, you would use this: # Reversed time format POWERLEVEL9K_TIME_FORMAT='%D{%S:%M:%H}' @@ -270,22 +286,14 @@ segment, as well: ##### vcs -By default, the `vcs` segment will provide quite a bit of information. If you -would also like for it to display the current hash / changeset, simply define -`POWERLEVEL9K_SHOW_CHANGESET` in your `~/.zshrc`. If activated, it will show -the first 12 characters of the changeset id. To change the amount of characters, -set `POWERLEVEL9K_CHANGESET_HASH_LENGTH` to any value you want. +By default, the `vcs` segment will provide quite a bit of information. Further +customization is provided via: - # enable the vcs segment in general - POWERLEVEL9K_SHOW_CHANGESET=true - # just show the 6 first characters of changeset - POWERLEVEL9K_CHANGESET_HASH_LENGTH=6 - -You can also disable the branch icon in your prompt by setting -`POWERLEVEL9K_HIDE_BRANCH_ICON` to `true`: - - # Hide the branch icon - POWERLEVEL9K_HIDE_BRANCH_ICON=true +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_HIDE_BRANCH_ICON`|`false`|Set to `true` to hide the branch icon from the segment.| +|`POWERLEVEL9K_SHOW_CHANGESET`|`false`|Set to `true` to display the hash / changeset in the segment.| +|`POWERLEVEL9K_CHANGESET_HASH_LENGTH`|`12`|How many characters of the hash / changeset to display in the segment.| **vcs Symbols** @@ -315,12 +323,10 @@ you are using the [ZSH Line Editor](http://zsh.sourceforge.net/Doc/Release/Zsh-L (VI mode). You can enable this either by `.zshrc` configuration or using a plugin, like [Oh-My-Zsh's vi-mode plugin](https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/vi-mode/vi-mode.plugin.zsh). -If you want to display a string other than "NORMAL" or "INSERT" in `command` and -`insert-mode`, you can do so by setting the following variables in your -`~/.zshrc`: - - POWERLEVEL9K_VI_INSERT_MODE_STRING="INSERT" - POWERLEVEL9K_VI_COMMAND_MODE_STRING="NORMAL" +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_VI_INSERT_MODE_STRING`|`"INSERT"`|String to display while in 'Insert' mode.| +|`POWERLEVEL9K_VI_COMMAND_MODE_STRING`|`"NORMAL"`|String to display while in 'Command' mode.| #### Unit Test Ratios From 02cb0fd88fa0a06bc3e20b3649c74074ce205556 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 16 Jan 2016 19:59:39 -0800 Subject: [PATCH 152/155] README: Turns out you can't linebreak in tables. --- README.md | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cc7becb4..057f2fad 100644 --- a/README.md +++ b/README.md @@ -208,17 +208,9 @@ Customizations available are: | Variable | Default Value | Description | |----------|---------------|-------------| -|`POWERLEVEL9K_SHORTEN_DIR_LENGTH`|`2`|If your shorten strategy, below, is -entire directories, this field determines how many directories to leave at the -end. If your shorten strategy is by character count, this field determines how -many characters to allow per directory string.| -|`POWERLEVEL9K_SHORTEN_STRATEGY`|None|How the directory strings should be -truncated. By default, it will truncate whole directories. Other options are -`truncate_middle`, which leaves the start and end of the directory strings, and -`truncate_from_right`, which cuts starting from the end of the string.| -|`POWERLEVEL9K_SHORTEN_DELIMITER`|`..`|Delimiter to replace strings with -indicating truncation. This can be any string you choose, including an empty -string if you wish to have no delimiter.| +|`POWERLEVEL9K_SHORTEN_DIR_LENGTH`|`2`|If your shorten strategy, below, is entire directories, this field determines how many directories to leave at the end. If your shorten strategy is by character count, this field determines how many characters to allow per directory string.| +|`POWERLEVEL9K_SHORTEN_STRATEGY`|None|How the directory strings should be truncated. By default, it will truncate whole directories. Other options are `truncate_middle`, which leaves the start and end of the directory strings, and `truncate_from_right`, which cuts starting from the end of the string.| +|`POWERLEVEL9K_SHORTEN_DELIMITER`|`..`|Delimiter to replace strings with indicating truncation. This can be any string you choose, including an empty string if you wish to have no delimiter.| For example, if you wanted the truncation behavior of the `fish` shell, which truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: @@ -253,15 +245,13 @@ This segment shows the return code of the last command. | Variable | Default Value | Description | |----------|---------------|-------------| -|`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to hide this -segment when the last command completed successfully.| +|`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to hide this segment when the last command completed successfully.| ##### ram | Variable | Default Value | Description | |----------|---------------|-------------| -|`POWERLEVEL9K_RAM_ELEMENTS`|Both|Specify `ram_free` or `swap_used` to only show -one or the other rather than both.| +|`POWERLEVEL9K_RAM_ELEMENTS`|Both|Specify `ram_free` or `swap_used` to only show one or the other rather than both.| ##### symphony2_tests From dc4871f1a0b4efd628f2d44089bf0fdf35fa60c4 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 16 Jan 2016 20:02:10 -0800 Subject: [PATCH 153/155] README: Minor cleanups --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 057f2fad..1f2a7669 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ Customizations available are: |----------|---------------|-------------| |`POWERLEVEL9K_SHORTEN_DIR_LENGTH`|`2`|If your shorten strategy, below, is entire directories, this field determines how many directories to leave at the end. If your shorten strategy is by character count, this field determines how many characters to allow per directory string.| |`POWERLEVEL9K_SHORTEN_STRATEGY`|None|How the directory strings should be truncated. By default, it will truncate whole directories. Other options are `truncate_middle`, which leaves the start and end of the directory strings, and `truncate_from_right`, which cuts starting from the end of the string.| -|`POWERLEVEL9K_SHORTEN_DELIMITER`|`..`|Delimiter to replace strings with indicating truncation. This can be any string you choose, including an empty string if you wish to have no delimiter.| +|`POWERLEVEL9K_SHORTEN_DELIMITER`|`..`|Delimiter to use in truncated strings. This can be any string you choose, including an empty string if you wish to have no delimiter.| For example, if you wanted the truncation behavior of the `fish` shell, which truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: @@ -226,10 +226,9 @@ others whole directories. ##### ip -This segment shows you your current internal IP address. It tries to examine -all currently used network interfaces and prints the first address it finds. -In the case that this is not the right IP address you can specify the correct -network interface by setting: +This segment tries to examine all currently used network interfaces and prints +the first address it finds. In the case that this is not the right NIC, you can +specify the correct network interface by setting: | Variable | Default Value | Description | |----------|---------------|-------------| From 13b7d26e76af057b844c50fe55de60e211b14fe7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 17 Jan 2016 15:05:34 +0100 Subject: [PATCH 154/155] Changelog entries added for 'HOME_SUBFOLDER' state of the `dir` segment. --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cfaa1d6..2a0f4cfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## v0.3.1 + +### `dir` changes + +A new state `HOME_SUBFOLDER` was added. So if you want to overwrite +colors for this segment, also set this variables: +```zsh +POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND='black' +POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND='white' +``` + ## v0.3.0 ### Introduced "visual identifiers" to the segments From 67895cc5da1fe479d0ae321fba750e199758eee4 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sun, 17 Jan 2016 10:04:04 -0800 Subject: [PATCH 155/155] README: Added a tl;dr --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1f2a7669..d80fd39f 100644 --- a/README.md +++ b/README.md @@ -326,8 +326,11 @@ is count your source files and test files, and calculate the ratio between them. Just enough to give you a quick overview about the test situation of the project you are dealing with. -### Other +### tl; dr -Looking for more information? We put a lot of stuff in our Wiki! +Want to just get a quick start? Check out the [Show Off Your +Config](https://github.com/bhilburn/powerlevel9k/wiki/Show-Off-Your-Config) +portion of the wiki to get going. -[Head to the Wiki](https://github.com/bhilburn/powerlevel9k/wiki) +[The Wiki also has a ton of other useful +information!](https://github.com/bhilburn/powerlevel9k/wiki)