RAM: clean up format handling

This commit is contained in:
Casper da Costa-Luis 2020-03-02 13:24:36 +00:00
parent e2a7f5f8fc
commit 898bf90ce1
No known key found for this signature in database
GPG key ID: D88C553DBD362CDE

View file

@ -10,9 +10,7 @@ print_ram_percentage() {
ram_percentage_format=$(get_tmux_option "@ram_percentage_format" "$ram_percentage_format")
if command_exists "free"; then
IFS=' ' read -ra numbers <<< "$(free | sed '/^\s*$/d' | grep "Mem:" | tr -s ' ' )"
ram=$(bc <<< "scale=6; 100 * ${numbers[2]} / ${numbers[1]}" | awk -v format="$ram_percentage_format" '{usage=$1} END {printf(format,usage)}')
echo "$ram" # I get an extra percent if I don't use the variable for some reason
free | awk -v format="$ram_percentage_format" '$1 == "Mem:" {printf(format, 100*$3/$2)}'
fi
}