Ram as own prompt.

pull/22/head
Dominik Ritter 9 years ago
parent 2809000f9c
commit 43a6079d83

@ -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"
}
prompt_ram() {
defined POWERLEVEL9K_RAM_ELEMENTS || POWERLEVEL9K_RAM_ELEMENTS=(ram_free swap_used)
if [[ "$POWERLEVEL9K_LOAD_SHOW_FREE_RAM" == true ]]; then
echo -n "$(print_icon 'RAM_ICON') $(printSizeHumanReadable "$ramfree" $base) "
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)

Loading…
Cancel
Save