New TMUX statusbar and config cleanup

This commit is contained in:
2024-09-27 20:03:50 +01:00
parent 19537c6d3f
commit 5d64f87244
73 changed files with 3266 additions and 93 deletions

View File

@@ -0,0 +1,88 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$CURRENT_DIR/scripts/helpers.sh"
cpu_interpolation=(
"\#{cpu_percentage}"
"\#{cpu_icon}"
"\#{cpu_bg_color}"
"\#{cpu_fg_color}"
"\#{gpu_percentage}"
"\#{gpu_icon}"
"\#{gpu_bg_color}"
"\#{gpu_fg_color}"
"\#{ram_percentage}"
"\#{ram_icon}"
"\#{ram_bg_color}"
"\#{ram_fg_color}"
"\#{gram_percentage}"
"\#{gram_icon}"
"\#{gram_bg_color}"
"\#{gram_fg_color}"
"\#{cpu_temp}"
"\#{cpu_temp_icon}"
"\#{cpu_temp_bg_color}"
"\#{cpu_temp_fg_color}"
"\#{gpu_temp}"
"\#{gpu_temp_icon}"
"\#{gpu_temp_bg_color}"
"\#{gpu_temp_fg_color}"
)
cpu_commands=(
"#($CURRENT_DIR/scripts/cpu_percentage.sh)"
"#($CURRENT_DIR/scripts/cpu_icon.sh)"
"#($CURRENT_DIR/scripts/cpu_bg_color.sh)"
"#($CURRENT_DIR/scripts/cpu_fg_color.sh)"
"#($CURRENT_DIR/scripts/gpu_percentage.sh)"
"#($CURRENT_DIR/scripts/gpu_icon.sh)"
"#($CURRENT_DIR/scripts/gpu_bg_color.sh)"
"#($CURRENT_DIR/scripts/gpu_fg_color.sh)"
"#($CURRENT_DIR/scripts/ram_percentage.sh)"
"#($CURRENT_DIR/scripts/ram_icon.sh)"
"#($CURRENT_DIR/scripts/ram_bg_color.sh)"
"#($CURRENT_DIR/scripts/ram_fg_color.sh)"
"#($CURRENT_DIR/scripts/gram_percentage.sh)"
"#($CURRENT_DIR/scripts/gram_icon.sh)"
"#($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)"
"#($CURRENT_DIR/scripts/gpu_temp.sh)"
"#($CURRENT_DIR/scripts/gpu_temp_icon.sh)"
"#($CURRENT_DIR/scripts/gpu_temp_bg_color.sh)"
"#($CURRENT_DIR/scripts/gpu_temp_fg_color.sh)"
)
set_tmux_option() {
local option=$1
local value=$2
tmux set-option -gq "$option" "$value"
}
do_interpolation() {
local all_interpolated="$1"
for ((i = 0; i < ${#cpu_commands[@]}; i++)); do
all_interpolated=${all_interpolated//${cpu_interpolation[$i]}/${cpu_commands[$i]}}
done
echo "$all_interpolated"
}
update_tmux_option() {
local option
local option_value
local new_option_value
option=$1
option_value=$(get_tmux_option "$option")
new_option_value=$(do_interpolation "$option_value")
set_tmux_option "$option" "$new_option_value"
}
main() {
update_tmux_option "status-right"
update_tmux_option "status-left"
}
main

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_low_bg_color=""
cpu_medium_bg_color=""
cpu_high_bg_color=""
cpu_low_default_bg_color="#[bg=green]"
cpu_medium_default_bg_color="#[bg=yellow]"
cpu_high_default_bg_color="#[bg=red]"
get_bg_color_settings() {
cpu_low_bg_color=$(get_tmux_option "@cpu_low_bg_color" "$cpu_low_default_bg_color")
cpu_medium_bg_color=$(get_tmux_option "@cpu_medium_bg_color" "$cpu_medium_default_bg_color")
cpu_high_bg_color=$(get_tmux_option "@cpu_high_bg_color" "$cpu_high_default_bg_color")
}
print_bg_color() {
local cpu_percentage
local load_status
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
load_status=$(load_status "$cpu_percentage" "cpu")
if [ "$load_status" == "low" ]; then
echo "$cpu_low_bg_color"
elif [ "$load_status" == "medium" ]; then
echo "$cpu_medium_bg_color"
elif [ "$load_status" == "high" ]; then
echo "$cpu_high_bg_color"
fi
}
main() {
get_bg_color_settings
print_bg_color
}
main "$@"

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_low_fg_color=""
cpu_medium_fg_color=""
cpu_high_fg_color=""
cpu_low_default_fg_color="#[fg=green]"
cpu_medium_default_fg_color="#[fg=yellow]"
cpu_high_default_fg_color="#[fg=red]"
get_fg_color_settings() {
cpu_low_fg_color=$(get_tmux_option "@cpu_low_fg_color" "$cpu_low_default_fg_color")
cpu_medium_fg_color=$(get_tmux_option "@cpu_medium_fg_color" "$cpu_medium_default_fg_color")
cpu_high_fg_color=$(get_tmux_option "@cpu_high_fg_color" "$cpu_high_default_fg_color")
}
print_fg_color() {
local cpu_percentage
local load_status
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
load_status=$(load_status "$cpu_percentage" "cpu")
if [ "$load_status" == "low" ]; then
echo "$cpu_low_fg_color"
elif [ "$load_status" == "medium" ]; then
echo "$cpu_medium_fg_color"
elif [ "$load_status" == "high" ]; then
echo "$cpu_high_fg_color"
fi
}
main() {
get_fg_color_settings
print_fg_color
}
main "$@"

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
cpu_low_icon=""
cpu_medium_icon=""
cpu_high_icon=""
cpu_low_default_icon="="
cpu_medium_default_icon="≡"
cpu_high_default_icon="≣"
# icons are set as script global variables
get_icon_settings() {
cpu_low_icon=$(get_tmux_option "@cpu_low_icon" "$cpu_low_default_icon")
cpu_medium_icon=$(get_tmux_option "@cpu_medium_icon" "$cpu_medium_default_icon")
cpu_high_icon=$(get_tmux_option "@cpu_high_icon" "$cpu_high_default_icon")
}
print_icon() {
local cpu_percentage
local load_status
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
load_status=$(load_status "$cpu_percentage" "cpu")
if [ "$load_status" == "low" ]; then
echo "$cpu_low_icon"
elif [ "$load_status" == "medium" ]; then
echo "$cpu_medium_icon"
elif [ "$load_status" == "high" ]; then
echo "$cpu_high_icon"
fi
}
main() {
get_icon_settings
print_icon "$1"
}
main "$@"

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_percentage_format="%3.1f%%"
print_cpu_percentage() {
cpu_percentage_format=$(get_tmux_option "@cpu_percentage_format" "$cpu_percentage_format")
if command_exists "iostat"; then
if is_linux_iostat; then
cached_eval iostat -c 1 2 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$NF} END {printf(format, usage)}' | sed 's/,/./'
elif is_osx; then
cached_eval iostat -c 2 disk0 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$6} END {printf(format, usage)}' | sed 's/,/./'
elif is_freebsd || is_openbsd; then
cached_eval iostat -c 2 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$NF} END {printf(format, usage)}' | sed 's/,/./'
else
echo "Unknown iostat version please create an issue"
fi
elif command_exists "sar"; then
cached_eval sar -u 1 1 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$NF} END {printf(format, usage)}' | sed 's/,/./'
else
if is_cygwin; then
usage="$(cached_eval WMIC cpu get LoadPercentage | grep -Eo '^[0-9]+')"
# shellcheck disable=SC2059
printf "$cpu_percentage_format" "$usage"
else
load=$(cached_eval ps -aux | awk '{print $3}' | tail -n+2 | awk '{s+=$1} END {print s}')
cpus=$(cpus_number)
echo "$load $cpus" | awk -v format="$cpu_percentage_format" '{printf format, $1/$2}'
fi
fi
}
main() {
print_cpu_percentage
}
main

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_temp_format="%2.0f"
cpu_temp_unit="C"
print_cpu_temp() {
cpu_temp_format=$(get_tmux_option "@cpu_temp_format" "$cpu_temp_format")
cpu_temp_unit=$(get_tmux_option "@cpu_temp_unit" "$cpu_temp_unit")
if command_exists "sensors"; then
local val
if [[ "$cpu_temp_unit" == F ]]; then
val="$(sensors -f)"
else
val="$(sensors)"
fi
echo "$val" | sed -e 's/^Tccd/Core /' | awk -v format="$cpu_temp_format$cpu_temp_unit" '/^Core [0-9]+/ {gsub("[^0-9.]", "", $3); sum+=$3; n+=1} END {printf(format, sum/n)}'
fi
}
main() {
print_cpu_temp
}
main

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
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
local cpu_temp_status
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
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

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
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="#[fg=green]"
cpu_temp_medium_default_fg_color="#[fg=yellow]"
cpu_temp_high_default_fg_color="#[fg=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
local cpu_temp_status
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
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

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
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
local cpu_temp_status
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
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
print_icon "$1"
}
main "$@"

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_low_bg_color=""
gpu_medium_bg_color=""
gpu_high_bg_color=""
gpu_low_default_bg_color="#[bg=green]"
gpu_medium_default_bg_color="#[bg=yellow]"
gpu_high_default_bg_color="#[bg=red]"
get_bg_color_settings() {
gpu_low_bg_color=$(get_tmux_option "@gpu_low_bg_color" "$gpu_low_default_bg_color")
gpu_medium_bg_color=$(get_tmux_option "@gpu_medium_bg_color" "$gpu_medium_default_bg_color")
gpu_high_bg_color=$(get_tmux_option "@gpu_high_bg_color" "$gpu_high_default_bg_color")
}
print_bg_color() {
local gpu_percentage
local gpu_load_status
gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//')
gpu_load_status=$(load_status "$gpu_percentage" "gpu")
if [ "$gpu_load_status" == "low" ]; then
echo "$gpu_low_bg_color"
elif [ "$gpu_load_status" == "medium" ]; then
echo "$gpu_medium_bg_color"
elif [ "$gpu_load_status" == "high" ]; then
echo "$gpu_high_bg_color"
fi
}
main() {
get_bg_color_settings
print_bg_color
}
main "$@"

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_low_fg_color=""
gpu_medium_fg_color=""
gpu_high_fg_color=""
gpu_low_default_fg_color="#[fg=green]"
gpu_medium_default_fg_color="#[fg=yellow]"
gpu_high_default_fg_color="#[fg=red]"
get_fg_color_settings() {
gpu_low_fg_color=$(get_tmux_option "@gpu_low_fg_color" "$gpu_low_default_fg_color")
gpu_medium_fg_color=$(get_tmux_option "@gpu_medium_fg_color" "$gpu_medium_default_fg_color")
gpu_high_fg_color=$(get_tmux_option "@gpu_high_fg_color" "$gpu_high_default_fg_color")
}
print_fg_color() {
local gpu_percentage
local gpu_load_status
gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//')
gpu_load_status=$(load_status "$gpu_percentage" "gpu")
if [ "$gpu_load_status" == "low" ]; then
echo "$gpu_low_fg_color"
elif [ "$gpu_load_status" == "medium" ]; then
echo "$gpu_medium_fg_color"
elif [ "$gpu_load_status" == "high" ]; then
echo "$gpu_high_fg_color"
fi
}
main() {
get_fg_color_settings
print_fg_color
}
main "$@"

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
gpu_low_icon=""
gpu_medium_icon=""
gpu_high_icon=""
gpu_low_default_icon="="
gpu_medium_default_icon="≡"
gpu_high_default_icon="≣"
# icons are set as script global variables
get_icon_settings() {
gpu_low_icon=$(get_tmux_option "@gpu_low_icon" "$gpu_low_default_icon")
gpu_medium_icon=$(get_tmux_option "@gpu_medium_icon" "$gpu_medium_default_icon")
gpu_high_icon=$(get_tmux_option "@gpu_high_icon" "$gpu_high_default_icon")
}
print_icon() {
local gpu_percentage
local gpu_load_status
gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//')
gpu_load_status=$(load_status "$gpu_percentage" "gpu")
if [ "$gpu_load_status" == "low" ]; then
echo "$gpu_low_icon"
elif [ "$gpu_load_status" == "medium" ]; then
echo "$gpu_medium_icon"
elif [ "$gpu_load_status" == "high" ]; then
echo "$gpu_high_icon"
fi
}
main() {
get_icon_settings
print_icon "$1"
}
main "$@"

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_percentage_format="%3.1f%%"
print_gpu_percentage() {
gpu_percentage_format=$(get_tmux_option "@gpu_percentage_format" "$gpu_percentage_format")
if command_exists "nvidia-smi"; then
loads=$(cached_eval nvidia-smi)
elif command_exists "cuda-smi"; then
loads=$(cached_eval cuda-smi)
else
echo "No GPU"
return
fi
echo "$loads" | sed -nr 's/.*\s([0-9]+)%.*/\1/p' | awk -v format="$gpu_percentage_format" '{sum+=$1; n+=1} END {printf format, sum/n}'
}
main() {
print_gpu_percentage
}
main

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_temp_format="%2.0f"
gpu_temp_unit="C"
print_gpu_temp() {
gpu_temp_format=$(get_tmux_option "@gpu_temp_format" "$gpu_temp_format")
gpu_temp_unit=$(get_tmux_option "@gpu_temp_unit" "$gpu_temp_unit")
if command_exists "nvidia-smi"; then
loads=$(cached_eval nvidia-smi)
elif command_exists "cuda-smi"; then
loads=$(cached_eval cuda-smi)
else
echo "No GPU"
return
fi
tempC=$(echo "$loads" | sed -nr 's/.*\s([0-9]+)C.*/\1/p' | awk '{sum+=$1; n+=1} END {printf "%5.3f", sum/n}')
if [ "$gpu_temp_unit" == "C" ]; then
echo "$tempC" | awk -v format="${gpu_temp_format}C" '{sum+=$1} END {printf format, sum}'
else
echo "$tempC" | awk -v format="${gpu_temp_format}F" '{sum+=$1} END {printf format, sum*9/5+32}'
fi
}
main() {
print_gpu_temp
}
main "$@"

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_temp_low_bg_color=""
gpu_temp_medium_bg_color=""
gpu_temp_high_bg_color=""
gpu_temp_low_default_bg_color="#[bg=green]"
gpu_temp_medium_default_bg_color="#[bg=yellow]"
gpu_temp_high_default_bg_color="#[bg=red]"
get_bg_color_settings() {
gpu_temp_low_bg_color=$(get_tmux_option "@gpu_temp_low_bg_color" "$gpu_temp_low_default_bg_color")
gpu_temp_medium_bg_color=$(get_tmux_option "@gpu_temp_medium_bg_color" "$gpu_temp_medium_default_bg_color")
gpu_temp_high_bg_color=$(get_tmux_option "@gpu_temp_high_bg_color" "$gpu_temp_high_default_bg_color")
}
print_bg_color() {
local gpu_temp
local gpu_temp_status
gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//')
gpu_temp_status=$(temp_status "$gpu_temp")
if [ "$gpu_temp_status" == "low" ]; then
echo "$gpu_temp_low_bg_color"
elif [ "$gpu_temp_status" == "medium" ]; then
echo "$gpu_temp_medium_bg_color"
elif [ "$gpu_temp_status" == "high" ]; then
echo "$gpu_temp_high_bg_color"
fi
}
main() {
get_bg_color_settings
print_bg_color
}
main "$@"

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_temp_low_fg_color=""
gpu_temp_medium_fg_color=""
gpu_temp_high_fg_color=""
gpu_temp_low_default_fg_color="#[fg=green]"
gpu_temp_medium_default_fg_color="#[fg=yellow]"
gpu_temp_high_default_fg_color="#[fg=red]"
get_fg_color_settings() {
gpu_temp_low_fg_color=$(get_tmux_option "@gpu_temp_low_fg_color" "$gpu_temp_low_default_fg_color")
gpu_temp_medium_fg_color=$(get_tmux_option "@gpu_temp_medium_fg_color" "$gpu_temp_medium_default_fg_color")
gpu_temp_high_fg_color=$(get_tmux_option "@gpu_temp_high_fg_color" "$gpu_temp_high_default_fg_color")
}
print_fg_color() {
local gpu_temp
local gpu_temp_status
gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//')
gpu_temp_status=$(temp_status "$gpu_temp")
if [ "$gpu_temp_status" == "low" ]; then
echo "$gpu_temp_low_fg_color"
elif [ "$gpu_temp_status" == "medium" ]; then
echo "$gpu_temp_medium_fg_color"
elif [ "$gpu_temp_status" == "high" ]; then
echo "$gpu_temp_high_fg_color"
fi
}
main() {
get_fg_color_settings
print_fg_color
}
main "$@"

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
gpu_temp_low_icon=""
gpu_temp_medium_icon=""
gpu_temp_high_icon=""
gpu_temp_low_default_icon="="
gpu_temp_medium_default_icon="≡"
gpu_temp_high_default_icon="≣"
# icons are set as script global variables
get_icon_settings() {
gpu_temp_low_icon=$(get_tmux_option "@gpu_temp_low_icon" "$gpu_temp_low_default_icon")
gpu_temp_medium_icon=$(get_tmux_option "@gpu_temp_medium_icon" "$gpu_temp_medium_default_icon")
gpu_temp_high_icon=$(get_tmux_option "@gpu_temp_high_icon" "$gpu_temp_high_default_icon")
}
print_icon() {
local gpu_temp
local gpu_temp_status
gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//')
gpu_temp_status=$(temp_status "$gpu_temp")
if [ "$gpu_temp_status" == "low" ]; then
echo "$gpu_temp_low_icon"
elif [ "$gpu_temp_status" == "medium" ]; then
echo "$gpu_temp_medium_icon"
elif [ "$gpu_temp_status" == "high" ]; then
echo "$gpu_temp_high_icon"
fi
}
main() {
get_icon_settings
print_icon "$1"
}
main "$@"

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
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
local gram_load_status
gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//')
gram_load_status=$(load_status "$gram_percentage" "gram")
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 "$@"

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
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
local gram_load_status
gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//')
gram_load_status=$(load_status "$gram_percentage" "gram")
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 "$@"

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
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
local gram_load_status
gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//')
gram_load_status=$(load_status "$gram_percentage" "gram")
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
print_icon "$1"
}
main "$@"

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
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=$(cached_eval nvidia-smi | sed -nr 's/.*\s([0-9]+)MiB\s*\/\s*([0-9]+)MiB.*/\1 \2/p')
elif command_exists "cuda-smi"; then
loads=$(cached_eval cuda-smi | sed -nr 's/.*\s([0-9.]+) of ([0-9.]+) MB.*/\1 \2/p' | awk '{print $2-$1" "$2}')
else
echo "No GPU"
return
fi
echo "$loads" | awk -v format="$gram_percentage_format" '{used+=$1; tot+=$2} END {printf format, 100*used/tot}'
}
main() {
print_gram_percentage
}
main "$@"

View File

@@ -0,0 +1,152 @@
#!/usr/bin/env bash
export LANG=C
export LC_ALL=C
get_tmux_option() {
local option
local default_value
local option_value
option="$1"
default_value="$2"
option_value="$(tmux show-option -qv "$option")"
if [ -z "$option_value" ]; then
option_value="$(tmux show-option -gqv "$option")"
fi
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
is_osx() {
[ "$(uname)" == "Darwin" ]
}
is_freebsd() {
[ "$(uname)" == "FreeBSD" ]
}
is_openbsd() {
[ "$(uname)" == "OpenBSD" ]
}
is_linux() {
[ "$(uname)" == "Linux" ]
}
is_cygwin() {
command -v WMIC &>/dev/null
}
is_linux_iostat() {
# Bug in early versions of linux iostat -V return error code
iostat -c &>/dev/null
}
# is second float bigger or equal?
fcomp() {
awk -v n1="$1" -v n2="$2" 'BEGIN {if (n1<=n2) exit 0; exit 1}'
}
load_status() {
local percentage=$1
local prefix=$2
medium_thresh=$(get_tmux_option "@${prefix}_medium_thresh" "30")
high_thresh=$(get_tmux_option "@${prefix}_high_thresh" "80")
if fcomp "$high_thresh" "$percentage"; then
echo "high"
elif fcomp "$medium_thresh" "$percentage" && fcomp "$percentage" "$high_thresh"; then
echo "medium"
else
echo "low"
fi
}
temp_status() {
local temp
temp=$1
cpu_temp_medium_thresh=$(get_tmux_option "@cpu_temp_medium_thresh" "80")
cpu_temp_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
if command_exists "nproc"; then
nproc
else
echo "$(($(sed -n 's/^processor.*:\s*\([0-9]\+\)/\1/p' /proc/cpuinfo | tail -n 1) + 1))"
fi
else
sysctl -n hw.ncpu
fi
}
command_exists() {
local command
command="$1"
command -v "$command" &>/dev/null
}
get_tmp_dir() {
local tmpdir
tmpdir="${TMPDIR:-${TMP:-${TEMP:-/tmp}}}"
[ -d "$tmpdir" ] || local tmpdir=~/tmp
echo "$tmpdir/tmux-$EUID-cpu"
}
get_time() {
date +%s.%N
}
get_cache_val() {
local key
local timeout
local cache
key="$1"
# seconds after which cache is invalidated
timeout="${2:-2}"
cache="$(get_tmp_dir)/$key"
if [ -f "$cache" ]; then
awk -v cache="$(head -n1 "$cache")" -v timeout="$timeout" -v now="$(get_time)" \
'BEGIN {if (now - timeout < cache) exit 0; exit 1}' &&
tail -n+2 "$cache"
fi
}
put_cache_val() {
local key
local val
local tmpdir
key="$1"
val="${*:2}"
tmpdir="$(get_tmp_dir)"
[ ! -d "$tmpdir" ] && mkdir -p "$tmpdir" && chmod 0700 "$tmpdir"
(
get_time
echo -n "$val"
) >"$tmpdir/$key"
echo -n "$val"
}
cached_eval() {
local command
local key
local val
command="$1"
key="$(basename "$command")"
val="$(get_cache_val "$key")"
if [ -z "$val" ]; then
put_cache_val "$key" "$($command "${@:2}")"
else
echo -n "$val"
fi
}

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
ram_low_bg_color=""
ram_medium_bg_color=""
ram_high_bg_color=""
ram_low_default_bg_color="#[bg=green]"
ram_medium_default_bg_color="#[bg=yellow]"
ram_high_default_bg_color="#[bg=red]"
get_bg_color_settings() {
ram_low_bg_color=$(get_tmux_option "@ram_low_bg_color" "$ram_low_default_bg_color")
ram_medium_bg_color=$(get_tmux_option "@ram_medium_bg_color" "$ram_medium_default_bg_color")
ram_high_bg_color=$(get_tmux_option "@ram_high_bg_color" "$ram_high_default_bg_color")
}
print_bg_color() {
local ram_percentage
local ram_load_status
ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//')
ram_load_status=$(load_status "$ram_percentage" "ram")
if [ "$ram_load_status" == "low" ]; then
echo "$ram_low_bg_color"
elif [ "$ram_load_status" == "medium" ]; then
echo "$ram_medium_bg_color"
elif [ "$ram_load_status" == "high" ]; then
echo "$ram_high_bg_color"
fi
}
main() {
get_bg_color_settings
print_bg_color
}
main

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
ram_low_fg_color=""
ram_medium_fg_color=""
ram_high_fg_color=""
ram_low_default_fg_color="#[fg=green]"
ram_medium_default_fg_color="#[fg=yellow]"
ram_high_default_fg_color="#[fg=red]"
get_fg_color_settings() {
ram_low_fg_color=$(get_tmux_option "@ram_low_fg_color" "$ram_low_default_fg_color")
ram_medium_fg_color=$(get_tmux_option "@ram_medium_fg_color" "$ram_medium_default_fg_color")
ram_high_fg_color=$(get_tmux_option "@ram_high_fg_color" "$ram_high_default_fg_color")
}
print_fg_color() {
local ram_percentage
local ram_load_status
ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//')
ram_load_status=$(load_status "$ram_percentage" "ram")
if [ "$ram_load_status" == "low" ]; then
echo "$ram_low_fg_color"
elif [ "$ram_load_status" == "medium" ]; then
echo "$ram_medium_fg_color"
elif [ "$ram_load_status" == "high" ]; then
echo "$ram_high_fg_color"
fi
}
main() {
get_fg_color_settings
print_fg_color
}
main

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
ram_low_icon=""
ram_medium_icon=""
ram_high_icon=""
ram_low_default_icon="="
ram_medium_default_icon="≡"
ram_high_default_icon="≣"
# icons are set as script global variables
get_icon_settings() {
ram_low_icon=$(get_tmux_option "@ram_low_icon" "$ram_low_default_icon")
ram_medium_icon=$(get_tmux_option "@ram_medium_icon" "$ram_medium_default_icon")
ram_high_icon=$(get_tmux_option "@ram_high_icon" "$ram_high_default_icon")
}
print_icon() {
local ram_percentage
local ram_load_status
ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//')
ram_load_status=$(load_status "$ram_percentage" "ram")
if [ "$ram_load_status" == "low" ]; then
echo "$ram_low_icon"
elif [ "$ram_load_status" == "medium" ]; then
echo "$ram_medium_icon"
elif [ "$ram_load_status" == "high" ]; then
echo "$ram_high_icon"
fi
}
main() {
get_icon_settings
print_icon "$1"
}
main "$@"

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
ram_percentage_format="%3.1f%%"
sum_macos_vm_stats() {
grep -Eo '[0-9]+' |
awk '{ a += $1 * 4096 } END { print a }'
}
print_ram_percentage() {
ram_percentage_format=$(get_tmux_option "@ram_percentage_format" "$ram_percentage_format")
if command_exists "free"; then
cached_eval free | awk -v format="$ram_percentage_format" '$1 ~ /Mem/ {printf(format, 100*$3/$2)}'
elif command_exists "vm_stat"; then
# page size of 4096 bytes
stats="$(cached_eval vm_stat)"
used_and_cached=$(
echo "$stats" |
grep -E "(Pages active|Pages inactive|Pages speculative|Pages wired down|Pages occupied by compressor)" |
sum_macos_vm_stats
)
cached=$(
echo "$stats" |
grep -E "(Pages purgeable|File-backed pages)" |
sum_macos_vm_stats
)
free=$(
echo "$stats" |
grep -E "(Pages free)" |
sum_macos_vm_stats
)
used=$((used_and_cached - cached))
total=$((used_and_cached + free))
echo "$used $total" | awk -v format="$ram_percentage_format" '{printf(format, 100*$1/$2)}'
fi
}
main() {
print_ram_percentage
}
main