Skip to content

Commit 00ab1d2

Browse files
ctjhoacasperdcl
andauthored
Add CI linting (#72)
Co-authored-by: Casper da Costa-Luis <[email protected]>
1 parent 86c0023 commit 00ab1d2

27 files changed

+289
-187
lines changed

.github/workflows/check.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Check
2+
on:
3+
push:
4+
pull_request:
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: luizm/action-sh-checker@master
11+
env:
12+
SHELLCHECK_OPTS: -x

cpu.tmux

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

55
source "$CURRENT_DIR/scripts/helpers.sh"
66

@@ -65,16 +65,19 @@ set_tmux_option() {
6565

6666
do_interpolation() {
6767
local all_interpolated="$1"
68-
for ((i=0; i<${#cpu_commands[@]}; i++)); do
68+
for ((i = 0; i < ${#cpu_commands[@]}; i++)); do
6969
all_interpolated=${all_interpolated//${cpu_interpolation[$i]}/${cpu_commands[$i]}}
7070
done
7171
echo "$all_interpolated"
7272
}
7373

7474
update_tmux_option() {
75-
local option=$1
76-
local option_value=$(get_tmux_option "$option")
77-
local new_option_value=$(do_interpolation "$option_value")
75+
local option
76+
local option_value
77+
local new_option_value
78+
option=$1
79+
option_value=$(get_tmux_option "$option")
80+
new_option_value=$(do_interpolation "$option_value")
7881
set_tmux_option "$option" "$new_option_value"
7982
}
8083

scripts/cpu_bg_color.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

5+
# shellcheck source=scripts/helpers.sh
56
source "$CURRENT_DIR/helpers.sh"
67

78
cpu_low_bg_color=""
@@ -19,13 +20,15 @@ get_bg_color_settings() {
1920
}
2021

2122
print_bg_color() {
22-
local cpu_percentage=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
23-
local load_status=$(load_status $cpu_percentage "cpu")
24-
if [ $load_status == "low" ]; then
23+
local cpu_percentage
24+
local load_status
25+
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
26+
load_status=$(load_status "$cpu_percentage" "cpu")
27+
if [ "$load_status" == "low" ]; then
2528
echo "$cpu_low_bg_color"
26-
elif [ $load_status == "medium" ]; then
29+
elif [ "$load_status" == "medium" ]; then
2730
echo "$cpu_medium_bg_color"
28-
elif [ $load_status == "high" ]; then
31+
elif [ "$load_status" == "high" ]; then
2932
echo "$cpu_high_bg_color"
3033
fi
3134
}
@@ -34,4 +37,4 @@ main() {
3437
get_bg_color_settings
3538
print_bg_color
3639
}
37-
main
40+
main "$@"

scripts/cpu_fg_color.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

5+
# shellcheck source=scripts/helpers.sh
56
source "$CURRENT_DIR/helpers.sh"
67

78
cpu_low_fg_color=""
@@ -19,13 +20,15 @@ get_fg_color_settings() {
1920
}
2021

2122
print_fg_color() {
22-
local cpu_percentage=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
23-
local load_status=$(load_status $cpu_percentage "cpu")
24-
if [ $load_status == "low" ]; then
23+
local cpu_percentage
24+
local load_status
25+
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
26+
load_status=$(load_status "$cpu_percentage" "cpu")
27+
if [ "$load_status" == "low" ]; then
2528
echo "$cpu_low_fg_color"
26-
elif [ $load_status == "medium" ]; then
29+
elif [ "$load_status" == "medium" ]; then
2730
echo "$cpu_medium_fg_color"
28-
elif [ $load_status == "high" ]; then
31+
elif [ "$load_status" == "high" ]; then
2932
echo "$cpu_high_fg_color"
3033
fi
3134
}
@@ -34,4 +37,4 @@ main() {
3437
get_fg_color_settings
3538
print_fg_color
3639
}
37-
main
40+
main "$@"

scripts/cpu_icon.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

5+
# shellcheck source=scripts/helpers.sh
56
source "$CURRENT_DIR/helpers.sh"
67

78
# script global variables
@@ -21,13 +22,15 @@ get_icon_settings() {
2122
}
2223

2324
print_icon() {
24-
local cpu_percentage=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
25-
local load_status=$(load_status $cpu_percentage "cpu")
26-
if [ $load_status == "low" ]; then
25+
local cpu_percentage
26+
local load_status
27+
cpu_percentage=$("$CURRENT_DIR"/cpu_percentage.sh | sed -e 's/%//')
28+
load_status=$(load_status "$cpu_percentage" "cpu")
29+
if [ "$load_status" == "low" ]; then
2730
echo "$cpu_low_icon"
28-
elif [ $load_status == "medium" ]; then
31+
elif [ "$load_status" == "medium" ]; then
2932
echo "$cpu_medium_icon"
30-
elif [ $load_status == "high" ]; then
33+
elif [ "$load_status" == "high" ]; then
3134
echo "$cpu_high_icon"
3235
fi
3336
}
@@ -36,4 +39,4 @@ main() {
3639
get_icon_settings
3740
print_icon "$1"
3841
}
39-
main
42+
main "$@"

scripts/cpu_percentage.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

5+
# shellcheck source=scripts/helpers.sh
56
source "$CURRENT_DIR/helpers.sh"
67

78
cpu_percentage_format="%3.1f%%"
@@ -25,9 +26,10 @@ print_cpu_percentage() {
2526
else
2627
if is_cygwin; then
2728
usage="$(cached_eval WMIC cpu get LoadPercentage | grep -Eo '^[0-9]+')"
29+
# shellcheck disable=SC2059
2830
printf "$cpu_percentage_format" "$usage"
2931
else
30-
load=`cached_eval ps -aux | awk '{print $3}' | tail -n+2 | awk '{s+=$1} END {print s}'`
32+
load=$(cached_eval ps -aux | awk '{print $3}' | tail -n+2 | awk '{s+=$1} END {print s}')
3133
cpus=$(cpus_number)
3234
echo "$load $cpus" | awk -v format="$cpu_percentage_format" '{printf format, $1/$2}'
3335
fi

scripts/cpu_temp.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

5+
# shellcheck source=scripts/helpers.sh
56
source "$CURRENT_DIR/helpers.sh"
67

78
cpu_temp_format="%2.0f"
@@ -11,7 +12,13 @@ print_cpu_temp() {
1112
cpu_temp_format=$(get_tmux_option "@cpu_temp_format" "$cpu_temp_format")
1213
cpu_temp_unit=$(get_tmux_option "@cpu_temp_unit" "$cpu_temp_unit")
1314
if command_exists "sensors"; then
14-
([ "$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)}'
15+
local val
16+
if [[ "$cpu_temp_unit" == F ]]; then
17+
val=$(sensors -f)
18+
else
19+
val=$(sensors)
20+
fi
21+
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)}'
1522
fi
1623
}
1724

scripts/cpu_temp_bg_color.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

5+
# shellcheck source=scripts/helpers.sh
56
source "$CURRENT_DIR/helpers.sh"
67

78
cpu_temp_low_bg_color=""
@@ -19,13 +20,15 @@ get_bg_color_settings() {
1920
}
2021

2122
print_bg_color() {
22-
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
23-
local cpu_temp_status=$(temp_status $cpu_temp)
24-
if [ $cpu_temp_status == "low" ]; then
23+
local cpu_temp
24+
local cpu_temp_status
25+
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
26+
cpu_temp_status=$(temp_status "$cpu_temp")
27+
if [ "$cpu_temp_status" == "low" ]; then
2528
echo "$cpu_temp_low_bg_color"
26-
elif [ $cpu_temp_status == "medium" ]; then
29+
elif [ "$cpu_temp_status" == "medium" ]; then
2730
echo "$cpu_temp_medium_bg_color"
28-
elif [ $cpu_temp_status == "high" ]; then
31+
elif [ "$cpu_temp_status" == "high" ]; then
2932
echo "$cpu_temp_high_bg_color"
3033
fi
3134
}

scripts/cpu_temp_fg_color.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

5+
# shellcheck source=scripts/helpers.sh
56
source "$CURRENT_DIR/helpers.sh"
67

78
cpu_temp_low_fg_color=""
@@ -19,13 +20,15 @@ get_fg_color_settings() {
1920
}
2021

2122
print_fg_color() {
22-
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
23-
local cpu_temp_status=$(temp_status $cpu_temp)
24-
if [ $cpu_temp_status == "low" ]; then
23+
local cpu_temp
24+
local cpu_temp_status
25+
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
26+
cpu_temp_status=$(temp_status "$cpu_temp")
27+
if [ "$cpu_temp_status" == "low" ]; then
2528
echo "$cpu_temp_low_fg_color"
26-
elif [ $cpu_temp_status == "medium" ]; then
29+
elif [ "$cpu_temp_status" == "medium" ]; then
2730
echo "$cpu_temp_medium_fg_color"
28-
elif [ $cpu_temp_status == "high" ]; then
31+
elif [ "$cpu_temp_status" == "high" ]; then
2932
echo "$cpu_temp_high_fg_color"
3033
fi
3134
}

scripts/cpu_temp_icon.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

5+
# shellcheck source=scripts/helpers.sh
56
source "$CURRENT_DIR/helpers.sh"
67

78
# script global variables
@@ -21,13 +22,15 @@ get_icon_settings() {
2122
}
2223

2324
print_icon() {
24-
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
25-
local cpu_temp_status=$(temp_status $cpu_temp)
26-
if [ $cpu_temp_status == "low" ]; then
25+
local cpu_temp
26+
local cpu_temp_status
27+
cpu_temp=$("$CURRENT_DIR"/cpu_temp.sh | sed -e 's/[^0-9.]//')
28+
cpu_temp_status=$(temp_status "$cpu_temp")
29+
if [ "$cpu_temp_status" == "low" ]; then
2730
echo "$cpu_temp_low_icon"
28-
elif [ $cpu_temp_status == "medium" ]; then
31+
elif [ "$cpu_temp_status" == "medium" ]; then
2932
echo "$cpu_temp_medium_icon"
30-
elif [ $cpu_temp_status == "high" ]; then
33+
elif [ "$cpu_temp_status" == "high" ]; then
3134
echo "$cpu_temp_high_icon"
3235
fi
3336
}
@@ -36,4 +39,4 @@ main() {
3639
get_icon_settings
3740
print_icon "$1"
3841
}
39-
main
42+
main "$@"

0 commit comments

Comments
 (0)