add temp icons & colours

This commit is contained in:
Casper da Costa-Luis 2020-10-18 00:05:46 +01:00
parent 1d27247757
commit 13a7844f57
No known key found for this signature in database
GPG key ID: D88C553DBD362CDE
5 changed files with 133 additions and 0 deletions

View file

@ -22,6 +22,9 @@ cpu_interpolation=(
"\#{gram_bg_color}"
"\#{gram_fg_color}"
"\#{cpu_temp}"
"\#{cpu_temp_icon}"
"\#{cpu_temp_bg_color}"
"\#{cpu_temp_fg_color}"
)
cpu_commands=(
"#($CURRENT_DIR/scripts/cpu_percentage.sh)"
@ -41,6 +44,9 @@ cpu_commands=(
"#($CURRENT_DIR/scripts/gram_bg_color.sh)"
"#($CURRENT_DIR/scripts/gram_fg_color.sh)"
"#($CURRENT_DIR/scripts/cpu_temp.sh)"
"#($CURRENT_DIR/scripts/cpu_temp_icon.sh)"
"#($CURRENT_DIR/scripts/cpu_temp_bg_color.sh)"
"#($CURRENT_DIR/scripts/cpu_temp_fg_color.sh)"
)
set_tmux_option() {

37
scripts/cpu_temp_bg_color.sh Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
cpu_temp_low_bg_color=""
cpu_temp_medium_bg_color=""
cpu_temp_high_bg_color=""
cpu_temp_low_default_bg_color="#[bg=green]"
cpu_temp_medium_default_bg_color="#[bg=yellow]"
cpu_temp_high_default_bg_color="#[bg=red]"
get_bg_color_settings() {
cpu_temp_low_bg_color=$(get_tmux_option "@cpu_temp_low_bg_color" "$cpu_temp_low_default_bg_color")
cpu_temp_medium_bg_color=$(get_tmux_option "@cpu_temp_medium_bg_color" "$cpu_temp_medium_default_bg_color")
cpu_temp_high_bg_color=$(get_tmux_option "@cpu_temp_high_bg_color" "$cpu_temp_high_default_bg_color")
}
print_bg_color() {
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
local cpu_temp_status=$(temp_status $cpu_temp)
if [ $cpu_temp_status == "low" ]; then
echo "$cpu_temp_low_bg_color"
elif [ $cpu_temp_status == "medium" ]; then
echo "$cpu_temp_medium_bg_color"
elif [ $cpu_temp_status == "high" ]; then
echo "$cpu_temp_high_bg_color"
fi
}
main() {
get_bg_color_settings
print_bg_color
}
main

37
scripts/cpu_temp_fg_color.sh Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
cpu_temp_low_fg_color=""
cpu_temp_medium_fg_color=""
cpu_temp_high_fg_color=""
cpu_temp_low_default_fg_color="#[bg=green]"
cpu_temp_medium_default_fg_color="#[bg=yellow]"
cpu_temp_high_default_fg_color="#[bg=red]"
get_fg_color_settings() {
cpu_temp_low_fg_color=$(get_tmux_option "@cpu_temp_low_fg_color" "$cpu_temp_low_default_fg_color")
cpu_temp_medium_fg_color=$(get_tmux_option "@cpu_temp_medium_fg_color" "$cpu_temp_medium_default_fg_color")
cpu_temp_high_fg_color=$(get_tmux_option "@cpu_temp_high_fg_color" "$cpu_temp_high_default_fg_color")
}
print_fg_color() {
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
local cpu_temp_status=$(temp_status $cpu_temp)
if [ $cpu_temp_status == "low" ]; then
echo "$cpu_temp_low_fg_color"
elif [ $cpu_temp_status == "medium" ]; then
echo "$cpu_temp_medium_fg_color"
elif [ $cpu_temp_status == "high" ]; then
echo "$cpu_temp_high_fg_color"
fi
}
main() {
get_fg_color_settings
print_fg_color
}
main

40
scripts/cpu_temp_icon.sh Executable file
View 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
cpu_temp_low_icon=""
cpu_temp_medium_icon=""
cpu_temp_high_icon=""
cpu_temp_low_default_icon="="
cpu_temp_medium_default_icon="≡"
cpu_temp_high_default_icon="≣"
# icons are set as script global variables
get_icon_settings() {
cpu_temp_low_icon=$(get_tmux_option "@cpu_temp_low_icon" "$cpu_temp_low_default_icon")
cpu_temp_medium_icon=$(get_tmux_option "@cpu_temp_medium_icon" "$cpu_temp_medium_default_icon")
cpu_temp_high_icon=$(get_tmux_option "@cpu_temp_high_icon" "$cpu_temp_high_default_icon")
}
print_icon() {
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
local cpu_temp_status=$(temp_status $cpu_temp)
if [ $cpu_temp_status == "low" ]; then
echo "$cpu_temp_low_icon"
elif [ $cpu_temp_status == "medium" ]; then
echo "$cpu_temp_medium_icon"
elif [ $cpu_temp_status == "high" ]; then
echo "$cpu_temp_high_icon"
fi
}
main() {
get_icon_settings
local cpu_temp_icon=$(print_icon "$1")
echo "$cpu_temp_icon"
}
main

View file

@ -55,6 +55,19 @@ load_status() {
fi
}
temp_status() {
local temp=$1
cpu_medium_thresh=$(get_tmux_option "@cpu_temp_medium_thresh" "80")
cpu_high_thresh=$(get_tmux_option "@cpu_temp_high_thresh" "90")
if fcomp $cpu_temp_high_thresh $temp; then
echo "high"
elif fcomp $cpu_temp_medium_thresh $temp && fcomp $temp $cpu_temp_high_thresh; then
echo "medium"
else
echo "low"
fi
}
cpus_number() {
if is_linux; then
nproc