summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md13
-rwxr-xr-xpowerlevel9k.zsh-theme74
2 files changed, 69 insertions, 18 deletions
diff --git a/README.md b/README.md
index b66304bc..f811169e 100644
--- a/README.md
+++ b/README.md
@@ -74,13 +74,15 @@ The segments that are currently available are:
* [battery](#battery) - Current battery status.
* [context](#context) - Your username and host.
* [dir](#dir) - Your current working directory.
+* **go_version** - Show the current GO version.
* **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.
@@ -172,6 +174,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.
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index bc37de31..ea832fe7 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -233,7 +233,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
@@ -248,7 +249,7 @@ printSizeHumanReadable() {
done
fi
- while (( (size / 1024) > 0 )); do
+ while (( (size / 1024) > 0.1 )); do
size=$(( size / 1024 ))
index=$(( index + 1 ))
done
@@ -720,6 +721,16 @@ prompt_dir() {
"$1_prompt_segment" "$0" "blue" "$DEFAULT_COLOR" "$(print_icon 'HOME_ICON')$current_path"
}
+# GO-prompt
+prompt_go_version() {
+ local go_version
+ go_version=$(go version 2>&1 | grep -oe "^go[0-9.]*")
+
+ if [[ -n "$go_version" ]]; then
+ "$1_prompt_segment" "$0" "green" "255" "$go_version"
+ fi
+}
+
# Command number (in local history)
prompt_history() {
"$1_prompt_segment" "$0" "244" "$DEFAULT_COLOR" '%h'
@@ -765,22 +776,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
@@ -798,10 +798,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
@@ -828,6 +824,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() {