Populate repo
This commit is contained in:
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_bg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
|
||||
local load_status=$(load_status $cpu_percentage)
|
||||
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
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_fg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
|
||||
local load_status=$(load_status $cpu_percentage)
|
||||
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
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_icon.sh
Executable file
39
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
|
||||
local load_status=$(load_status $cpu_percentage)
|
||||
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
|
40
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_percentage.sh
Executable file
40
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_percentage.sh
Executable file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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]+')"
|
||||
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
|
21
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp.sh
Executable file
21
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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
|
||||
([ "$cpu_temp_unit" == F ] && sensors -f || sensors) | 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
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_bg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_temp_low_bg_color=""
|
||||
cpu_temp_medium_bg_color=""
|
||||
cpu_temp_high_bg_color=""
|
||||
|
||||
cpu_temp_low_default_bg_color="#[bg=green]"
|
||||
cpu_temp_medium_default_bg_color="#[bg=yellow]"
|
||||
cpu_temp_high_default_bg_color="#[bg=red]"
|
||||
|
||||
get_bg_color_settings() {
|
||||
cpu_temp_low_bg_color=$(get_tmux_option "@cpu_temp_low_bg_color" "$cpu_temp_low_default_bg_color")
|
||||
cpu_temp_medium_bg_color=$(get_tmux_option "@cpu_temp_medium_bg_color" "$cpu_temp_medium_default_bg_color")
|
||||
cpu_temp_high_bg_color=$(get_tmux_option "@cpu_temp_high_bg_color" "$cpu_temp_high_default_bg_color")
|
||||
}
|
||||
|
||||
print_bg_color() {
|
||||
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local cpu_temp_status=$(temp_status $cpu_temp)
|
||||
if [ $cpu_temp_status == "low" ]; then
|
||||
echo "$cpu_temp_low_bg_color"
|
||||
elif [ $cpu_temp_status == "medium" ]; then
|
||||
echo "$cpu_temp_medium_bg_color"
|
||||
elif [ $cpu_temp_status == "high" ]; then
|
||||
echo "$cpu_temp_high_bg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_bg_color_settings
|
||||
print_bg_color
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_fg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_temp_low_fg_color=""
|
||||
cpu_temp_medium_fg_color=""
|
||||
cpu_temp_high_fg_color=""
|
||||
|
||||
cpu_temp_low_default_fg_color="#[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=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local cpu_temp_status=$(temp_status $cpu_temp)
|
||||
if [ $cpu_temp_status == "low" ]; then
|
||||
echo "$cpu_temp_low_fg_color"
|
||||
elif [ $cpu_temp_status == "medium" ]; then
|
||||
echo "$cpu_temp_medium_fg_color"
|
||||
elif [ $cpu_temp_status == "high" ]; then
|
||||
echo "$cpu_temp_high_fg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_fg_color_settings
|
||||
print_fg_color
|
||||
}
|
||||
main
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_icon.sh
Executable file
39
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
cpu_temp_low_icon=""
|
||||
cpu_temp_medium_icon=""
|
||||
cpu_temp_high_icon=""
|
||||
|
||||
cpu_temp_low_default_icon="="
|
||||
cpu_temp_medium_default_icon="≡"
|
||||
cpu_temp_high_default_icon="≣"
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_settings() {
|
||||
cpu_temp_low_icon=$(get_tmux_option "@cpu_temp_low_icon" "$cpu_temp_low_default_icon")
|
||||
cpu_temp_medium_icon=$(get_tmux_option "@cpu_temp_medium_icon" "$cpu_temp_medium_default_icon")
|
||||
cpu_temp_high_icon=$(get_tmux_option "@cpu_temp_high_icon" "$cpu_temp_high_default_icon")
|
||||
}
|
||||
|
||||
print_icon() {
|
||||
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local cpu_temp_status=$(temp_status $cpu_temp)
|
||||
if [ $cpu_temp_status == "low" ]; then
|
||||
echo "$cpu_temp_low_icon"
|
||||
elif [ $cpu_temp_status == "medium" ]; then
|
||||
echo "$cpu_temp_medium_icon"
|
||||
elif [ $cpu_temp_status == "high" ]; then
|
||||
echo "$cpu_temp_high_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_settings
|
||||
print_icon "$1"
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_bg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gpu_percentage.sh | sed -e 's/%//')
|
||||
local gpu_load_status=$(load_status $gpu_percentage)
|
||||
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
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_fg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gpu_percentage.sh | sed -e 's/%//')
|
||||
local gpu_load_status=$(load_status $gpu_percentage)
|
||||
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
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_icon.sh
Executable file
39
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gpu_percentage.sh | sed -e 's/%//')
|
||||
local gpu_load_status=$(load_status $gpu_percentage)
|
||||
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
|
26
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_percentage.sh
Executable file
26
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_percentage.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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
|
33
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp.sh
Executable file
33
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_bg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local 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
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_fg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local 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
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_icon.sh
Executable file
39
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local 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
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gram_bg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/gram_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(load_status $gram_percentage)
|
||||
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
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gram_fg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/gram_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(load_status $gram_percentage)
|
||||
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
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/gram_icon.sh
Executable file
39
tmux/.tmux/plugins/tmux-cpu/scripts/gram_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(load_status $gram_percentage)
|
||||
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
|
26
tmux/.tmux/plugins/tmux-cpu/scripts/gram_percentage.sh
Executable file
26
tmux/.tmux/plugins/tmux-cpu/scripts/gram_percentage.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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*$1/$2}'
|
||||
}
|
||||
|
||||
main() {
|
||||
print_gram_percentage
|
||||
}
|
||||
main
|
132
tmux/.tmux/plugins/tmux-cpu/scripts/helpers.sh
Normal file
132
tmux/.tmux/plugins/tmux-cpu/scripts/helpers.sh
Normal file
@ -0,0 +1,132 @@
|
||||
export LANG=C
|
||||
export LC_ALL=C
|
||||
|
||||
get_tmux_option() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local 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
|
||||
cpu_medium_thresh=$(get_tmux_option "@cpu_medium_thresh" "30")
|
||||
cpu_high_thresh=$(get_tmux_option "@cpu_high_thresh" "80")
|
||||
if fcomp $cpu_high_thresh $percentage; then
|
||||
echo "high"
|
||||
elif fcomp $cpu_medium_thresh $percentage && fcomp $percentage $cpu_high_thresh; then
|
||||
echo "medium"
|
||||
else
|
||||
echo "low"
|
||||
fi
|
||||
}
|
||||
|
||||
temp_status() {
|
||||
local 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="$1"
|
||||
command -v "$command" &> /dev/null
|
||||
}
|
||||
|
||||
get_tmp_dir() {
|
||||
local 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="$1"
|
||||
# seconds after which cache is invalidated
|
||||
local timeout="${2:-2}"
|
||||
local 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="$1"
|
||||
local val="${@:2}"
|
||||
local tmpdir="$(get_tmp_dir)"
|
||||
[ ! -d "$tmpdir" ] && mkdir -p "$tmpdir" && chmod 0700 "$tmpdir"
|
||||
echo "$(get_time)" > "$tmpdir/$key"
|
||||
echo -n "$val" >> "$tmpdir/$key"
|
||||
echo -n "$val"
|
||||
}
|
||||
|
||||
cached_eval(){
|
||||
local command="$1"
|
||||
local key="$(basename "$command")"
|
||||
local val="$(get_cache_val "$key")"
|
||||
if [ -z "$val" ]; then
|
||||
put_cache_val "$key" "$($command "${@:2}")"
|
||||
else
|
||||
echo -n "$val"
|
||||
fi
|
||||
}
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/ram_bg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/ram_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/ram_percentage.sh | sed -e 's/%//')
|
||||
local ram_load_status=$(load_status $ram_percentage)
|
||||
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
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/ram_fg_color.sh
Executable file
37
tmux/.tmux/plugins/tmux-cpu/scripts/ram_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/ram_percentage.sh | sed -e 's/%//')
|
||||
local ram_load_status=$(load_status $ram_percentage)
|
||||
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
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/ram_icon.sh
Executable file
39
tmux/.tmux/plugins/tmux-cpu/scripts/ram_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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=$($CURRENT_DIR/ram_percentage.sh | sed -e 's/%//')
|
||||
local ram_load_status=$(load_status $ram_percentage)
|
||||
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
|
48
tmux/.tmux/plugins/tmux-cpu/scripts/ram_percentage.sh
Executable file
48
tmux/.tmux/plugins/tmux-cpu/scripts/ram_percentage.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
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
|
Reference in New Issue
Block a user