aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorDominik Ritter <dritter03@googlemail.com>2015-09-20 21:34:43 +0300
committerDominik Ritter <dritter03@googlemail.com>2015-09-20 21:34:43 +0300
commit43a6079d8396611e6d3693c1766b79b0356af65d (patch)
treede699a1168643efe75a356f60e99153249a6e0f2 /powerlevel9k.zsh-theme
parent2809000f9c11a932464810ff73ecbb6ac02d2952 (diff)
Ram as own prompt.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rw-r--r--powerlevel9k.zsh-theme56
1 files 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)