Skip to content

Commit fa633b0

Browse files
tree: run shellharden on bash files
Running shell harden on bash files makes them more secure and less buggy as vulnerabilities to malicious glob expansion and the like are reduced. GHA CI check for PRs incoming... Signed-off-by: Ethan Carter Edwards <[email protected]>
1 parent 3e1e7a1 commit fa633b0

32 files changed

+337
-337
lines changed

dracula.tmux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66

7-
$current_dir/scripts/dracula.sh
7+
"$current_dir"/scripts/dracula.sh
88

scripts/attached_clients.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export LC_ALL=en_US.UTF-8
88
# @dracula-clients-plural clients
99

1010
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11-
source $current_dir/utils.sh
11+
source "$current_dir"/utils.sh
1212

1313
count_clients() {
1414
pane=$(tmux list-panes -F "#{session_name}" | head -n 1)
15-
tmux list-clients -t $pane | wc -l | tr -d ' '
15+
tmux list-clients -t "$pane" | wc -l | tr -d ' '
1616
}
1717

1818
main() {
@@ -28,7 +28,7 @@ main() {
2828
fi
2929
echo "$clients_count $clients_label"
3030
fi
31-
sleep $RATE
31+
sleep "$RATE"
3232
}
3333

3434
# run main driver

scripts/battery.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
export LC_ALL=en_US.UTF-8
44

55
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6-
source $current_dir/utils.sh
6+
source "$current_dir"/utils.sh
77

88
linux_acpi() {
99
arg=$1
1010
BAT=$(ls -d /sys/class/power_supply/*)
1111
if [ ! -x "$(which acpi 2> /dev/null)" ];then
12-
for DEV in $BAT; do
12+
for DEV in "${BAT[@]}"; do
1313
case "$arg" in
1414
status)
1515
[ -f "$DEV/status" ] && cat "$DEV/status"
@@ -41,15 +41,15 @@ battery_percent()
4141
case $(uname -s) in
4242
Linux)
4343
percent=$(linux_acpi percent)
44-
[ -n "$percent" ] && echo "$percent%"
44+
[ "$percent" != "" ] && echo "$percent%"
4545
;;
4646

4747
Darwin)
48-
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')
48+
echo "$(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')"
4949
;;
5050

5151
FreeBSD)
52-
echo $(apm | sed '8,11d' | grep life | awk '{print $4}')
52+
echo "$(apm | sed '8,11d' | grep life | awk '{print $4}')"
5353
;;
5454

5555
CYGWIN*|MINGW32*|MSYS*|MINGW*)
@@ -161,17 +161,17 @@ main()
161161
fi
162162

163163
show_bat_label=$(get_tmux_option "@dracula-show-battery-status" false)
164-
if $show_bat_label; then
164+
if "$show_bat_label"; then
165165
bat_stat=$(battery_status)
166166
else
167167
bat_stat=""
168168
fi
169169

170170
bat_perc=$(battery_percent)
171171

172-
if [ -z "$bat_stat" ]; then # Test if status is empty or not
172+
if [ "$bat_stat" = "" ]; then # Test if status is empty or not
173173
echo "$bat_label $bat_perc"
174-
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
174+
elif [ "$bat_perc" = "" ]; then # In case it is a desktop with no battery percent, only AC power
175175
echo "$no_bat_label"
176176
else
177177
echo "$bat_label$bat_stat $bat_perc"

scripts/continuum.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ auto_save_interval_option="@continuum-save-interval"
2323
auto_save_interval_default="15"
2424

2525
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26-
source $current_dir/utils.sh
26+
source "$current_dir"/utils.sh
2727

2828
current_timestamp() {
2929
echo "$(date +%s)"
@@ -73,7 +73,7 @@ set_tmux_option() {
7373

7474
# tmux-resurrect dir
7575
resurrect_dir() {
76-
if [ -z "$_RESURRECT_DIR" ]; then
76+
if [ "$_RESURRECT_DIR" = "" ]; then
7777
local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")"
7878
# expands tilde, $HOME and $HOSTNAME if used in @resurrect-dir
7979
echo "$path" | sed "s,\$HOME,$HOME,g; s,\$HOSTNAME,$(hostname),g; s,\~,$HOME,g"
@@ -92,7 +92,7 @@ last_saved_timestamp() {
9292
local first_save_timestamp="$(get_tmux_option "$first_save" "")"
9393
# continuum sets the last save timestamp to the current time on first load if auto_save_option is not set
9494
# so we can outrace it and detect that last_uato_save_option is empty and the timestamp is a dummy save
95-
if [ -z "$first_save_timestamp" ]; then
95+
if [ "$first_save_timestamp" = "" ]; then
9696
last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=-1
9797
set_tmux_option "$first_save" "$last_saved_timestamp"
9898
elif [ "$first_save_timestamp" != "done" ]; then

scripts/cpu_info.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33
export LC_ALL=en_US.UTF-8
44

55
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6-
source $current_dir/utils.sh
6+
source "$current_dir"/utils.sh
77

88
get_percent()
99
{
1010
case $(uname -s) in
1111
Linux)
1212
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
13-
normalize_percent_len $percent
13+
normalize_percent_len "$percent"
1414
;;
1515

1616
Darwin)
1717
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
1818
cpucores=$(sysctl -n hw.logicalcpu)
1919
cpuusage=$(( cpuvalue / cpucores ))
2020
percent="$cpuusage%"
21-
normalize_percent_len $percent
21+
normalize_percent_len "$percent"
2222
;;
2323

2424
OpenBSD)
2525
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
2626
cpucores=$(sysctl -n hw.ncpuonline)
2727
cpuusage=$(( cpuvalue / cpucores ))
2828
percent="$cpuusage%"
29-
normalize_percent_len $percent
29+
normalize_percent_len "$percent"
3030
;;
3131

3232
CYGWIN*|MINGW32*|MSYS*|MINGW*)
@@ -39,7 +39,7 @@ get_load() {
3939
case $(uname -s) in
4040
Linux | Darwin | OpenBSD)
4141
loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g')
42-
echo $loadavg
42+
echo "$loadavg"
4343
;;
4444

4545
CYGWIN* | MINGW32* | MSYS* | MINGW*)
@@ -59,7 +59,7 @@ main() {
5959
cpu_percent=$(get_percent)
6060
echo "$cpu_label $cpu_percent"
6161
fi
62-
sleep $RATE
62+
sleep "$RATE"
6363
}
6464

6565
# run main driver

scripts/cwd.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source "$current_dir/utils.sh"
77
getPaneDir() {
88
nextone="false"
99
ret=""
10-
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); do
10+
for i in "$(tmux list-panes -F "#{pane_active} #{pane_current_path}")"; do
1111
[ "$i" == "1" ] && nextone="true" && continue
1212
[ "$i" == "0" ] && nextone="false"
1313
[ "$nextone" == "true" ] && ret+="$i "
@@ -41,7 +41,7 @@ main() {
4141
fi
4242

4343
cwd_max_chars="$(get_tmux_option "@dracula-cwd-max-chars" "0")"
44-
if [[ "${cwd_max_chars}" -gt 0 && "${#cwd}" -gt "$cwd_max_chars" ]]; then
44+
if [[ "$cwd_max_chars" -gt 0 && "${#cwd}" -gt "$cwd_max_chars" ]]; then
4545
cwd="…/…${cwd:(- cwd_max_chars)}"
4646
fi
4747

0 commit comments

Comments
 (0)