From 2809000f9c11a932464810ff73ecbb6ac02d2952 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 20 Sep 2015 20:33:50 +0200 Subject: [PATCH 01/15] 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 02/15] 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 03/15] 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 04/15] 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 05/15] 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 8e458e5e9acac0766f4319eb7494f033201978a9 Mon Sep 17 00:00:00 2001 From: Martin Pelikan Date: Sun, 18 Oct 2015 00:11:24 -0700 Subject: [PATCH 06/15] 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 07/15] 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 08/15] 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 09/15] 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 10/15] 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 11/15] 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 12/15] 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 13/15] 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 fa85a5158fa3d9ef84ecd3e94ab5deb805b735ab Mon Sep 17 00:00:00 2001 From: Daniel Gordon Date: Mon, 19 Oct 2015 13:02:24 -0500 Subject: [PATCH 14/15] 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 15/15] 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.