diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..6a7de52 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,12 @@ +name: Check +on: + push: + pull_request: +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: luizm/action-sh-checker@master + env: + SHELLCHECK_OPTS: -x diff --git a/cpu.tmux b/cpu.tmux index 576c206..40d8124 100755 --- a/cpu.tmux +++ b/cpu.tmux @@ -1,6 +1,6 @@ #!/usr/bin/env bash -CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$CURRENT_DIR/scripts/helpers.sh" @@ -65,16 +65,19 @@ set_tmux_option() { do_interpolation() { local all_interpolated="$1" - for ((i=0; i<${#cpu_commands[@]}; i++)); do + for ((i = 0; i < ${#cpu_commands[@]}; i++)); do all_interpolated=${all_interpolated//${cpu_interpolation[$i]}/${cpu_commands[$i]}} done echo "$all_interpolated" } update_tmux_option() { - local option=$1 - local option_value=$(get_tmux_option "$option") - local new_option_value=$(do_interpolation "$option_value") + local option + local option_value + local new_option_value + option=$1 + option_value=$(get_tmux_option "$option") + new_option_value=$(do_interpolation "$option_value") set_tmux_option "$option" "$new_option_value" } diff --git a/scripts/cpu_bg_color.sh b/scripts/cpu_bg_color.sh index 0479e54..e072405 100755 --- a/scripts/cpu_bg_color.sh +++ b/scripts/cpu_bg_color.sh @@ -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 "cpu") - 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 "$@" diff --git a/scripts/cpu_fg_color.sh b/scripts/cpu_fg_color.sh index 4f1e98d..3afb80e 100755 --- a/scripts/cpu_fg_color.sh +++ b/scripts/cpu_fg_color.sh @@ -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 "cpu") - 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 "$@" diff --git a/scripts/cpu_icon.sh b/scripts/cpu_icon.sh index 2240640..99b9272 100755 --- a/scripts/cpu_icon.sh +++ b/scripts/cpu_icon.sh @@ -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 "cpu") - 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 "$@" diff --git a/scripts/cpu_percentage.sh b/scripts/cpu_percentage.sh index 7816e0e..15190f0 100755 --- a/scripts/cpu_percentage.sh +++ b/scripts/cpu_percentage.sh @@ -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 diff --git a/scripts/cpu_temp.sh b/scripts/cpu_temp.sh index e645ac5..94fdfda 100755 --- a/scripts/cpu_temp.sh +++ b/scripts/cpu_temp.sh @@ -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 + 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 } diff --git a/scripts/cpu_temp_bg_color.sh b/scripts/cpu_temp_bg_color.sh index 7cabaa2..c1fadd9 100755 --- a/scripts/cpu_temp_bg_color.sh +++ b/scripts/cpu_temp_bg_color.sh @@ -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 } diff --git a/scripts/cpu_temp_fg_color.sh b/scripts/cpu_temp_fg_color.sh index 73bb9bc..d5e4c6d 100755 --- a/scripts/cpu_temp_fg_color.sh +++ b/scripts/cpu_temp_fg_color.sh @@ -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 } diff --git a/scripts/cpu_temp_icon.sh b/scripts/cpu_temp_icon.sh index 85dfec0..93ad8df 100755 --- a/scripts/cpu_temp_icon.sh +++ b/scripts/cpu_temp_icon.sh @@ -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 "$@" diff --git a/scripts/gpu_bg_color.sh b/scripts/gpu_bg_color.sh index 9fd0c80..9b978fc 100755 --- a/scripts/gpu_bg_color.sh +++ b/scripts/gpu_bg_color.sh @@ -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 "gpu") - 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 "$@" diff --git a/scripts/gpu_fg_color.sh b/scripts/gpu_fg_color.sh index 3fd6ad3..aa02cf6 100755 --- a/scripts/gpu_fg_color.sh +++ b/scripts/gpu_fg_color.sh @@ -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 "gpu") - 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 "$@" diff --git a/scripts/gpu_icon.sh b/scripts/gpu_icon.sh index 7ce17ec..0bb52f4 100755 --- a/scripts/gpu_icon.sh +++ b/scripts/gpu_icon.sh @@ -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 "gpu") - 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 "$@" diff --git a/scripts/gpu_percentage.sh b/scripts/gpu_percentage.sh index d78dce1..e68785e 100755 --- a/scripts/gpu_percentage.sh +++ b/scripts/gpu_percentage.sh @@ -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%%" diff --git a/scripts/gpu_temp.sh b/scripts/gpu_temp.sh index ea9ed4d..05179a0 100755 --- a/scripts/gpu_temp.sh +++ b/scripts/gpu_temp.sh @@ -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 "$@" diff --git a/scripts/gpu_temp_bg_color.sh b/scripts/gpu_temp_bg_color.sh index 2bb5a70..57c566e 100755 --- a/scripts/gpu_temp_bg_color.sh +++ b/scripts/gpu_temp_bg_color.sh @@ -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 "$@" diff --git a/scripts/gpu_temp_fg_color.sh b/scripts/gpu_temp_fg_color.sh index 4b15d7f..5dc5094 100755 --- a/scripts/gpu_temp_fg_color.sh +++ b/scripts/gpu_temp_fg_color.sh @@ -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 "$@" diff --git a/scripts/gpu_temp_icon.sh b/scripts/gpu_temp_icon.sh index d4a162d..ece6487 100755 --- a/scripts/gpu_temp_icon.sh +++ b/scripts/gpu_temp_icon.sh @@ -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 "$@" diff --git a/scripts/gram_bg_color.sh b/scripts/gram_bg_color.sh index 224aab4..e8d95e6 100755 --- a/scripts/gram_bg_color.sh +++ b/scripts/gram_bg_color.sh @@ -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 "gram") - 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 "$@" diff --git a/scripts/gram_fg_color.sh b/scripts/gram_fg_color.sh index 387ae69..4f4d155 100755 --- a/scripts/gram_fg_color.sh +++ b/scripts/gram_fg_color.sh @@ -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 "gram") - 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 "$@" diff --git a/scripts/gram_icon.sh b/scripts/gram_icon.sh index f27aabe..04eb694 100755 --- a/scripts/gram_icon.sh +++ b/scripts/gram_icon.sh @@ -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 "gram") - 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 "$@" diff --git a/scripts/gram_percentage.sh b/scripts/gram_percentage.sh index 9588b43..93dd7a7 100755 --- a/scripts/gram_percentage.sh +++ b/scripts/gram_percentage.sh @@ -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%%" @@ -23,4 +24,4 @@ print_gram_percentage() { main() { print_gram_percentage } -main +main "$@" diff --git a/scripts/helpers.sh b/scripts/helpers.sh index a410a7e..6d72c46 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -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,33 +21,33 @@ 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() { @@ -50,9 +55,9 @@ load_status() { 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 + if fcomp "$high_thresh" "$percentage"; then echo "high" - elif fcomp $medium_thresh $percentage && fcomp $percentage $high_thresh; then + elif fcomp "$medium_thresh" "$percentage" && fcomp "$percentage" "$high_thresh"; then echo "medium" else echo "low" @@ -60,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" @@ -77,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 @@ -85,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" } @@ -99,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 diff --git a/scripts/ram_bg_color.sh b/scripts/ram_bg_color.sh index 5a2a2c5..57ae7e7 100755 --- a/scripts/ram_bg_color.sh +++ b/scripts/ram_bg_color.sh @@ -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 "ram") - 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 } diff --git a/scripts/ram_fg_color.sh b/scripts/ram_fg_color.sh index 6be021b..9d5a172 100755 --- a/scripts/ram_fg_color.sh +++ b/scripts/ram_fg_color.sh @@ -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 "ram") - 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 } diff --git a/scripts/ram_icon.sh b/scripts/ram_icon.sh index 9c3e454..5ad253b 100755 --- a/scripts/ram_icon.sh +++ b/scripts/ram_icon.sh @@ -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 "ram") - 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 "$@" diff --git a/scripts/ram_percentage.sh b/scripts/ram_percentage.sh index df31c2c..25c85cd 100755 --- a/scripts/ram_percentage.sh +++ b/scripts/ram_percentage.sh @@ -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