summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2019-05-22 20:14:57 +0300
committerromkatv <roman.perepelitsa@gmail.com>2019-05-22 20:14:57 +0300
commitb92d510882fb9f95174843137c72df84e9d82b72 (patch)
treef10c1c913c0ad54ce676f26361f256f588318cca /functions
parent3e3da88dbcaeffba98ac5ed500061ea28207d34b (diff)
speed up ram and swap prompts
Diffstat (limited to 'functions')
-rwxr-xr-xfunctions/utilities.zsh36
1 files changed, 10 insertions, 26 deletions
diff --git a/functions/utilities.zsh b/functions/utilities.zsh
index 88470885..56fcdc59 100755
--- a/functions/utilities.zsh
+++ b/functions/utilities.zsh
@@ -45,34 +45,18 @@ function _p9k_g_expand() {
typeset -g $1=${(g::)${(P)1}}
}
-# Converts large memory values into a human-readable unit (e.g., bytes --> GB)
-# Takes two arguments:
-# * $size - The number which should be prettified
-# * $base - The base of the number (default Bytes)
-printSizeHumanReadable() {
- typeset -F 2 size
- size="$1"+0.00001
- local extension
- extension=('B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y')
- local index=1
+typeset -g _P9K_BYTE_SUFFIX=('B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y')
- # if the base is not Bytes
- if [[ -n $2 ]]; then
- local idx
- for idx in "${extension[@]}"; do
- if [[ "$2" == "$idx" ]]; then
- break
- fi
- index=$(( index + 1 ))
- done
- fi
-
- while (( (size / 1024) > 0.1 )); do
- size=$(( size / 1024 ))
- index=$(( index + 1 ))
+# 42 => 42B
+# 1536 => 1.5K
+function _p9k_human_readable_bytes() {
+ typeset -F 2 n=$1
+ local suf
+ for suf in $_P9K_BYTE_SUFFIX; do
+ (( n < 100 )) && break
+ (( n /= 1024 ))
done
-
- echo "$size${extension[$index]}"
+ _P9K_RETVAL=$n$suf
}
# Determine if the passed segment is used in the prompt