[OPEN] Polybar scripts all fail running in shellcheck, easily corrected, save tempcores.sh

Post your suggestions and improvements for future releases of ArcoLinux.
Post Reply
Poetician
Crewman
Posts: 116
Joined: Wed Sep 04, 2019 4:00 pm

ATM I have i3, awesomewm, bspwm, Herbie, and Hypr in my ArcoS installation. and the same in my alci installation with a few Arco repos enabled.
In the ALCI installation, the Arch-updates Polybar module does not display updates, though it responds to click open. So I started looking into this.
Because scripting and I will never get along, I ran it through shellcheck, which found and easily provided the following correction:

Code: Select all

$ shellcheck myscript
 
Line 9:
if [ $updates_arch -gt 0 ]; then
     ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
if [ "$updates_arch" -gt 0 ]; then
 
Line 10:
    echo $updates_arch
         ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
    echo "$updates_arch"
to this:

Code: Select all

#!/bin/sh
#source https://github.com/x70b1/polybar-scripts
#source https://github.com/polybar/polybar-scripts

if ! updates_arch=$(checkupdates 2> /dev/null | wc -l ); then
    updates_arch=0
fi

if [ $updates_arch -gt 0 ]; then
    echo $updates_arch
else
    echo "0"
fi
If this is innocuous, it ends here, because most of the other modules have similarly simple edits.

However, when I try this trick with tempcores, I get the following:

Code: Select all

$ shellcheck myscript
 
Line 8:
tempCore=($rawData)
          ^-- SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
 
Line 29:
sum=$(( $total/${#tempCore[*]} ))
        ^-- SC2004 (style): $/${} is unnecessary on arithmetic variables.
 
Line 43:
echo $finalEcho
     ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
echo "$finalEcho"
which I can reduce to this:

Code: Select all

$ shellcheck myscript
 
Line 8:
tempCore=($rawData)
          ^-- SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
 
Line 29:
sum=$(( $total/${#tempCore[*]} ))
        ^-- SC2004 (style): $/${} is unnecessary on arithmetic variables.
and that's where my knowledge stops. I have not checked for the Spotify scripts because I never use them.

For your consideration.
Ryzen 7 2700, 32GB Corsair Dominator 3200, MSI Armor RX-580, ASUS Crosshair Hero VII X470, Sabrent NVMe
Poetician
Crewman
Posts: 116
Joined: Wed Sep 04, 2019 4:00 pm

Solved by trial and error and reading the shellcheck output with every click.

Code: Select all

#!/bin/bash

# fork from Per-core temperatures :
# https://github.com/jaagr/polybar/wiki/User-contributed-modules#per-core-temperatures

# Get information from cores temp thanks to sensors
rawData=$( sensors | grep -m 1 Core | awk '{print substr($3, 2, length($3)-5)}' )
tempCore="($rawData)"

# Define constants :
degree="°C"
temperaturesValues=(40 50 60 70 80 90)
temperaturesColors=("#6bff49" "#f4cb24" "#ff8819" "#ff3205" "#f40202" "#ef02db")
temperaturesIcons=(     )

for iCore in ${!tempCore[*]}
do
    for iTemp in ${!temperaturesValues[*]}
    do
        if (( "${tempCore[$iCore]}" < "${temperaturesValues[$iTemp]}"  )); then
            tmpEcho="%{F${temperaturesColors[$iTemp]}}${tempCore[$iCore]}$degree%{F-}"
            finalEcho="$finalEcho $tmpEcho"
            break
        fi
    done
    total=$(( ${tempCore[$iCore]} + total ));
done

sum=$(( total/${#tempCore[*]} ))

for iTemp in ${!temperaturesValues[*]}
do
    if (( "$sum" < "${temperaturesValues[$iTemp]}" )); then
        ## This line will color the icon too
        tmpEcho="%{F${temperaturesColors[$iTemp]}}${temperaturesIcons[$iTemp]}%{F-}"
        ## This line will NOT color the icon
        #tmpEcho="${temperaturesIcons[$iTemp]}"
        finalEcho=" $finalEcho $tmpEcho"
        break
    fi
done

echo "$finalEcho"
Ryzen 7 2700, 32GB Corsair Dominator 3200, MSI Armor RX-580, ASUS Crosshair Hero VII X470, Sabrent NVMe
Post Reply

Return to “Suggestions & New Ideas”