mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-18 05:40:07 +00:00
Merge pull request #129 from dritter/ram_prompt
Breaking RAM and Swap out of load segment into their own segment.
This commit is contained in:
commit
15670379ed
2 changed files with 58 additions and 18 deletions
12
README.md
12
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.
|
||||
|
|
|
@ -230,7 +230,8 @@ function print_icon() {
|
|||
|
||||
# Converts large memory values into a human-readable unit (e.g., bytes --> GB)
|
||||
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
|
||||
|
@ -245,7 +246,7 @@ printSizeHumanReadable() {
|
|||
done
|
||||
fi
|
||||
|
||||
while (( (size / 1024) > 0 )); do
|
||||
while (( (size / 1024) > 0.1 )); do
|
||||
size=$(( size / 1024 ))
|
||||
index=$(( index + 1 ))
|
||||
done
|
||||
|
@ -691,22 +692,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
|
||||
|
@ -724,10 +714,6 @@ 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
|
||||
}
|
||||
|
||||
# Node version
|
||||
|
@ -754,6 +740,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% }"
|
||||
}
|
||||
|
||||
# Node version from NVM
|
||||
# Only prints the segment if different than the default value
|
||||
prompt_nvm() {
|
||||
|
|
Loading…
Reference in a new issue