This commit is contained in:
Christian Nieves
2022-10-20 12:01:05 -05:00
parent b178f8c58f
commit 10714e9258
56 changed files with 811 additions and 266 deletions

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_low_bg_color=""
@ -19,13 +20,15 @@ get_bg_color_settings() {
}
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
local cpu_percentage
local load_status
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
load_status=$(load_status "$cpu_percentage" "cpu")
if [ "$load_status" == "low" ]; then
echo "$cpu_low_bg_color"
elif [ $load_status == "medium" ]; then
elif [ "$load_status" == "medium" ]; then
echo "$cpu_medium_bg_color"
elif [ $load_status == "high" ]; then
elif [ "$load_status" == "high" ]; then
echo "$cpu_high_bg_color"
fi
}
@ -34,4 +37,4 @@ main() {
get_bg_color_settings
print_bg_color
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_low_fg_color=""
@ -19,13 +20,15 @@ get_fg_color_settings() {
}
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
local cpu_percentage
local load_status
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
load_status=$(load_status "$cpu_percentage" "cpu")
if [ "$load_status" == "low" ]; then
echo "$cpu_low_fg_color"
elif [ $load_status == "medium" ]; then
elif [ "$load_status" == "medium" ]; then
echo "$cpu_medium_fg_color"
elif [ $load_status == "high" ]; then
elif [ "$load_status" == "high" ]; then
echo "$cpu_high_fg_color"
fi
}
@ -34,4 +37,4 @@ main() {
get_fg_color_settings
print_fg_color
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
@ -21,13 +22,15 @@ get_icon_settings() {
}
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
local cpu_percentage
local load_status
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
load_status=$(load_status "$cpu_percentage" "cpu")
if [ "$load_status" == "low" ]; then
echo "$cpu_low_icon"
elif [ $load_status == "medium" ]; then
elif [ "$load_status" == "medium" ]; then
echo "$cpu_medium_icon"
elif [ $load_status == "high" ]; then
elif [ "$load_status" == "high" ]; then
echo "$cpu_high_icon"
fi
}
@ -36,4 +39,4 @@ main() {
get_icon_settings
print_icon "$1"
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_percentage_format="%3.1f%%"
@ -25,9 +26,10 @@ print_cpu_percentage() {
else
if is_cygwin; then
usage="$(cached_eval WMIC cpu get LoadPercentage | grep -Eo '^[0-9]+')"
# shellcheck disable=SC2059
printf "$cpu_percentage_format" "$usage"
else
load=`cached_eval ps -aux | awk '{print $3}' | tail -n+2 | awk '{s+=$1} END {print s}'`
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

View File

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

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_temp_low_bg_color=""
@ -19,13 +20,15 @@ get_bg_color_settings() {
}
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
local cpu_temp
local cpu_temp_status
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
cpu_temp_status=$(temp_status "$cpu_temp")
if [ "$cpu_temp_status" == "low" ]; then
echo "$cpu_temp_low_bg_color"
elif [ $cpu_temp_status == "medium" ]; then
elif [ "$cpu_temp_status" == "medium" ]; then
echo "$cpu_temp_medium_bg_color"
elif [ $cpu_temp_status == "high" ]; then
elif [ "$cpu_temp_status" == "high" ]; then
echo "$cpu_temp_high_bg_color"
fi
}

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_temp_low_fg_color=""
@ -19,13 +20,15 @@ get_fg_color_settings() {
}
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
local cpu_temp
local cpu_temp_status
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
cpu_temp_status=$(temp_status "$cpu_temp")
if [ "$cpu_temp_status" == "low" ]; then
echo "$cpu_temp_low_fg_color"
elif [ $cpu_temp_status == "medium" ]; then
elif [ "$cpu_temp_status" == "medium" ]; then
echo "$cpu_temp_medium_fg_color"
elif [ $cpu_temp_status == "high" ]; then
elif [ "$cpu_temp_status" == "high" ]; then
echo "$cpu_temp_high_fg_color"
fi
}

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
@ -21,13 +22,15 @@ get_icon_settings() {
}
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
local cpu_temp
local cpu_temp_status
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
cpu_temp_status=$(temp_status "$cpu_temp")
if [ "$cpu_temp_status" == "low" ]; then
echo "$cpu_temp_low_icon"
elif [ $cpu_temp_status == "medium" ]; then
elif [ "$cpu_temp_status" == "medium" ]; then
echo "$cpu_temp_medium_icon"
elif [ $cpu_temp_status == "high" ]; then
elif [ "$cpu_temp_status" == "high" ]; then
echo "$cpu_temp_high_icon"
fi
}
@ -36,4 +39,4 @@ main() {
get_icon_settings
print_icon "$1"
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_low_bg_color=""
@ -19,13 +20,15 @@ get_bg_color_settings() {
}
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
local gpu_percentage
local gpu_load_status
gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//')
gpu_load_status=$(load_status "$gpu_percentage" "gpu")
if [ "$gpu_load_status" == "low" ]; then
echo "$gpu_low_bg_color"
elif [ $gpu_load_status == "medium" ]; then
elif [ "$gpu_load_status" == "medium" ]; then
echo "$gpu_medium_bg_color"
elif [ $gpu_load_status == "high" ]; then
elif [ "$gpu_load_status" == "high" ]; then
echo "$gpu_high_bg_color"
fi
}
@ -34,4 +37,4 @@ main() {
get_bg_color_settings
print_bg_color
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_low_fg_color=""
@ -19,13 +20,15 @@ get_fg_color_settings() {
}
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
local gpu_percentage
local gpu_load_status
gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//')
gpu_load_status=$(load_status "$gpu_percentage" "gpu")
if [ "$gpu_load_status" == "low" ]; then
echo "$gpu_low_fg_color"
elif [ $gpu_load_status == "medium" ]; then
elif [ "$gpu_load_status" == "medium" ]; then
echo "$gpu_medium_fg_color"
elif [ $gpu_load_status == "high" ]; then
elif [ "$gpu_load_status" == "high" ]; then
echo "$gpu_high_fg_color"
fi
}
@ -34,4 +37,4 @@ main() {
get_fg_color_settings
print_fg_color
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
@ -21,13 +22,15 @@ get_icon_settings() {
}
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
local gpu_percentage
local gpu_load_status
gpu_percentage=$("$CURRENT_DIR"/gpu_percentage.sh | sed -e 's/%//')
gpu_load_status=$(load_status "$gpu_percentage" "gpu")
if [ "$gpu_load_status" == "low" ]; then
echo "$gpu_low_icon"
elif [ $gpu_load_status == "medium" ]; then
elif [ "$gpu_load_status" == "medium" ]; then
echo "$gpu_medium_icon"
elif [ $gpu_load_status == "high" ]; then
elif [ "$gpu_load_status" == "high" ]; then
echo "$gpu_high_icon"
fi
}
@ -36,4 +39,4 @@ main() {
get_icon_settings
print_icon "$1"
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_percentage_format="%3.1f%%"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_temp_format="%2.0f"
@ -20,7 +21,7 @@ print_gpu_temp() {
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
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}'
@ -30,4 +31,4 @@ print_gpu_temp() {
main() {
print_gpu_temp
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_temp_low_bg_color=""
@ -19,13 +20,15 @@ get_bg_color_settings() {
}
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
local gpu_temp
local gpu_temp_status
gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//')
gpu_temp_status=$(temp_status "$gpu_temp")
if [ "$gpu_temp_status" == "low" ]; then
echo "$gpu_temp_low_bg_color"
elif [ $gpu_temp_status == "medium" ]; then
elif [ "$gpu_temp_status" == "medium" ]; then
echo "$gpu_temp_medium_bg_color"
elif [ $gpu_temp_status == "high" ]; then
elif [ "$gpu_temp_status" == "high" ]; then
echo "$gpu_temp_high_bg_color"
fi
}
@ -34,4 +37,4 @@ main() {
get_bg_color_settings
print_bg_color
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gpu_temp_low_fg_color=""
@ -19,13 +20,15 @@ get_fg_color_settings() {
}
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
local gpu_temp
local gpu_temp_status
gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//')
gpu_temp_status=$(temp_status "$gpu_temp")
if [ "$gpu_temp_status" == "low" ]; then
echo "$gpu_temp_low_fg_color"
elif [ $gpu_temp_status == "medium" ]; then
elif [ "$gpu_temp_status" == "medium" ]; then
echo "$gpu_temp_medium_fg_color"
elif [ $gpu_temp_status == "high" ]; then
elif [ "$gpu_temp_status" == "high" ]; then
echo "$gpu_temp_high_fg_color"
fi
}
@ -34,4 +37,4 @@ main() {
get_fg_color_settings
print_fg_color
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
@ -21,13 +22,15 @@ get_icon_settings() {
}
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
local gpu_temp
local gpu_temp_status
gpu_temp=$("$CURRENT_DIR"/gpu_temp.sh | sed -e 's/[^0-9.]//')
gpu_temp_status=$(temp_status "$gpu_temp")
if [ "$gpu_temp_status" == "low" ]; then
echo "$gpu_temp_low_icon"
elif [ $gpu_temp_status == "medium" ]; then
elif [ "$gpu_temp_status" == "medium" ]; then
echo "$gpu_temp_medium_icon"
elif [ $gpu_temp_status == "high" ]; then
elif [ "$gpu_temp_status" == "high" ]; then
echo "$gpu_temp_high_icon"
fi
}
@ -36,4 +39,4 @@ main() {
get_icon_settings
print_icon "$1"
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gram_low_bg_color=""
@ -19,13 +20,15 @@ get_bg_color_settings() {
}
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
local gram_percentage
local gram_load_status
gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//')
gram_load_status=$(load_status "$gram_percentage" "gram")
if [ "$gram_load_status" == "low" ]; then
echo "$gram_low_bg_color"
elif [ $gram_load_status == "medium" ]; then
elif [ "$gram_load_status" == "medium" ]; then
echo "$gram_medium_bg_color"
elif [ $gram_load_status == "high" ]; then
elif [ "$gram_load_status" == "high" ]; then
echo "$gram_high_bg_color"
fi
}
@ -34,4 +37,4 @@ main() {
get_bg_color_settings
print_bg_color
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gram_low_fg_color=""
@ -19,13 +20,15 @@ get_fg_color_settings() {
}
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
local gram_percentage
local gram_load_status
gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//')
gram_load_status=$(load_status "$gram_percentage" "gram")
if [ "$gram_load_status" == "low" ]; then
echo "$gram_low_fg_color"
elif [ $gram_load_status == "medium" ]; then
elif [ "$gram_load_status" == "medium" ]; then
echo "$gram_medium_fg_color"
elif [ $gram_load_status == "high" ]; then
elif [ "$gram_load_status" == "high" ]; then
echo "$gram_high_fg_color"
fi
}
@ -34,4 +37,4 @@ main() {
get_fg_color_settings
print_fg_color
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
@ -21,13 +22,15 @@ get_icon_settings() {
}
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
local gram_percentage
local gram_load_status
gram_percentage=$("$CURRENT_DIR"/gram_percentage.sh | sed -e 's/%//')
gram_load_status=$(load_status "$gram_percentage" "gram")
if [ "$gram_load_status" == "low" ]; then
echo "$gram_low_icon"
elif [ $gram_load_status == "medium" ]; then
elif [ "$gram_load_status" == "medium" ]; then
echo "$gram_medium_icon"
elif [ $gram_load_status == "high" ]; then
elif [ "$gram_load_status" == "high" ]; then
echo "$gram_high_icon"
fi
}
@ -36,4 +39,4 @@ main() {
get_icon_settings
print_icon "$1"
}
main
main "$@"

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gram_percentage_format="%3.1f%%"
@ -17,10 +18,10 @@ print_gram_percentage() {
echo "No GPU"
return
fi
echo "$loads" | awk -v format="$gram_percentage_format" '{used+=$1; tot+=$2} END {printf format, 100*$1/$2}'
echo "$loads" | awk -v format="$gram_percentage_format" '{used+=$1; tot+=$2} END {printf format, 100*used/tot}'
}
main() {
print_gram_percentage
}
main
main "$@"

View File

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

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
ram_low_bg_color=""
@ -19,13 +20,15 @@ get_bg_color_settings() {
}
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
local ram_percentage
local ram_load_status
ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//')
ram_load_status=$(load_status "$ram_percentage" "ram")
if [ "$ram_load_status" == "low" ]; then
echo "$ram_low_bg_color"
elif [ $ram_load_status == "medium" ]; then
elif [ "$ram_load_status" == "medium" ]; then
echo "$ram_medium_bg_color"
elif [ $ram_load_status == "high" ]; then
elif [ "$ram_load_status" == "high" ]; then
echo "$ram_high_bg_color"
fi
}

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
ram_low_fg_color=""
@ -19,13 +20,15 @@ get_fg_color_settings() {
}
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
local ram_percentage
local ram_load_status
ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//')
ram_load_status=$(load_status "$ram_percentage" "ram")
if [ "$ram_load_status" == "low" ]; then
echo "$ram_low_fg_color"
elif [ $ram_load_status == "medium" ]; then
elif [ "$ram_load_status" == "medium" ]; then
echo "$ram_medium_fg_color"
elif [ $ram_load_status == "high" ]; then
elif [ "$ram_load_status" == "high" ]; then
echo "$ram_high_fg_color"
fi
}

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
# script global variables
@ -21,13 +22,15 @@ get_icon_settings() {
}
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
local ram_percentage
local ram_load_status
ram_percentage=$("$CURRENT_DIR"/ram_percentage.sh | sed -e 's/%//')
ram_load_status=$(load_status "$ram_percentage" "ram")
if [ "$ram_load_status" == "low" ]; then
echo "$ram_low_icon"
elif [ $ram_load_status == "medium" ]; then
elif [ "$ram_load_status" == "medium" ]; then
echo "$ram_medium_icon"
elif [ $ram_load_status == "high" ]; then
elif [ "$ram_load_status" == "high" ]; then
echo "$ram_high_icon"
fi
}
@ -36,4 +39,4 @@ main() {
get_icon_settings
print_icon "$1"
}
main
main "$@"

View File

@ -1,14 +1,15 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
ram_percentage_format="%3.1f%%"
sum_macos_vm_stats() {
grep -Eo '[0-9]+' \
| awk '{ a += $1 * 4096 } END { print a }'
grep -Eo '[0-9]+' |
awk '{ a += $1 * 4096 } END { print a }'
}
print_ram_percentage() {
@ -20,23 +21,26 @@ print_ram_percentage() {
# 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 \
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 \
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 \
free=$(
echo "$stats" |
grep -E "(Pages free)" |
sum_macos_vm_stats
)
used=$(($used_and_cached - $cached))
total=$(($used_and_cached + $free))
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