Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Swap #68

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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%:<br/>
Expand Down
8 changes: 8 additions & 0 deletions cpu.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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() {
Expand Down
37 changes: 37 additions & 0 deletions scripts/swap_bg_color.sh
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions scripts/swap_fg_color.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions scripts/swap_icon.sh
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions scripts/swap_percentage.sh
Original file line number Diff line number Diff line change
@@ -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