mirror of
https://github.com/tmux-plugins/tmux-cpu.git
synced 2026-09-10 07:16:16 -04:00
GRAM: add GPU RAM use
This commit is contained in:
parent
0fbc185654
commit
02077415a8
37
scripts/gram_bg_color.sh
Executable file
37
scripts/gram_bg_color.sh
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gram_low_bg_color=""
|
||||
gram_medium_bg_color=""
|
||||
gram_high_bg_color=""
|
||||
|
||||
gram_low_default_bg_color="#[bg=green]"
|
||||
gram_medium_default_bg_color="#[bg=yellow]"
|
||||
gram_high_default_bg_color="#[bg=red]"
|
||||
|
||||
get_bg_color_settings() {
|
||||
gram_low_bg_color=$(get_tmux_option "@gram_low_bg_color" "$gram_low_default_bg_color")
|
||||
gram_medium_bg_color=$(get_tmux_option "@gram_medium_bg_color" "$gram_medium_default_bg_color")
|
||||
gram_high_bg_color=$(get_tmux_option "@gram_high_bg_color" "$gram_high_default_bg_color")
|
||||
}
|
||||
|
||||
print_bg_color() {
|
||||
local gram_percentage=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(cpu_load_status $gram_percentage)
|
||||
if [ $gram_load_status == "low" ]; then
|
||||
echo "$gram_low_bg_color"
|
||||
elif [ $gram_load_status == "medium" ]; then
|
||||
echo "$gram_medium_bg_color"
|
||||
elif [ $gram_load_status == "high" ]; then
|
||||
echo "$gram_high_bg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_bg_color_settings
|
||||
print_bg_color
|
||||
}
|
||||
main
|
||||
37
scripts/gram_fg_color.sh
Executable file
37
scripts/gram_fg_color.sh
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gram_low_fg_color=""
|
||||
gram_medium_fg_color=""
|
||||
gram_high_fg_color=""
|
||||
|
||||
gram_low_default_fg_color="#[fg=green]"
|
||||
gram_medium_default_fg_color="#[fg=yellow]"
|
||||
gram_high_default_fg_color="#[fg=red]"
|
||||
|
||||
get_fg_color_settings() {
|
||||
gram_low_fg_color=$(get_tmux_option "@gram_low_fg_color" "$gram_low_default_fg_color")
|
||||
gram_medium_fg_color=$(get_tmux_option "@gram_medium_fg_color" "$gram_medium_default_fg_color")
|
||||
gram_high_fg_color=$(get_tmux_option "@gram_high_fg_color" "$gram_high_default_fg_color")
|
||||
}
|
||||
|
||||
print_fg_color() {
|
||||
local gram_percentage=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(cpu_load_status $gram_percentage)
|
||||
if [ $gram_load_status == "low" ]; then
|
||||
echo "$gram_low_fg_color"
|
||||
elif [ $gram_load_status == "medium" ]; then
|
||||
echo "$gram_medium_fg_color"
|
||||
elif [ $gram_load_status == "high" ]; then
|
||||
echo "$gram_high_fg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_fg_color_settings
|
||||
print_fg_color
|
||||
}
|
||||
main
|
||||
40
scripts/gram_icon.sh
Executable file
40
scripts/gram_icon.sh
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
gram_low_icon=""
|
||||
gram_medium_icon=""
|
||||
gram_high_icon=""
|
||||
|
||||
gram_low_default_icon="="
|
||||
gram_medium_default_icon="≡"
|
||||
gram_high_default_icon="≣"
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_settings() {
|
||||
gram_low_icon=$(get_tmux_option "@gram_low_icon" "$gram_low_default_icon")
|
||||
gram_medium_icon=$(get_tmux_option "@gram_medium_icon" "$gram_medium_default_icon")
|
||||
gram_high_icon=$(get_tmux_option "@gram_high_icon" "$gram_high_default_icon")
|
||||
}
|
||||
|
||||
print_icon() {
|
||||
local gram_percentage=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(cpu_load_status $gram_percentage)
|
||||
if [ $gram_load_status == "low" ]; then
|
||||
echo "$gram_low_icon"
|
||||
elif [ $gram_load_status == "medium" ]; then
|
||||
echo "$gram_medium_icon"
|
||||
elif [ $gram_load_status == "high" ]; then
|
||||
echo "$gram_high_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_settings
|
||||
local gram_icon=$(print_icon "$1")
|
||||
echo "$gram_icon"
|
||||
}
|
||||
main
|
||||
27
scripts/gram_percentage.sh
Executable file
27
scripts/gram_percentage.sh
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gram_percentage_format="%3.1f%%"
|
||||
|
||||
print_gram_percentage() {
|
||||
gram_percentage_format=$(get_tmux_option "@gram_percentage_format" "$gram_percentage_format")
|
||||
|
||||
if command_exists "nvidia-smi"; then
|
||||
loads=$(nvidia-smi)
|
||||
elif command_exists "cuda-smi"; then
|
||||
loads=$(cuda-smi)
|
||||
else
|
||||
echo "No GPU"
|
||||
return
|
||||
fi
|
||||
loads=$(echo "$loads" | sed -nr 's/.*\s([0-9]+)MiB\s*\/\s*([0-9]+)MiB.*/\1 \2/p')
|
||||
echo "$loads" | awk -v format="$gram_percentage_format" '{used+=$1; tot+=$2} END {printf format, 100*$1/$2}'
|
||||
}
|
||||
|
||||
main() {
|
||||
print_gram_percentage
|
||||
}
|
||||
main
|
||||
Loading…
Reference in a new issue