mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-18 13:41:56 +00:00
Ram as own prompt.
This commit is contained in:
parent
2809000f9c
commit
43a6079d83
1 changed files with 42 additions and 14 deletions
|
@ -654,22 +654,11 @@ prompt_ip() {
|
||||||
"$1_prompt_segment" "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip"
|
"$1_prompt_segment" "$0" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_default POWERLEVEL9K_LOAD_SHOW_FREE_RAM true
|
|
||||||
prompt_load() {
|
prompt_load() {
|
||||||
if [[ "$OS" == "OSX" ]]; then
|
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)
|
||||||
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
|
else
|
||||||
load_avg_5min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1)
|
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
|
fi
|
||||||
|
|
||||||
# Replace comma
|
# Replace comma
|
||||||
|
@ -687,10 +676,49 @@ prompt_load() {
|
||||||
fi
|
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" "$(print_icon 'LOAD_ICON') $load_avg_5min"
|
||||||
|
}
|
||||||
|
|
||||||
if [[ "$POWERLEVEL9K_LOAD_SHOW_FREE_RAM" == true ]]; then
|
prompt_ram() {
|
||||||
echo -n "$(print_icon 'RAM_ICON') $(printSizeHumanReadable "$ramfree" $base) "
|
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
|
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)
|
# Right Status: (return code, root status, background jobs)
|
||||||
|
|
Loading…
Reference in a new issue