├── .editorconfig ├── .github └── workflows │ └── check.yml ├── .mailmap ├── LICENSE ├── README.md ├── cpu.tmux ├── screenshots ├── high_bg.png ├── high_fg.png ├── high_icon.png ├── low_bg.png ├── low_fg.png ├── low_icon.png ├── medium_bg.png ├── medium_fg.png └── medium_icon.png └── scripts ├── cpu_bg_color.sh ├── cpu_fg_color.sh ├── cpu_icon.sh ├── cpu_percentage.sh ├── cpu_temp.sh ├── cpu_temp_bg_color.sh ├── cpu_temp_fg_color.sh ├── cpu_temp_icon.sh ├── gpu_bg_color.sh ├── gpu_fg_color.sh ├── gpu_icon.sh ├── gpu_percentage.sh ├── gpu_temp.sh ├── gpu_temp_bg_color.sh ├── gpu_temp_fg_color.sh ├── gpu_temp_icon.sh ├── gram_bg_color.sh ├── gram_fg_color.sh ├── gram_icon.sh ├── gram_percentage.sh ├── helpers.sh ├── ram_bg_color.sh ├── ram_fg_color.sh ├── ram_icon.sh └── ram_percentage.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | 13 | # 2 space indentation 14 | [*.{sh,tmux}] 15 | indent_style = space 16 | indent_size = 2 17 | -------------------------------------------------------------------------------- /.github/workflows/check.yml: -------------------------------------------------------------------------------- 1 | name: Check 2 | on: 3 | push: 4 | pull_request: 5 | jobs: 6 | lint: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: luizm/action-sh-checker@master 11 | env: 12 | SHELLCHECK_OPTS: -x 13 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Camille TJHOA 2 | Yuichi Kiri 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 ctjhoa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tmux CPU and GPU status 2 | 3 | Enables displaying CPU and GPU information in Tmux `status-right` and `status-left`. 4 | Configurable percentage and icon display. 5 | 6 | ## Installation 7 | ### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) 8 | 9 | Add plugin to the list of TPM plugins in `.tmux.conf`: 10 | 11 | ```shell 12 | set -g @plugin 'tmux-plugins/tmux-cpu' 13 | ``` 14 | 15 | Hit `prefix + I` to fetch the plugin and source it. 16 | 17 | If format strings are added to `status-right`, they should now be visible. 18 | 19 | ### Manual Installation 20 | 21 | Clone the repo: 22 | 23 | ```shell 24 | $ git clone https://github.com/tmux-plugins/tmux-cpu ~/clone/path 25 | ``` 26 | 27 | Add this line to the bottom of `.tmux.conf`: 28 | 29 | ```shell 30 | run-shell ~/clone/path/cpu.tmux 31 | ``` 32 | 33 | Reload TMUX environment: 34 | 35 | ```shell 36 | # type this in terminal 37 | $ tmux source-file ~/.tmux.conf 38 | ``` 39 | 40 | If format strings are added to `status-right`, they should now be visible. 41 | 42 | ### Optional requirements (Linux, BSD, OSX) 43 | 44 | - `iostat` or `sar` are the best way to get an accurate CPU percentage. 45 | A fallback is included using `ps aux` but could be inaccurate. 46 | - `free` is used for obtaining system RAM status. 47 | - `lm-sensors` is used for CPU temperature. 48 | - `nvidia-smi` is required for GPU information. 49 | For OSX, `cuda-smi` is required instead (but only shows GPU memory use rather than load). 50 | If "No GPU" is displayed, it means the script was not able to find `nvidia-smi`/`cuda-smi`. 51 | Please make sure the appropriate command is installed and in the `$PATH`. 52 | 53 | ## Usage 54 | 55 | Add any of the supported format strings (see below) to the existing `status-right` tmux option. 56 | Example: 57 | 58 | ```shell 59 | # in .tmux.conf 60 | set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M ' 61 | ``` 62 | 63 | ### Supported Options 64 | 65 | This is done by introducing 12 new format strings that can be added to 66 | `status-right` option: 67 | 68 | - `#{cpu_icon}` - will display a CPU status icon 69 | - `#{cpu_percentage}` - will show CPU percentage (averaged across cores) 70 | - `#{cpu_bg_color}` - will change the background color based on the CPU percentage 71 | - `#{cpu_fg_color}` - will change the foreground color based on the CPU percentage 72 | - `#{ram_icon}` - will display a RAM status icon 73 | - `#{ram_percentage}` - will show RAM percentage (averaged across cores) 74 | - `#{ram_bg_color}` - will change the background color based on the RAM percentage 75 | - `#{ram_fg_color}` - will change the foreground color based on the RAM percentage 76 | - `#{cpu_temp_icon}` - will display a CPU temperature status icon 77 | - `#{cpu_temp}` - will show CPU temperature (averaged across cores) 78 | - `#{cpu_temp_bg_color}` - will change the background color based on the CPU temperature 79 | - `#{cpu_temp_fg_color}` - will change the foreground color based on the CPU temperature 80 | 81 | GPU equivalents also exist: 82 | 83 | - `#{gpu_icon}` - will display a GPU status icon 84 | - `#{gpu_percentage}` - will show GPU percentage (averaged across devices) 85 | - `#{gpu_bg_color}` - will change the background color based on the GPU percentage 86 | - `#{gpu_fg_color}` - will change the foreground color based on the GPU percentage 87 | - `#{gram_icon}` - will display a GPU RAM status icon 88 | - `#{gram_percentage}` - will show GPU RAM percentage (total across devices) 89 | - `#{gram_bg_color}` - will change the background color based on the GPU RAM percentage 90 | - `#{gram_fg_color}` - will change the foreground color based on the GPU RAM percentage 91 | - `#{gpu_temp_icon}` - will display a GPU temperature status icon 92 | - `#{gpu_temp}` - will show GPU temperature (average across devices) 93 | - `#{gpu_temp_bg_color}` - will change the background color based on the GPU temperature 94 | - `#{gpu_temp_fg_color}` - will change the foreground color based on the GPU temperature 95 | 96 | ## Examples 97 | 98 | CPU usage lower than 30%:
99 | ![low_fg](/screenshots/low_fg.png) 100 | ![low_bg](/screenshots/low_bg.png) 101 | ![low_icon](/screenshots/low_icon.png) 102 | 103 | CPU usage between 30% and 80%:
104 | ![medium_fg](/screenshots/medium_fg.png) 105 | ![medium_bg](/screenshots/medium_bg.png) 106 | ![medium_icon](/screenshots/medium_icon.png) 107 | 108 | CPU usage higher than 80%:
109 | ![high_fg](/screenshots/high_fg.png) 110 | ![high_bg](/screenshots/high_bg.png) 111 | ![high_icon](/screenshots/high_icon.png) 112 | 113 | ## Customization 114 | 115 | Here are all available options with their default values: 116 | 117 | ```shell 118 | @cpu_low_icon "=" # icon when cpu is low 119 | @cpu_medium_icon "≡" # icon when cpu is medium 120 | @cpu_high_icon "≣" # icon when cpu is high 121 | 122 | @cpu_low_fg_color "" # foreground color when cpu is low 123 | @cpu_medium_fg_color "" # foreground color when cpu is medium 124 | @cpu_high_fg_color "" # foreground color when cpu is high 125 | 126 | @cpu_low_bg_color "#[bg=green]" # background color when cpu is low 127 | @cpu_medium_bg_color "#[bg=yellow]" # background color when cpu is medium 128 | @cpu_high_bg_color "#[bg=red]" # background color when cpu is high 129 | 130 | @cpu_percentage_format "%3.1f%%" # printf format to use to display percentage 131 | 132 | @cpu_medium_thresh "30" # medium percentage threshold 133 | @cpu_high_thresh "80" # high percentage threshold 134 | 135 | @ram_(low_icon,high_bg_color,etc...) # same defaults as above 136 | 137 | @cpu_temp_format "%2.0f" # printf format to use to display temperature 138 | @cpu_temp_unit "C" # supports C & F 139 | 140 | @cpu_temp_medium_thresh "80" # medium temperature threshold 141 | @cpu_temp_high_thresh "90" # high temperature threshold 142 | 143 | @cpu_temp_(low_icon,high_bg_color,etc...) # same defaults as above 144 | ``` 145 | 146 | All `@cpu_*` options are valid with `@gpu_*` (except `@cpu_*_thresh` which apply to both CPU and GPU). Additionally, `@ram_*` options become `@gram_*` for GPU equivalents. 147 | 148 | Note that these colors depend on your terminal / X11 config. 149 | 150 | You can can customize each one of these options in your `.tmux.conf`, for example: 151 | 152 | ```shell 153 | set -g @cpu_low_fg_color "#[fg=#00ff00]" 154 | set -g @cpu_percentage_format "%5.1f%%" # Add left padding 155 | ``` 156 | 157 | Don't forget to reload the tmux environment (`$ tmux source-file ~/.tmux.conf`) after you do this. 158 | 159 | ### Tmux Plugins 160 | 161 | This plugin is part of the [tmux-plugins](https://github.com/tmux-plugins) organisation. Checkout plugins as [battery](https://github.com/tmux-plugins/tmux-battery), [logging](https://github.com/tmux-plugins/tmux-logging), [online status](https://github.com/tmux-plugins/tmux-online-status), and many more over at the [tmux-plugins](https://github.com/tmux-plugins) organisation page. 162 | 163 | ### Maintainers 164 | 165 | - [Camille Tjhoa](https://github.com/ctjhoa) 166 | - [Casper da Costa-Luis](https://github.com/casperdcl) 167 | 168 | ### License 169 | 170 | [MIT](LICENSE.md) 171 | -------------------------------------------------------------------------------- /cpu.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | source "$CURRENT_DIR/scripts/helpers.sh" 6 | 7 | cpu_interpolation=( 8 | "\#{cpu_percentage}" 9 | "\#{cpu_icon}" 10 | "\#{cpu_bg_color}" 11 | "\#{cpu_fg_color}" 12 | "\#{gpu_percentage}" 13 | "\#{gpu_icon}" 14 | "\#{gpu_bg_color}" 15 | "\#{gpu_fg_color}" 16 | "\#{ram_percentage}" 17 | "\#{ram_icon}" 18 | "\#{ram_bg_color}" 19 | "\#{ram_fg_color}" 20 | "\#{gram_percentage}" 21 | "\#{gram_icon}" 22 | "\#{gram_bg_color}" 23 | "\#{gram_fg_color}" 24 | "\#{cpu_temp}" 25 | "\#{cpu_temp_icon}" 26 | "\#{cpu_temp_bg_color}" 27 | "\#{cpu_temp_fg_color}" 28 | "\#{gpu_temp}" 29 | "\#{gpu_temp_icon}" 30 | "\#{gpu_temp_bg_color}" 31 | "\#{gpu_temp_fg_color}" 32 | ) 33 | cpu_commands=( 34 | "#($CURRENT_DIR/scripts/cpu_percentage.sh)" 35 | "#($CURRENT_DIR/scripts/cpu_icon.sh)" 36 | "#($CURRENT_DIR/scripts/cpu_bg_color.sh)" 37 | "#($CURRENT_DIR/scripts/cpu_fg_color.sh)" 38 | "#($CURRENT_DIR/scripts/gpu_percentage.sh)" 39 | "#($CURRENT_DIR/scripts/gpu_icon.sh)" 40 | "#($CURRENT_DIR/scripts/gpu_bg_color.sh)" 41 | "#($CURRENT_DIR/scripts/gpu_fg_color.sh)" 42 | "#($CURRENT_DIR/scripts/ram_percentage.sh)" 43 | "#($CURRENT_DIR/scripts/ram_icon.sh)" 44 | "#($CURRENT_DIR/scripts/ram_bg_color.sh)" 45 | "#($CURRENT_DIR/scripts/ram_fg_color.sh)" 46 | "#($CURRENT_DIR/scripts/gram_percentage.sh)" 47 | "#($CURRENT_DIR/scripts/gram_icon.sh)" 48 | "#($CURRENT_DIR/scripts/gram_bg_color.sh)" 49 | "#($CURRENT_DIR/scripts/gram_fg_color.sh)" 50 | "#($CURRENT_DIR/scripts/cpu_temp.sh)" 51 | "#($CURRENT_DIR/scripts/cpu_temp_icon.sh)" 52 | "#($CURRENT_DIR/scripts/cpu_temp_bg_color.sh)" 53 | "#($CURRENT_DIR/scripts/cpu_temp_fg_color.sh)" 54 | "#($CURRENT_DIR/scripts/gpu_temp.sh)" 55 | "#($CURRENT_DIR/scripts/gpu_temp_icon.sh)" 56 | "#($CURRENT_DIR/scripts/gpu_temp_bg_color.sh)" 57 | "#($CURRENT_DIR/scripts/gpu_temp_fg_color.sh)" 58 | ) 59 | 60 | set_tmux_option() { 61 | local option=$1 62 | local value=$2 63 | tmux set-option -gq "$option" "$value" 64 | } 65 | 66 | do_interpolation() { 67 | local all_interpolated="$1" 68 | for ((i = 0; i < ${#cpu_commands[@]}; i++)); do 69 | all_interpolated=${all_interpolated//${cpu_interpolation[$i]}/${cpu_commands[$i]}} 70 | done 71 | echo "$all_interpolated" 72 | } 73 | 74 | update_tmux_option() { 75 | local option 76 | local option_value 77 | local new_option_value 78 | option=$1 79 | option_value=$(get_tmux_option "$option") 80 | new_option_value=$(do_interpolation "$option_value") 81 | set_tmux_option "$option" "$new_option_value" 82 | } 83 | 84 | main() { 85 | update_tmux_option "status-right" 86 | update_tmux_option "status-left" 87 | } 88 | main 89 | -------------------------------------------------------------------------------- /screenshots/high_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/high_bg.png -------------------------------------------------------------------------------- /screenshots/high_fg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/high_fg.png -------------------------------------------------------------------------------- /screenshots/high_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/high_icon.png -------------------------------------------------------------------------------- /screenshots/low_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/low_bg.png -------------------------------------------------------------------------------- /screenshots/low_fg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/low_fg.png -------------------------------------------------------------------------------- /screenshots/low_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/low_icon.png -------------------------------------------------------------------------------- /screenshots/medium_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/medium_bg.png -------------------------------------------------------------------------------- /screenshots/medium_fg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/medium_fg.png -------------------------------------------------------------------------------- /screenshots/medium_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-cpu/bcb110d754ab2417de824c464730c412a3eb2769/screenshots/medium_icon.png -------------------------------------------------------------------------------- /scripts/cpu_bg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | cpu_low_bg_color="" 9 | cpu_medium_bg_color="" 10 | cpu_high_bg_color="" 11 | 12 | cpu_low_default_bg_color="#[bg=green]" 13 | cpu_medium_default_bg_color="#[bg=yellow]" 14 | cpu_high_default_bg_color="#[bg=red]" 15 | 16 | get_bg_color_settings() { 17 | cpu_low_bg_color=$(get_tmux_option "@cpu_low_bg_color" "$cpu_low_default_bg_color") 18 | cpu_medium_bg_color=$(get_tmux_option "@cpu_medium_bg_color" "$cpu_medium_default_bg_color") 19 | cpu_high_bg_color=$(get_tmux_option "@cpu_high_bg_color" "$cpu_high_default_bg_color") 20 | } 21 | 22 | print_bg_color() { 23 | local cpu_percentage 24 | local load_status 25 | cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//') 26 | load_status=$(load_status "$cpu_percentage" "cpu") 27 | if [ "$load_status" == "low" ]; then 28 | echo "$cpu_low_bg_color" 29 | elif [ "$load_status" == "medium" ]; then 30 | echo "$cpu_medium_bg_color" 31 | elif [ "$load_status" == "high" ]; then 32 | echo "$cpu_high_bg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_bg_color_settings 38 | print_bg_color 39 | } 40 | main "$@" 41 | -------------------------------------------------------------------------------- /scripts/cpu_fg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | cpu_low_fg_color="" 9 | cpu_medium_fg_color="" 10 | cpu_high_fg_color="" 11 | 12 | cpu_low_default_fg_color="#[fg=green]" 13 | cpu_medium_default_fg_color="#[fg=yellow]" 14 | cpu_high_default_fg_color="#[fg=red]" 15 | 16 | get_fg_color_settings() { 17 | cpu_low_fg_color=$(get_tmux_option "@cpu_low_fg_color" "$cpu_low_default_fg_color") 18 | cpu_medium_fg_color=$(get_tmux_option "@cpu_medium_fg_color" "$cpu_medium_default_fg_color") 19 | cpu_high_fg_color=$(get_tmux_option "@cpu_high_fg_color" "$cpu_high_default_fg_color") 20 | } 21 | 22 | print_fg_color() { 23 | local cpu_percentage 24 | local load_status 25 | cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//') 26 | load_status=$(load_status "$cpu_percentage" "cpu") 27 | if [ "$load_status" == "low" ]; then 28 | echo "$cpu_low_fg_color" 29 | elif [ "$load_status" == "medium" ]; then 30 | echo "$cpu_medium_fg_color" 31 | elif [ "$load_status" == "high" ]; then 32 | echo "$cpu_high_fg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_fg_color_settings 38 | print_fg_color 39 | } 40 | main "$@" 41 | -------------------------------------------------------------------------------- /scripts/cpu_icon.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | # script global variables 9 | cpu_low_icon="" 10 | cpu_medium_icon="" 11 | cpu_high_icon="" 12 | 13 | cpu_low_default_icon="=" 14 | cpu_medium_default_icon="≡" 15 | cpu_high_default_icon="≣" 16 | 17 | # icons are set as script global variables 18 | get_icon_settings() { 19 | cpu_low_icon=$(get_tmux_option "@cpu_low_icon" "$cpu_low_default_icon") 20 | cpu_medium_icon=$(get_tmux_option "@cpu_medium_icon" "$cpu_medium_default_icon") 21 | cpu_high_icon=$(get_tmux_option "@cpu_high_icon" "$cpu_high_default_icon") 22 | } 23 | 24 | print_icon() { 25 | local cpu_percentage 26 | local load_status 27 | cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//') 28 | load_status=$(load_status "$cpu_percentage" "cpu") 29 | if [ "$load_status" == "low" ]; then 30 | echo "$cpu_low_icon" 31 | elif [ "$load_status" == "medium" ]; then 32 | echo "$cpu_medium_icon" 33 | elif [ "$load_status" == "high" ]; then 34 | echo "$cpu_high_icon" 35 | fi 36 | } 37 | 38 | main() { 39 | get_icon_settings 40 | print_icon "$1" 41 | } 42 | main "$@" 43 | -------------------------------------------------------------------------------- /scripts/cpu_percentage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | cpu_percentage_format="%3.1f%%" 9 | 10 | print_cpu_percentage() { 11 | cpu_percentage_format=$(get_tmux_option "@cpu_percentage_format" "$cpu_percentage_format") 12 | 13 | if command_exists "iostat"; then 14 | 15 | if is_linux_iostat; then 16 | 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/,/./' 17 | elif is_osx; then 18 | 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/,/./' 19 | elif is_freebsd || is_openbsd; then 20 | 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/,/./' 21 | else 22 | echo "Unknown iostat version please create an issue" 23 | fi 24 | elif command_exists "sar"; then 25 | 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/,/./' 26 | else 27 | if is_cygwin; then 28 | usage="$(cached_eval WMIC cpu get LoadPercentage | grep -Eo '^[0-9]+')" 29 | # shellcheck disable=SC2059 30 | printf "$cpu_percentage_format" "$usage" 31 | else 32 | load=$(cached_eval ps aux | awk '{print $3}' | tail -n+2 | awk '{s+=$1} END {print s}') 33 | cpus=$(cpus_number) 34 | echo "$load $cpus" | awk -v format="$cpu_percentage_format" '{printf format, $1/$2}' 35 | fi 36 | fi 37 | } 38 | 39 | main() { 40 | print_cpu_percentage 41 | } 42 | main 43 | -------------------------------------------------------------------------------- /scripts/cpu_temp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | cpu_temp_format="%2.0f" 9 | cpu_temp_unit="C" 10 | 11 | print_cpu_temp() { 12 | cpu_temp_format=$(get_tmux_option "@cpu_temp_format" "$cpu_temp_format") 13 | cpu_temp_unit=$(get_tmux_option "@cpu_temp_unit" "$cpu_temp_unit") 14 | if command_exists "sensors"; then 15 | local val 16 | if [[ "$cpu_temp_unit" == F ]]; then 17 | val="$(sensors -f)" 18 | else 19 | val="$(sensors)" 20 | fi 21 | 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)}' 22 | fi 23 | } 24 | 25 | main() { 26 | print_cpu_temp 27 | } 28 | main 29 | -------------------------------------------------------------------------------- /scripts/cpu_temp_bg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | cpu_temp_low_bg_color="" 9 | cpu_temp_medium_bg_color="" 10 | cpu_temp_high_bg_color="" 11 | 12 | cpu_temp_low_default_bg_color="#[bg=green]" 13 | cpu_temp_medium_default_bg_color="#[bg=yellow]" 14 | cpu_temp_high_default_bg_color="#[bg=red]" 15 | 16 | get_bg_color_settings() { 17 | cpu_temp_low_bg_color=$(get_tmux_option "@cpu_temp_low_bg_color" "$cpu_temp_low_default_bg_color") 18 | cpu_temp_medium_bg_color=$(get_tmux_option "@cpu_temp_medium_bg_color" "$cpu_temp_medium_default_bg_color") 19 | cpu_temp_high_bg_color=$(get_tmux_option "@cpu_temp_high_bg_color" "$cpu_temp_high_default_bg_color") 20 | } 21 | 22 | print_bg_color() { 23 | local cpu_temp 24 | local cpu_temp_status 25 | cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//') 26 | cpu_temp_status=$(temp_status "$cpu_temp") 27 | if [ "$cpu_temp_status" == "low" ]; then 28 | echo "$cpu_temp_low_bg_color" 29 | elif [ "$cpu_temp_status" == "medium" ]; then 30 | echo "$cpu_temp_medium_bg_color" 31 | elif [ "$cpu_temp_status" == "high" ]; then 32 | echo "$cpu_temp_high_bg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_bg_color_settings 38 | print_bg_color 39 | } 40 | main 41 | -------------------------------------------------------------------------------- /scripts/cpu_temp_fg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | cpu_temp_low_fg_color="" 9 | cpu_temp_medium_fg_color="" 10 | cpu_temp_high_fg_color="" 11 | 12 | cpu_temp_low_default_fg_color="#[fg=green]" 13 | cpu_temp_medium_default_fg_color="#[fg=yellow]" 14 | cpu_temp_high_default_fg_color="#[fg=red]" 15 | 16 | get_fg_color_settings() { 17 | cpu_temp_low_fg_color=$(get_tmux_option "@cpu_temp_low_fg_color" "$cpu_temp_low_default_fg_color") 18 | cpu_temp_medium_fg_color=$(get_tmux_option "@cpu_temp_medium_fg_color" "$cpu_temp_medium_default_fg_color") 19 | cpu_temp_high_fg_color=$(get_tmux_option "@cpu_temp_high_fg_color" "$cpu_temp_high_default_fg_color") 20 | } 21 | 22 | print_fg_color() { 23 | local cpu_temp 24 | local cpu_temp_status 25 | cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//') 26 | cpu_temp_status=$(temp_status "$cpu_temp") 27 | if [ "$cpu_temp_status" == "low" ]; then 28 | echo "$cpu_temp_low_fg_color" 29 | elif [ "$cpu_temp_status" == "medium" ]; then 30 | echo "$cpu_temp_medium_fg_color" 31 | elif [ "$cpu_temp_status" == "high" ]; then 32 | echo "$cpu_temp_high_fg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_fg_color_settings 38 | print_fg_color 39 | } 40 | main 41 | -------------------------------------------------------------------------------- /scripts/cpu_temp_icon.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | # script global variables 9 | cpu_temp_low_icon="" 10 | cpu_temp_medium_icon="" 11 | cpu_temp_high_icon="" 12 | 13 | cpu_temp_low_default_icon="=" 14 | cpu_temp_medium_default_icon="≡" 15 | cpu_temp_high_default_icon="≣" 16 | 17 | # icons are set as script global variables 18 | get_icon_settings() { 19 | cpu_temp_low_icon=$(get_tmux_option "@cpu_temp_low_icon" "$cpu_temp_low_default_icon") 20 | cpu_temp_medium_icon=$(get_tmux_option "@cpu_temp_medium_icon" "$cpu_temp_medium_default_icon") 21 | cpu_temp_high_icon=$(get_tmux_option "@cpu_temp_high_icon" "$cpu_temp_high_default_icon") 22 | } 23 | 24 | print_icon() { 25 | local cpu_temp 26 | local cpu_temp_status 27 | cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//') 28 | cpu_temp_status=$(temp_status "$cpu_temp") 29 | if [ "$cpu_temp_status" == "low" ]; then 30 | echo "$cpu_temp_low_icon" 31 | elif [ "$cpu_temp_status" == "medium" ]; then 32 | echo "$cpu_temp_medium_icon" 33 | elif [ "$cpu_temp_status" == "high" ]; then 34 | echo "$cpu_temp_high_icon" 35 | fi 36 | } 37 | 38 | main() { 39 | get_icon_settings 40 | print_icon "$1" 41 | } 42 | main "$@" 43 | -------------------------------------------------------------------------------- /scripts/gpu_bg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gpu_low_bg_color="" 9 | gpu_medium_bg_color="" 10 | gpu_high_bg_color="" 11 | 12 | gpu_low_default_bg_color="#[bg=green]" 13 | gpu_medium_default_bg_color="#[bg=yellow]" 14 | gpu_high_default_bg_color="#[bg=red]" 15 | 16 | get_bg_color_settings() { 17 | gpu_low_bg_color=$(get_tmux_option "@gpu_low_bg_color" "$gpu_low_default_bg_color") 18 | gpu_medium_bg_color=$(get_tmux_option "@gpu_medium_bg_color" "$gpu_medium_default_bg_color") 19 | gpu_high_bg_color=$(get_tmux_option "@gpu_high_bg_color" "$gpu_high_default_bg_color") 20 | } 21 | 22 | print_bg_color() { 23 | local gpu_percentage 24 | local gpu_load_status 25 | gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//') 26 | gpu_load_status=$(load_status "$gpu_percentage" "gpu") 27 | if [ "$gpu_load_status" == "low" ]; then 28 | echo "$gpu_low_bg_color" 29 | elif [ "$gpu_load_status" == "medium" ]; then 30 | echo "$gpu_medium_bg_color" 31 | elif [ "$gpu_load_status" == "high" ]; then 32 | echo "$gpu_high_bg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_bg_color_settings 38 | print_bg_color 39 | } 40 | main "$@" 41 | -------------------------------------------------------------------------------- /scripts/gpu_fg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gpu_low_fg_color="" 9 | gpu_medium_fg_color="" 10 | gpu_high_fg_color="" 11 | 12 | gpu_low_default_fg_color="#[fg=green]" 13 | gpu_medium_default_fg_color="#[fg=yellow]" 14 | gpu_high_default_fg_color="#[fg=red]" 15 | 16 | get_fg_color_settings() { 17 | gpu_low_fg_color=$(get_tmux_option "@gpu_low_fg_color" "$gpu_low_default_fg_color") 18 | gpu_medium_fg_color=$(get_tmux_option "@gpu_medium_fg_color" "$gpu_medium_default_fg_color") 19 | gpu_high_fg_color=$(get_tmux_option "@gpu_high_fg_color" "$gpu_high_default_fg_color") 20 | } 21 | 22 | print_fg_color() { 23 | local gpu_percentage 24 | local gpu_load_status 25 | gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//') 26 | gpu_load_status=$(load_status "$gpu_percentage" "gpu") 27 | if [ "$gpu_load_status" == "low" ]; then 28 | echo "$gpu_low_fg_color" 29 | elif [ "$gpu_load_status" == "medium" ]; then 30 | echo "$gpu_medium_fg_color" 31 | elif [ "$gpu_load_status" == "high" ]; then 32 | echo "$gpu_high_fg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_fg_color_settings 38 | print_fg_color 39 | } 40 | main "$@" 41 | -------------------------------------------------------------------------------- /scripts/gpu_icon.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | # script global variables 9 | gpu_low_icon="" 10 | gpu_medium_icon="" 11 | gpu_high_icon="" 12 | 13 | gpu_low_default_icon="=" 14 | gpu_medium_default_icon="≡" 15 | gpu_high_default_icon="≣" 16 | 17 | # icons are set as script global variables 18 | get_icon_settings() { 19 | gpu_low_icon=$(get_tmux_option "@gpu_low_icon" "$gpu_low_default_icon") 20 | gpu_medium_icon=$(get_tmux_option "@gpu_medium_icon" "$gpu_medium_default_icon") 21 | gpu_high_icon=$(get_tmux_option "@gpu_high_icon" "$gpu_high_default_icon") 22 | } 23 | 24 | print_icon() { 25 | local gpu_percentage 26 | local gpu_load_status 27 | gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//') 28 | gpu_load_status=$(load_status "$gpu_percentage" "gpu") 29 | if [ "$gpu_load_status" == "low" ]; then 30 | echo "$gpu_low_icon" 31 | elif [ "$gpu_load_status" == "medium" ]; then 32 | echo "$gpu_medium_icon" 33 | elif [ "$gpu_load_status" == "high" ]; then 34 | echo "$gpu_high_icon" 35 | fi 36 | } 37 | 38 | main() { 39 | get_icon_settings 40 | print_icon "$1" 41 | } 42 | main "$@" 43 | -------------------------------------------------------------------------------- /scripts/gpu_percentage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gpu_percentage_format="%3.1f%%" 9 | 10 | print_gpu_percentage() { 11 | gpu_percentage_format=$(get_tmux_option "@gpu_percentage_format" "$gpu_percentage_format") 12 | 13 | if command_exists "nvidia-smi"; then 14 | loads=$(cached_eval nvidia-smi) 15 | elif command_exists "cuda-smi"; then 16 | loads=$(cached_eval cuda-smi) 17 | else 18 | echo "No GPU" 19 | return 20 | fi 21 | 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}' 22 | } 23 | 24 | main() { 25 | print_gpu_percentage 26 | } 27 | main 28 | -------------------------------------------------------------------------------- /scripts/gpu_temp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gpu_temp_format="%2.0f" 9 | gpu_temp_unit="C" 10 | 11 | print_gpu_temp() { 12 | gpu_temp_format=$(get_tmux_option "@gpu_temp_format" "$gpu_temp_format") 13 | gpu_temp_unit=$(get_tmux_option "@gpu_temp_unit" "$gpu_temp_unit") 14 | 15 | if command_exists "nvidia-smi"; then 16 | loads=$(cached_eval nvidia-smi) 17 | elif command_exists "cuda-smi"; then 18 | loads=$(cached_eval cuda-smi) 19 | else 20 | echo "No GPU" 21 | return 22 | fi 23 | tempC=$(echo "$loads" | sed -nr 's/.*\s([0-9]+)C.*/\1/p' | awk '{sum+=$1; n+=1} END {printf "%5.3f", sum/n}') 24 | if [ "$gpu_temp_unit" == "C" ]; then 25 | echo "$tempC" | awk -v format="${gpu_temp_format}C" '{sum+=$1} END {printf format, sum}' 26 | else 27 | echo "$tempC" | awk -v format="${gpu_temp_format}F" '{sum+=$1} END {printf format, sum*9/5+32}' 28 | fi 29 | } 30 | 31 | main() { 32 | print_gpu_temp 33 | } 34 | main "$@" 35 | -------------------------------------------------------------------------------- /scripts/gpu_temp_bg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gpu_temp_low_bg_color="" 9 | gpu_temp_medium_bg_color="" 10 | gpu_temp_high_bg_color="" 11 | 12 | gpu_temp_low_default_bg_color="#[bg=green]" 13 | gpu_temp_medium_default_bg_color="#[bg=yellow]" 14 | gpu_temp_high_default_bg_color="#[bg=red]" 15 | 16 | get_bg_color_settings() { 17 | gpu_temp_low_bg_color=$(get_tmux_option "@gpu_temp_low_bg_color" "$gpu_temp_low_default_bg_color") 18 | gpu_temp_medium_bg_color=$(get_tmux_option "@gpu_temp_medium_bg_color" "$gpu_temp_medium_default_bg_color") 19 | gpu_temp_high_bg_color=$(get_tmux_option "@gpu_temp_high_bg_color" "$gpu_temp_high_default_bg_color") 20 | } 21 | 22 | print_bg_color() { 23 | local gpu_temp 24 | local gpu_temp_status 25 | gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//') 26 | gpu_temp_status=$(temp_status "$gpu_temp") 27 | if [ "$gpu_temp_status" == "low" ]; then 28 | echo "$gpu_temp_low_bg_color" 29 | elif [ "$gpu_temp_status" == "medium" ]; then 30 | echo "$gpu_temp_medium_bg_color" 31 | elif [ "$gpu_temp_status" == "high" ]; then 32 | echo "$gpu_temp_high_bg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_bg_color_settings 38 | print_bg_color 39 | } 40 | main "$@" 41 | -------------------------------------------------------------------------------- /scripts/gpu_temp_fg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gpu_temp_low_fg_color="" 9 | gpu_temp_medium_fg_color="" 10 | gpu_temp_high_fg_color="" 11 | 12 | gpu_temp_low_default_fg_color="#[fg=green]" 13 | gpu_temp_medium_default_fg_color="#[fg=yellow]" 14 | gpu_temp_high_default_fg_color="#[fg=red]" 15 | 16 | get_fg_color_settings() { 17 | gpu_temp_low_fg_color=$(get_tmux_option "@gpu_temp_low_fg_color" "$gpu_temp_low_default_fg_color") 18 | gpu_temp_medium_fg_color=$(get_tmux_option "@gpu_temp_medium_fg_color" "$gpu_temp_medium_default_fg_color") 19 | gpu_temp_high_fg_color=$(get_tmux_option "@gpu_temp_high_fg_color" "$gpu_temp_high_default_fg_color") 20 | } 21 | 22 | print_fg_color() { 23 | local gpu_temp 24 | local gpu_temp_status 25 | gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//') 26 | gpu_temp_status=$(temp_status "$gpu_temp") 27 | if [ "$gpu_temp_status" == "low" ]; then 28 | echo "$gpu_temp_low_fg_color" 29 | elif [ "$gpu_temp_status" == "medium" ]; then 30 | echo "$gpu_temp_medium_fg_color" 31 | elif [ "$gpu_temp_status" == "high" ]; then 32 | echo "$gpu_temp_high_fg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_fg_color_settings 38 | print_fg_color 39 | } 40 | main "$@" 41 | -------------------------------------------------------------------------------- /scripts/gpu_temp_icon.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | # script global variables 9 | gpu_temp_low_icon="" 10 | gpu_temp_medium_icon="" 11 | gpu_temp_high_icon="" 12 | 13 | gpu_temp_low_default_icon="=" 14 | gpu_temp_medium_default_icon="≡" 15 | gpu_temp_high_default_icon="≣" 16 | 17 | # icons are set as script global variables 18 | get_icon_settings() { 19 | gpu_temp_low_icon=$(get_tmux_option "@gpu_temp_low_icon" "$gpu_temp_low_default_icon") 20 | gpu_temp_medium_icon=$(get_tmux_option "@gpu_temp_medium_icon" "$gpu_temp_medium_default_icon") 21 | gpu_temp_high_icon=$(get_tmux_option "@gpu_temp_high_icon" "$gpu_temp_high_default_icon") 22 | } 23 | 24 | print_icon() { 25 | local gpu_temp 26 | local gpu_temp_status 27 | gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//') 28 | gpu_temp_status=$(temp_status "$gpu_temp") 29 | if [ "$gpu_temp_status" == "low" ]; then 30 | echo "$gpu_temp_low_icon" 31 | elif [ "$gpu_temp_status" == "medium" ]; then 32 | echo "$gpu_temp_medium_icon" 33 | elif [ "$gpu_temp_status" == "high" ]; then 34 | echo "$gpu_temp_high_icon" 35 | fi 36 | } 37 | 38 | main() { 39 | get_icon_settings 40 | print_icon "$1" 41 | } 42 | main "$@" 43 | -------------------------------------------------------------------------------- /scripts/gram_bg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gram_low_bg_color="" 9 | gram_medium_bg_color="" 10 | gram_high_bg_color="" 11 | 12 | gram_low_default_bg_color="#[bg=green]" 13 | gram_medium_default_bg_color="#[bg=yellow]" 14 | gram_high_default_bg_color="#[bg=red]" 15 | 16 | get_bg_color_settings() { 17 | gram_low_bg_color=$(get_tmux_option "@gram_low_bg_color" "$gram_low_default_bg_color") 18 | gram_medium_bg_color=$(get_tmux_option "@gram_medium_bg_color" "$gram_medium_default_bg_color") 19 | gram_high_bg_color=$(get_tmux_option "@gram_high_bg_color" "$gram_high_default_bg_color") 20 | } 21 | 22 | print_bg_color() { 23 | local gram_percentage 24 | local gram_load_status 25 | gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//') 26 | gram_load_status=$(load_status "$gram_percentage" "gram") 27 | if [ "$gram_load_status" == "low" ]; then 28 | echo "$gram_low_bg_color" 29 | elif [ "$gram_load_status" == "medium" ]; then 30 | echo "$gram_medium_bg_color" 31 | elif [ "$gram_load_status" == "high" ]; then 32 | echo "$gram_high_bg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_bg_color_settings 38 | print_bg_color 39 | } 40 | main "$@" 41 | -------------------------------------------------------------------------------- /scripts/gram_fg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gram_low_fg_color="" 9 | gram_medium_fg_color="" 10 | gram_high_fg_color="" 11 | 12 | gram_low_default_fg_color="#[fg=green]" 13 | gram_medium_default_fg_color="#[fg=yellow]" 14 | gram_high_default_fg_color="#[fg=red]" 15 | 16 | get_fg_color_settings() { 17 | gram_low_fg_color=$(get_tmux_option "@gram_low_fg_color" "$gram_low_default_fg_color") 18 | gram_medium_fg_color=$(get_tmux_option "@gram_medium_fg_color" "$gram_medium_default_fg_color") 19 | gram_high_fg_color=$(get_tmux_option "@gram_high_fg_color" "$gram_high_default_fg_color") 20 | } 21 | 22 | print_fg_color() { 23 | local gram_percentage 24 | local gram_load_status 25 | gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//') 26 | gram_load_status=$(load_status "$gram_percentage" "gram") 27 | if [ "$gram_load_status" == "low" ]; then 28 | echo "$gram_low_fg_color" 29 | elif [ "$gram_load_status" == "medium" ]; then 30 | echo "$gram_medium_fg_color" 31 | elif [ "$gram_load_status" == "high" ]; then 32 | echo "$gram_high_fg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_fg_color_settings 38 | print_fg_color 39 | } 40 | main "$@" 41 | -------------------------------------------------------------------------------- /scripts/gram_icon.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | # script global variables 9 | gram_low_icon="" 10 | gram_medium_icon="" 11 | gram_high_icon="" 12 | 13 | gram_low_default_icon="=" 14 | gram_medium_default_icon="≡" 15 | gram_high_default_icon="≣" 16 | 17 | # icons are set as script global variables 18 | get_icon_settings() { 19 | gram_low_icon=$(get_tmux_option "@gram_low_icon" "$gram_low_default_icon") 20 | gram_medium_icon=$(get_tmux_option "@gram_medium_icon" "$gram_medium_default_icon") 21 | gram_high_icon=$(get_tmux_option "@gram_high_icon" "$gram_high_default_icon") 22 | } 23 | 24 | print_icon() { 25 | local gram_percentage 26 | local gram_load_status 27 | gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//') 28 | gram_load_status=$(load_status "$gram_percentage" "gram") 29 | if [ "$gram_load_status" == "low" ]; then 30 | echo "$gram_low_icon" 31 | elif [ "$gram_load_status" == "medium" ]; then 32 | echo "$gram_medium_icon" 33 | elif [ "$gram_load_status" == "high" ]; then 34 | echo "$gram_high_icon" 35 | fi 36 | } 37 | 38 | main() { 39 | get_icon_settings 40 | print_icon "$1" 41 | } 42 | main "$@" 43 | -------------------------------------------------------------------------------- /scripts/gram_percentage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | gram_percentage_format="%3.1f%%" 9 | 10 | print_gram_percentage() { 11 | gram_percentage_format=$(get_tmux_option "@gram_percentage_format" "$gram_percentage_format") 12 | 13 | if command_exists "nvidia-smi"; then 14 | loads=$(cached_eval nvidia-smi | sed -nr 's/.*\s([0-9]+)MiB\s*\/\s*([0-9]+)MiB.*/\1 \2/p') 15 | elif command_exists "cuda-smi"; then 16 | loads=$(cached_eval cuda-smi | sed -nr 's/.*\s([0-9.]+) of ([0-9.]+) MB.*/\1 \2/p' | awk '{print $2-$1" "$2}') 17 | else 18 | echo "No GPU" 19 | return 20 | fi 21 | echo "$loads" | awk -v format="$gram_percentage_format" '{used+=$1; tot+=$2} END {printf format, 100*used/tot}' 22 | } 23 | 24 | main() { 25 | print_gram_percentage 26 | } 27 | main "$@" 28 | -------------------------------------------------------------------------------- /scripts/helpers.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | export LANG=C 4 | export LC_ALL=C 5 | 6 | get_tmux_option() { 7 | local option 8 | local default_value 9 | local option_value 10 | option="$1" 11 | default_value="$2" 12 | option_value="$(tmux show-option -qv "$option")" 13 | if [ -z "$option_value" ]; then 14 | option_value="$(tmux show-option -gqv "$option")" 15 | fi 16 | if [ -z "$option_value" ]; then 17 | echo "$default_value" 18 | else 19 | echo "$option_value" 20 | fi 21 | } 22 | 23 | is_osx() { 24 | [ "$(uname)" == "Darwin" ] 25 | } 26 | 27 | is_freebsd() { 28 | [ "$(uname)" == "FreeBSD" ] 29 | } 30 | 31 | is_openbsd() { 32 | [ "$(uname)" == "OpenBSD" ] 33 | } 34 | 35 | is_linux() { 36 | [ "$(uname)" == "Linux" ] 37 | } 38 | 39 | is_cygwin() { 40 | command -v WMIC &>/dev/null 41 | } 42 | 43 | is_linux_iostat() { 44 | # Bug in early versions of linux iostat -V return error code 45 | iostat -c &>/dev/null 46 | } 47 | 48 | # is second float bigger or equal? 49 | fcomp() { 50 | awk -v n1="$1" -v n2="$2" 'BEGIN {if (n1<=n2) exit 0; exit 1}' 51 | } 52 | 53 | load_status() { 54 | local percentage=$1 55 | local prefix=$2 56 | medium_thresh=$(get_tmux_option "@${prefix}_medium_thresh" "30") 57 | high_thresh=$(get_tmux_option "@${prefix}_high_thresh" "80") 58 | if fcomp "$high_thresh" "$percentage"; then 59 | echo "high" 60 | elif fcomp "$medium_thresh" "$percentage" && fcomp "$percentage" "$high_thresh"; then 61 | echo "medium" 62 | else 63 | echo "low" 64 | fi 65 | } 66 | 67 | temp_status() { 68 | local temp 69 | temp=$1 70 | cpu_temp_medium_thresh=$(get_tmux_option "@cpu_temp_medium_thresh" "80") 71 | cpu_temp_high_thresh=$(get_tmux_option "@cpu_temp_high_thresh" "90") 72 | if fcomp "$cpu_temp_high_thresh" "$temp"; then 73 | echo "high" 74 | elif fcomp "$cpu_temp_medium_thresh" "$temp" && fcomp "$temp" "$cpu_temp_high_thresh"; then 75 | echo "medium" 76 | else 77 | echo "low" 78 | fi 79 | } 80 | 81 | cpus_number() { 82 | if is_linux; then 83 | if command_exists "nproc"; then 84 | nproc 85 | else 86 | echo "$(($(sed -n 's/^processor.*:\s*\([0-9]\+\)/\1/p' /proc/cpuinfo | tail -n 1) + 1))" 87 | fi 88 | else 89 | sysctl -n hw.ncpu 90 | fi 91 | } 92 | 93 | command_exists() { 94 | local command 95 | command="$1" 96 | command -v "$command" &>/dev/null 97 | } 98 | 99 | get_tmp_dir() { 100 | local tmpdir 101 | tmpdir="${TMPDIR:-${TMP:-${TEMP:-/tmp}}}" 102 | [ -d "$tmpdir" ] || local tmpdir=~/tmp 103 | echo "$tmpdir/tmux-$EUID-cpu" 104 | } 105 | 106 | get_time() { 107 | date +%s.%N 108 | } 109 | 110 | get_cache_val() { 111 | local key 112 | local timeout 113 | local cache 114 | key="$1" 115 | # seconds after which cache is invalidated 116 | timeout="${2:-2}" 117 | cache="$(get_tmp_dir)/$key" 118 | if [ -f "$cache" ]; then 119 | awk -v cache="$(head -n1 "$cache")" -v timeout="$timeout" -v now="$(get_time)" \ 120 | 'BEGIN {if (now - timeout < cache) exit 0; exit 1}' && 121 | tail -n+2 "$cache" 122 | fi 123 | } 124 | 125 | put_cache_val() { 126 | local key 127 | local val 128 | local tmpdir 129 | key="$1" 130 | val="${*:2}" 131 | tmpdir="$(get_tmp_dir)" 132 | [ ! -d "$tmpdir" ] && mkdir -p "$tmpdir" && chmod 0700 "$tmpdir" 133 | ( 134 | get_time 135 | echo -n "$val" 136 | ) >"$tmpdir/$key" 137 | echo -n "$val" 138 | } 139 | 140 | cached_eval() { 141 | local command 142 | local key 143 | local val 144 | command="$1" 145 | key="$(basename "$command")" 146 | val="$(get_cache_val "$key")" 147 | if [ -z "$val" ]; then 148 | put_cache_val "$key" "$($command "${@:2}")" 149 | else 150 | echo -n "$val" 151 | fi 152 | } 153 | -------------------------------------------------------------------------------- /scripts/ram_bg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | ram_low_bg_color="" 9 | ram_medium_bg_color="" 10 | ram_high_bg_color="" 11 | 12 | ram_low_default_bg_color="#[bg=green]" 13 | ram_medium_default_bg_color="#[bg=yellow]" 14 | ram_high_default_bg_color="#[bg=red]" 15 | 16 | get_bg_color_settings() { 17 | ram_low_bg_color=$(get_tmux_option "@ram_low_bg_color" "$ram_low_default_bg_color") 18 | ram_medium_bg_color=$(get_tmux_option "@ram_medium_bg_color" "$ram_medium_default_bg_color") 19 | ram_high_bg_color=$(get_tmux_option "@ram_high_bg_color" "$ram_high_default_bg_color") 20 | } 21 | 22 | print_bg_color() { 23 | local ram_percentage 24 | local ram_load_status 25 | ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//') 26 | ram_load_status=$(load_status "$ram_percentage" "ram") 27 | if [ "$ram_load_status" == "low" ]; then 28 | echo "$ram_low_bg_color" 29 | elif [ "$ram_load_status" == "medium" ]; then 30 | echo "$ram_medium_bg_color" 31 | elif [ "$ram_load_status" == "high" ]; then 32 | echo "$ram_high_bg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_bg_color_settings 38 | print_bg_color 39 | } 40 | main 41 | -------------------------------------------------------------------------------- /scripts/ram_fg_color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | ram_low_fg_color="" 9 | ram_medium_fg_color="" 10 | ram_high_fg_color="" 11 | 12 | ram_low_default_fg_color="#[fg=green]" 13 | ram_medium_default_fg_color="#[fg=yellow]" 14 | ram_high_default_fg_color="#[fg=red]" 15 | 16 | get_fg_color_settings() { 17 | ram_low_fg_color=$(get_tmux_option "@ram_low_fg_color" "$ram_low_default_fg_color") 18 | ram_medium_fg_color=$(get_tmux_option "@ram_medium_fg_color" "$ram_medium_default_fg_color") 19 | ram_high_fg_color=$(get_tmux_option "@ram_high_fg_color" "$ram_high_default_fg_color") 20 | } 21 | 22 | print_fg_color() { 23 | local ram_percentage 24 | local ram_load_status 25 | ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//') 26 | ram_load_status=$(load_status "$ram_percentage" "ram") 27 | if [ "$ram_load_status" == "low" ]; then 28 | echo "$ram_low_fg_color" 29 | elif [ "$ram_load_status" == "medium" ]; then 30 | echo "$ram_medium_fg_color" 31 | elif [ "$ram_load_status" == "high" ]; then 32 | echo "$ram_high_fg_color" 33 | fi 34 | } 35 | 36 | main() { 37 | get_fg_color_settings 38 | print_fg_color 39 | } 40 | main 41 | -------------------------------------------------------------------------------- /scripts/ram_icon.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | # script global variables 9 | ram_low_icon="" 10 | ram_medium_icon="" 11 | ram_high_icon="" 12 | 13 | ram_low_default_icon="=" 14 | ram_medium_default_icon="≡" 15 | ram_high_default_icon="≣" 16 | 17 | # icons are set as script global variables 18 | get_icon_settings() { 19 | ram_low_icon=$(get_tmux_option "@ram_low_icon" "$ram_low_default_icon") 20 | ram_medium_icon=$(get_tmux_option "@ram_medium_icon" "$ram_medium_default_icon") 21 | ram_high_icon=$(get_tmux_option "@ram_high_icon" "$ram_high_default_icon") 22 | } 23 | 24 | print_icon() { 25 | local ram_percentage 26 | local ram_load_status 27 | ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//') 28 | ram_load_status=$(load_status "$ram_percentage" "ram") 29 | if [ "$ram_load_status" == "low" ]; then 30 | echo "$ram_low_icon" 31 | elif [ "$ram_load_status" == "medium" ]; then 32 | echo "$ram_medium_icon" 33 | elif [ "$ram_load_status" == "high" ]; then 34 | echo "$ram_high_icon" 35 | fi 36 | } 37 | 38 | main() { 39 | get_icon_settings 40 | print_icon "$1" 41 | } 42 | main "$@" 43 | -------------------------------------------------------------------------------- /scripts/ram_percentage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | # shellcheck source=scripts/helpers.sh 6 | source "$CURRENT_DIR/helpers.sh" 7 | 8 | ram_percentage_format="%3.1f%%" 9 | 10 | sum_macos_vm_stats() { 11 | grep -Eo '[0-9]+' | 12 | awk '{ a += $1 * 4096 } END { print a }' 13 | } 14 | 15 | print_ram_percentage() { 16 | ram_percentage_format=$(get_tmux_option "@ram_percentage_format" "$ram_percentage_format") 17 | 18 | if command_exists "free"; then 19 | cached_eval free | awk -v format="$ram_percentage_format" '$1 ~ /Mem/ {printf(format, 100*$3/$2)}' 20 | elif command_exists "vm_stat"; then 21 | # page size of 4096 bytes 22 | stats="$(cached_eval vm_stat)" 23 | 24 | used_and_cached=$( 25 | echo "$stats" | 26 | grep -E "(Pages active|Pages inactive|Pages speculative|Pages wired down|Pages occupied by compressor)" | 27 | sum_macos_vm_stats 28 | ) 29 | 30 | cached=$( 31 | echo "$stats" | 32 | grep -E "(Pages purgeable|File-backed pages)" | 33 | sum_macos_vm_stats 34 | ) 35 | 36 | free=$( 37 | echo "$stats" | 38 | grep -E "(Pages free)" | 39 | sum_macos_vm_stats 40 | ) 41 | 42 | used=$((used_and_cached - cached)) 43 | total=$((used_and_cached + free)) 44 | 45 | echo "$used $total" | awk -v format="$ram_percentage_format" '{printf(format, 100*$1/$2)}' 46 | fi 47 | } 48 | 49 | main() { 50 | print_ram_percentage 51 | } 52 | main 53 | --------------------------------------------------------------------------------