From 1005a7c6fb120cb4b57d60feacc022cef14b1ce0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 17:22:42 +0200 Subject: [PATCH 01/15] Better Icons for Apple and Linux. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ae9da42a..8a7b4d50 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -71,9 +71,9 @@ case $POWERLEVEL9K_MODE in NODE_ICON $'\U2B22' # ⬢ MULTILINE_FIRST_PROMPT_PREFIX $'\U256D'$'\U2500' MULTILINE_SECOND_PROMPT_PREFIX $'\U2570'$'\U2500 ' - APPLE_ICON $'\UF8FF' #  + APPLE_ICON $'\UE26E' #  FREEBSD_ICON $'\U1F608 ' # 😈 - LINUX_ICON $'\U1F427 ' # 🐧 + LINUX_ICON $'\UE271' #  SUNOS_ICON $'\U1F31E ' # 🌞 VCS_UNTRACKED_ICON "\UE16C" #  VCS_UNSTAGED_ICON "\UE17C" #  From 66877efadeab78d8a517c20d2dd879f08d754e3a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 17:24:23 +0200 Subject: [PATCH 02/15] Moved `print_icon` to top in its own section "utility functions". --- powerlevel9k.zsh-theme | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8a7b4d50..654bb0b5 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -44,6 +44,21 @@ #zstyle ':vcs_info:*+*:*' debug true #set -o xtrace +################################################################ +# Utility functions +################################################################ + +function print_icon() { + local icon_name=$1 + local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} + local USER_ICON=${(P)ICON_USER_VARIABLE} + if [[ -n "$USER_ICON" ]]; then + echo -n $USER_ICON + else + echo -n ${icons[$icon_name]} + fi +} + ################################################################ # Icons ################################################################ @@ -190,17 +205,6 @@ if [[ "$OS" == 'OSX' ]]; then fi fi -function print_icon() { - local icon_name=$1 - local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} - local USER_ICON=${(P)ICON_USER_VARIABLE} - if [[ -n "$USER_ICON" ]]; then - echo -n $USER_ICON - else - echo -n ${icons[$icon_name]} - fi -} - ################################################################ # color scheme ################################################################ From f3d2a0755ef421b22b8d5f9a8db6d66e2f774ef9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 17:34:09 +0200 Subject: [PATCH 03/15] Added a segment that displays the 5 min load average and the free RAM. --- powerlevel9k.zsh-theme | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 654bb0b5..26ca7eac 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -59,6 +59,30 @@ function print_icon() { fi } +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]} +} + ################################################################ # Icons ################################################################ @@ -90,6 +114,9 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON $'\U1F608 ' # 😈 LINUX_ICON $'\UE271' #  SUNOS_ICON $'\U1F31E ' # 🌞 + LOAD_ICON $'\UE190 ' #  + #RAM_ICON $'\UE87D' #  + RAM_ICON $'\UE1E2 ' #  VCS_UNTRACKED_ICON "\UE16C" #  VCS_UNSTAGED_ICON "\UE17C" #  VCS_STAGED_ICON "\UE168" #  @@ -130,6 +157,8 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON 'BSD' LINUX_ICON 'Lx' SUNOS_ICON 'Sun' + LOAD_ICON '' + RAM_ICON '' VCS_UNTRACKED_ICON '?' VCS_UNSTAGED_ICON "\u25CF" # ● VCS_STAGED_ICON "\u271A" # ✚ @@ -524,6 +553,30 @@ prompt_icons_test() { done } +prompt_load() { + if [[ "$OS" == "OSX" ]]; then + load_avg_5min=$(sysctl vm.loadavg | grep -o -E -e '[0-9]+\.[0-9]+' | head -n 1) + ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') + # Convert pages into Bytes + ramfree=$(( $ramfree * 4096 )) + base='' + else + load_avg_5min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) + ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") + base=K + fi + + if [[ "$5min_load_avg" -gt 10 ]]; then + BACKGROUND_COLOR="001" + elif [[ "$5min_load_avg" -gt 3 ]]; then + BACKGROUND_COLOR="003" + else + BACKGROUND_COLOR="002" + fi + + $1_prompt_segment "$0" $BACKGROUND_COLOR "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min $(print_icon 'RAM_ICON') $(printSizeHumanReadable $ramfree $base)" +} + # 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. From 2bc5a60c7a84e4b59a8012e3cab82a32b254c406 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 17:35:25 +0200 Subject: [PATCH 04/15] Added a new Icon to the dir-segment. --- powerlevel9k.zsh-theme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 26ca7eac..8a5ce2b1 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -114,6 +114,7 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON $'\U1F608 ' # 😈 LINUX_ICON $'\UE271' #  SUNOS_ICON $'\U1F31E ' # 🌞 + HOME_ICON $'\UE12C' #  LOAD_ICON $'\UE190 ' #  #RAM_ICON $'\UE87D' #  RAM_ICON $'\UE1E2 ' #  @@ -157,6 +158,7 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON 'BSD' LINUX_ICON 'Lx' SUNOS_ICON 'Sun' + HOME_ICON '' LOAD_ICON '' RAM_ICON '' VCS_UNTRACKED_ICON '?' @@ -535,7 +537,7 @@ prompt_dir() { fi - $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$current_path" + $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$(print_icon 'HOME_ICON') $current_path" } # Command number (in local history) From b73366f039c8577cf8848fbbae7fda6221558155 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 17:36:04 +0200 Subject: [PATCH 05/15] Added a segment that displays the current IP address. --- powerlevel9k.zsh-theme | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8a5ce2b1..99c95156 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -115,6 +115,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON $'\UE271' #  SUNOS_ICON $'\U1F31E ' # 🌞 HOME_ICON $'\UE12C' #  + NETWORK_ICON $'\UE1AD' #  LOAD_ICON $'\UE190 ' #  #RAM_ICON $'\UE87D' #  RAM_ICON $'\UE1E2 ' #  @@ -159,6 +160,7 @@ case $POWERLEVEL9K_MODE in LINUX_ICON 'Lx' SUNOS_ICON 'Sun' HOME_ICON '' + NETWORK_ICON '' LOAD_ICON '' RAM_ICON '' VCS_UNTRACKED_ICON '?' @@ -555,6 +557,18 @@ prompt_icons_test() { done } +prompt_ip() { + # TODO: Specify Interface by variable! + if [[ "$OS" == "OSX" ]]; then + # Try to get IP addresses from common interfaces. + ip=$(ipconfig getifaddr en0 || ipconfig getifaddr en1) + else + # Take the first IP that `hostname -I` gives us. + ip=$(hostname -I | grep -o "[0-9.]*" | head -n 1) + fi + $1_prompt_segment "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip" +} + prompt_load() { if [[ "$OS" == "OSX" ]]; then load_avg_5min=$(sysctl vm.loadavg | grep -o -E -e '[0-9]+\.[0-9]+' | head -n 1) From 653ad3d565533116f42fc515b780086700d3f844 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 17:38:15 +0200 Subject: [PATCH 06/15] Added Documentation. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 187a67b4..19374cbd 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,8 @@ currently available are: * **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. * **rbenv** - Ruby environment information (if one is active). From fccc3d5e64869871744baa5d40b397826b9f3cb2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 18:08:38 +0200 Subject: [PATCH 07/15] Better descriptions for Stats and Network segements. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 99c95156..8c76ff85 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -160,9 +160,9 @@ case $POWERLEVEL9K_MODE in LINUX_ICON 'Lx' SUNOS_ICON 'Sun' HOME_ICON '' - NETWORK_ICON '' - LOAD_ICON '' - RAM_ICON '' + NETWORK_ICON 'IP' + LOAD_ICON 'L' + RAM_ICON 'RAM' VCS_UNTRACKED_ICON '?' VCS_UNSTAGED_ICON "\u25CF" # ● VCS_STAGED_ICON "\u271A" # ✚ From 730697893e4b9c06da74f5025fe9318f70a13fdc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 18:26:53 +0200 Subject: [PATCH 08/15] Grep statement simplified. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8c76ff85..f9b14c64 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -571,7 +571,7 @@ prompt_ip() { prompt_load() { if [[ "$OS" == "OSX" ]]; then - load_avg_5min=$(sysctl vm.loadavg | grep -o -E -e '[0-9]+\.[0-9]+' | head -n 1) + load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+\.[0-9]+' | head -n 1) ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') # Convert pages into Bytes ramfree=$(( $ramfree * 4096 )) From 61daa647f11019be316f51c4ade4b2e76c450de1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 19:56:49 +0200 Subject: [PATCH 09/15] IP is now customizable. By default we try to get the ip of `en1` (on OSX) and `eth0` on all other systems. --- powerlevel9k.zsh-theme | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f9b14c64..3142253b 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -558,15 +558,16 @@ prompt_icons_test() { } prompt_ip() { - # TODO: Specify Interface by variable! - if [[ "$OS" == "OSX" ]]; then - # Try to get IP addresses from common interfaces. - ip=$(ipconfig getifaddr en0 || ipconfig getifaddr en1) - else - # Take the first IP that `hostname -I` gives us. - ip=$(hostname -I | grep -o "[0-9.]*" | head -n 1) + if [[ -z "$POWERLEVEL9K_IP_INTERFACE" ]]; then + if [[ "$OS" == "OSX" ]]; then + POWERLEVEL9K_IP_INTERFACE="en1" + else + POWERLEVEL9K_IP_INTERFACE="eth0" + fi fi - $1_prompt_segment "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip" + + ip=$(ifconfig $POWERLEVEL9K_IP_INTERFACE 2> /dev/null | grep -o "inet\s[0-9.]*") + $1_prompt_segment "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') ${ip#inet }" } prompt_load() { From 69fc4d295ce9927e3e401d2442bcefc867cf821c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 27 Aug 2015 18:24:27 +0200 Subject: [PATCH 10/15] Bugfix: load segment changes the color reliably and is customizable. --- powerlevel9k.zsh-theme | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3142253b..2fedede0 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -583,15 +583,18 @@ prompt_load() { base=K fi - if [[ "$5min_load_avg" -gt 10 ]]; then - BACKGROUND_COLOR="001" - elif [[ "$5min_load_avg" -gt 3 ]]; then - BACKGROUND_COLOR="003" + if [[ "$load_avg_5min" -gt 10 ]]; then + BACKGROUND_COLOR="red" + FUNCTION_SUFFIX="_CRITICAL" + elif [[ "$load_avg_5min" -gt 3 ]]; then + BACKGROUND_COLOR="yellow" + FUNCTION_SUFFIX="_WARNING" else - BACKGROUND_COLOR="002" + BACKGROUND_COLOR="green" + FUNCTION_SUFFIX="_NORMAL" fi - $1_prompt_segment "$0" $BACKGROUND_COLOR "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min $(print_icon 'RAM_ICON') $(printSizeHumanReadable $ramfree $base)" + $1_prompt_segment "$0$FUNCTION_SUFFIX" $BACKGROUND_COLOR "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min $(print_icon 'RAM_ICON') $(printSizeHumanReadable $ramfree $base)" } # Right Status: (return code, root status, background jobs) From dca00112ad85b1f650015e666f511b1136213a26 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 29 Aug 2015 16:55:31 +0200 Subject: [PATCH 11/15] Reworked the IP segment. It now tries to get a IP address from all up network interfaces. --- powerlevel9k.zsh-theme | 53 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2fedede0..5065a6fb 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -83,6 +83,30 @@ printSizeHumanReadable() { 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 +} + ################################################################ # Icons ################################################################ @@ -558,16 +582,33 @@ prompt_icons_test() { } prompt_ip() { - if [[ -z "$POWERLEVEL9K_IP_INTERFACE" ]]; then - if [[ "$OS" == "OSX" ]]; then - POWERLEVEL9K_IP_INTERFACE="en1" + if [[ "$OS" == "OSX" ]]; then + if [[ -z "$POWERLEVEL9K_IP_INTERFACE" ]]; then + local interfaces callback + # Get network interface names ordered by service precedence. + interfaces=$(networksetup -listnetworkserviceorder | grep -o "Device:\s*[a-z0-9]*" | grep -o -E '[a-z0-9]*$') + callback='ipconfig getifaddr $item' + + ip=$(getRelevantItem $interfaces $callback) else - POWERLEVEL9K_IP_INTERFACE="eth0" + # Get the IP address of the specified interface. + ip=$(ipconfig getifaddr $POWERLEVEL9K_IP_INTERFACE) + fi + else + if [[ -z "$POWERLEVEL9K_IP_INTERFACE" ]]; then + local interfaces callback + # Get all network interface names that are up + interfaces=$(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o "[a-z0-9]*") + callback='ip -4 a show $item | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*"' + + ip=$(getRelevantItem $interfaces $callback) + else + # Get the IP address of the specified interface. + ip=$(ip -4 a show $POWERLEVEL9K_IP_INTERFACE | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*") fi fi - ip=$(ifconfig $POWERLEVEL9K_IP_INTERFACE 2> /dev/null | grep -o "inet\s[0-9.]*") - $1_prompt_segment "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') ${ip#inet }" + $1_prompt_segment "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip" } prompt_load() { From 602acf3afaea069c9c04668c7c8decb439d30c23 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 29 Aug 2015 17:03:44 +0200 Subject: [PATCH 12/15] Added documentation for the ip segment. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 19374cbd..b5a02dd0 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ this theme focus on four primary goals: - [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) @@ -293,6 +294,15 @@ 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 + +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: + + POWERLEVEL9K_IP_INTERFACE="eth0" + #### The 'time' segment By default the time is show in 'H:M:S' format. If you want to change it, From ae77fc17d84255aa134bf882959aa4b32eaf5913 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 31 Aug 2015 18:13:28 +0200 Subject: [PATCH 13/15] Under OSX the output of `sysctl vm.loadavg` may be localized. With german locale it will print an comma as separator.. --- powerlevel9k.zsh-theme | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5065a6fb..c0819d74 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -613,7 +613,7 @@ prompt_ip() { prompt_load() { if [[ "$OS" == "OSX" ]]; then - load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+\.[0-9]+' | head -n 1) + load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') # Convert pages into Bytes ramfree=$(( $ramfree * 4096 )) @@ -624,6 +624,9 @@ prompt_load() { base=K fi + # Replace comma + load_avg_5min=${load_avg_5min//,/.} + if [[ "$load_avg_5min" -gt 10 ]]; then BACKGROUND_COLOR="red" FUNCTION_SUFFIX="_CRITICAL" From b8b82eee21f8e08fed8a1e9290c763d2c4d87293 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 4 Sep 2015 16:39:28 +0200 Subject: [PATCH 14/15] Use the new `defined` function to test if a network interface was specified. --- powerlevel9k.zsh-theme | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dea71e07..bd187a6f 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -579,28 +579,28 @@ prompt_icons_test() { prompt_ip() { if [[ "$OS" == "OSX" ]]; then - if [[ -z "$POWERLEVEL9K_IP_INTERFACE" ]]; then + if defined POWERLEVEL9K_IP_INTERFACE; then + # Get the IP address of the specified interface. + ip=$(ipconfig getifaddr $POWERLEVEL9K_IP_INTERFACE) + else local interfaces callback # Get network interface names ordered by service precedence. interfaces=$(networksetup -listnetworkserviceorder | grep -o "Device:\s*[a-z0-9]*" | grep -o -E '[a-z0-9]*$') callback='ipconfig getifaddr $item' ip=$(getRelevantItem $interfaces $callback) - else - # Get the IP address of the specified interface. - ip=$(ipconfig getifaddr $POWERLEVEL9K_IP_INTERFACE) fi else - if [[ -z "$POWERLEVEL9K_IP_INTERFACE" ]]; then + if defined POWERLEVEL9K_IP_INTERFACE; then + # Get the IP address of the specified interface. + ip=$(ip -4 a show $POWERLEVEL9K_IP_INTERFACE | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*") + else local interfaces callback # Get all network interface names that are up interfaces=$(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o "[a-z0-9]*") callback='ip -4 a show $item | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*"' ip=$(getRelevantItem $interfaces $callback) - else - # Get the IP address of the specified interface. - ip=$(ip -4 a show $POWERLEVEL9K_IP_INTERFACE | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*") fi fi From f7a05fcd2c05e291e6051d8f2a5df3d723462067 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 4 Sep 2015 17:04:39 +0200 Subject: [PATCH 15/15] Display of free RAM is now configurable. --- powerlevel9k.zsh-theme | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index bd187a6f..75020860 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -607,17 +607,22 @@ 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) - ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') - # Convert pages into Bytes - ramfree=$(( $ramfree * 4096 )) - base='' + 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) - ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") - base=K + 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 @@ -634,7 +639,11 @@ prompt_load() { FUNCTION_SUFFIX="_NORMAL" fi - $1_prompt_segment "$0$FUNCTION_SUFFIX" $BACKGROUND_COLOR "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min $(print_icon 'RAM_ICON') $(printSizeHumanReadable $ramfree $base)" + $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 } # Right Status: (return code, root status, background jobs)