diff --git a/README.md b/README.md index 51f627c..448dcc8 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Example: ```shell # in .tmux.conf -set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M ' +set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | #{ram_bg_color} RAM: #{ram_icon} #{ram_percentage} | #{swap_bg_color} SWAP: #{swap_icon} #{swap_percentage} | %a %h-%d %H:%M ' ``` ### Supported Options @@ -93,6 +93,13 @@ GPU equivalents also exist: - `#{gpu_temp_bg_color}` - will change the background color based on the GPU temperature - `#{gpu_temp_fg_color}` - will change the foreground color based on the GPU temperature +SWAP percentage: + +- `#{swap_icon}` - will display a SWAP status icon +- `#{swap_percentage}` - will show SWAP percentage (averaged across cores) +- `#{swap_bg_color}` - will change the background color based on the SWAP percentage +- `#{swap_fg_color}` - will change the foreground color based on the SWAP percentage + ## Examples CPU usage lower than 30%:
diff --git a/cpu.tmux b/cpu.tmux index 576c206..619e86d 100755 --- a/cpu.tmux +++ b/cpu.tmux @@ -29,6 +29,10 @@ cpu_interpolation=( "\#{gpu_temp_icon}" "\#{gpu_temp_bg_color}" "\#{gpu_temp_fg_color}" + "\#{swap_percentage}" + "\#{swap_percentage_icon}" + "\#{swap_percentage_bg_color}" + "\#{swap_percentage_fg_color}" ) cpu_commands=( "#($CURRENT_DIR/scripts/cpu_percentage.sh)" @@ -55,6 +59,10 @@ cpu_commands=( "#($CURRENT_DIR/scripts/gpu_temp_icon.sh)" "#($CURRENT_DIR/scripts/gpu_temp_bg_color.sh)" "#($CURRENT_DIR/scripts/gpu_temp_fg_color.sh)" + "#($CURRENT_DIR/scripts/swap_percentage.sh)" + "#($CURRENT_DIR/scripts/swap_icon.sh)" + "#($CURRENT_DIR/scripts/swap_bg_color.sh)" + "#($CURRENT_DIR/scripts/swap_fg_color.sh)" ) set_tmux_option() { diff --git a/scripts/swap_bg_color.sh b/scripts/swap_bg_color.sh new file mode 100644 index 0000000..31bc200 --- /dev/null +++ b/scripts/swap_bg_color.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +swap_low_bg_color="" +swap_medium_bg_color="" +swap_high_bg_color="" + +swap_low_default_bg_color="#[bg=green]" +swap_medium_default_bg_color="#[bg=yellow]" +swap_high_default_bg_color="#[bg=red]" + +get_bg_color_settings() { + swap_low_bg_color=$(get_tmux_option "@swap_low_bg_color" "$swap_low_default_bg_color") + swap_medium_bg_color=$(get_tmux_option "@swap_medium_bg_color" "$swap_medium_default_bg_color") + swap_high_bg_color=$(get_tmux_option "@swap_high_bg_color" "$swap_high_default_bg_color") +} + +print_bg_color() { + local swap_percentage=$($CURRENT_DIR/swap_percentage.sh | sed -e 's/%//') + local load_status=$(load_status $swap_percentage) + if [ $load_status == "low" ]; then + echo "$swap_low_bg_color" + elif [ $load_status == "medium" ]; then + echo "$swap_medium_bg_color" + elif [ $load_status == "high" ]; then + echo "$swap_high_bg_color" + fi +} + +main() { + get_bg_color_settings + print_bg_color +} +main diff --git a/scripts/swap_fg_color.sh b/scripts/swap_fg_color.sh new file mode 100644 index 0000000..3e74b83 --- /dev/null +++ b/scripts/swap_fg_color.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +swap_low_fg_color="" +swap_medium_fg_color="" +swap_high_fg_color="" + +swap_low_default_fg_color="#[fg=green]" +swap_medium_default_fg_color="#[fg=yellow]" +swap_high_default_fg_color="#[fg=red]" + +get_fg_color_settings() { + swap_low_fg_color=$(get_tmux_option "@swap_low_fg_color" "$swap_low_default_fg_color") + swap_medium_fg_color=$(get_tmux_option "@swap_medium_fg_color" "$swap_medium_default_fg_color") + swap_high_fg_color=$(get_tmux_option "@swap_high_fg_color" "$swap_high_default_fg_color") +} + +print_fg_color() { + local swap_percentage=$($CURRENT_DIR/swap_percentage.sh | sed -e 's/%//') + local load_status=$(load_status $swap_percentage) + if [ $load_status == "low" ]; then + echo "$swap_low_fg_color" + elif [ $load_status == "medium" ]; then + echo "$swap_medium_fg_color" + elif [ $load_status == "high" ]; then + echo "$swap_high_fg_color" + fi +} + +main() { + get_fg_color_settings + print_fg_color +} +main diff --git a/scripts/swap_icon.sh b/scripts/swap_icon.sh new file mode 100644 index 0000000..f04a7d7 --- /dev/null +++ b/scripts/swap_icon.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +# script global variables +swap_low_icon="" +swap_medium_icon="" +swap_high_icon="" + +swap_low_default_icon="=" +swap_medium_default_icon="≡" +swap_high_default_icon="≣" + +# icons are set as script global variables +get_icon_settings() { + swap_low_icon=$(get_tmux_option "@swap_low_icon" "$swap_low_default_icon") + swap_medium_icon=$(get_tmux_option "@swap_medium_icon" "$swap_medium_default_icon") + swap_high_icon=$(get_tmux_option "@swap_high_icon" "$swap_high_default_icon") +} + +print_icon() { + local swap_percentage=$($CURRENT_DIR/swap_percentage.sh | sed -e 's/%//') + local load_status=$(load_status $swap_percentage) + if [ $load_status == "low" ]; then + echo "$swap_low_icon" + elif [ $load_status == "medium" ]; then + echo "$swap_medium_icon" + elif [ $load_status == "high" ]; then + echo "$swap_high_icon" + fi +} + +main() { + get_icon_settings + print_icon "$1" +} +main diff --git a/scripts/swap_percentage.sh b/scripts/swap_percentage.sh new file mode 100644 index 0000000..f49046b --- /dev/null +++ b/scripts/swap_percentage.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +swap_percentage_format="%3.1f%%" + +print_swap_percentage() { + swap_percentage_format=$(get_tmux_option "@swap_percentage_format" "$swap_percentage_format") + + if command_exists "free"; then + free -t | awk 'NR == 3 {printf("Current Swap Utilization is : %.2f%"), $3/$2*100}' + elif command_exists "cuda-smi"; then + free -t | awk 'NR == 3 {printf("Current Swap Utilization is : %.2f%"), $3/$2*100}' + else + echo "No SWAP" + return + fi + echo "$loads" | awk -v format="$swap_percentage_format" '{used+=$1; tot+=$2} END {printf format, 100*$1/$2}' +} + +main() { + print_swap_percentage +} +main