From 5078b6a63fc5cf86d0ca04162a57befbf816eff3 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Fri, 27 Jun 2025 12:59:13 +0200 Subject: [PATCH] *.sh: Fix some shellcheck issues --- .config/git/zsh-autoload.sh | 12 +++++++----- .config/i3/monitor-setup.sh | 2 +- .config/polybar/launch.sh | 6 +++--- .config/polybar/scripts/battery.sh | 5 ++--- .config/polybar/scripts/pub_ipv4.sh | 2 +- .config/rofi/powermenu.sh | 2 +- .local/bin/helpers.sh | 2 +- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.config/git/zsh-autoload.sh b/.config/git/zsh-autoload.sh index 93b2093..318083f 100755 --- a/.config/git/zsh-autoload.sh +++ b/.config/git/zsh-autoload.sh @@ -6,20 +6,22 @@ # correct directory. if [ $# -eq 0 ]; then - printf >&2 "Usage: $(basename "$0") \n" + printf >&2 "Usage: %s \n" "$(basename "$0")" exit 1 fi +name="$1" +shift BASE="${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git" # In git aliases, shell commands are executed from the top-level directory of # the repo. GIT_PREFIX contains the original directory relative to the # top-level. -[ -z "$GIT_PREFIX" ] || cd "$GIT_PREFIX" +[ -z "$GIT_PREFIX" ] || cd "$GIT_PREFIX" || exit # no need for error handling, the message from sh is descriptive enough -if [ "${1#git-}" != "$1" ] || [ -e "$BASE/$1" ]; then - exec "$BASE/$@" +if [ "${name#git-}" != "$name" ] || [ -e "$BASE/$name" ]; then + exec "$BASE/$name" "$@" else - exec "$BASE/git-$@" + exec "$BASE/git-$name" "$@" fi diff --git a/.config/i3/monitor-setup.sh b/.config/i3/monitor-setup.sh index 1ab3e9a..919385e 100755 --- a/.config/i3/monitor-setup.sh +++ b/.config/i3/monitor-setup.sh @@ -1,6 +1,6 @@ #!/bin/sh -if [ 1 -lt "$(xrandr -q | grep " connected" | wc -l)" ]; then +if [ 1 -lt "$(xrandr -q | grep -c " connected")" ]; then # scale second monitor to 3200x1800 and put to the left xrandr --output eDP1 --auto --pos 0x0 --primary \ --output DP1 --auto --scale-from 3200x1800 --pos 3200x0 \ diff --git a/.config/polybar/launch.sh b/.config/polybar/launch.sh index 6ceacb5..caa6059 100755 --- a/.config/polybar/launch.sh +++ b/.config/polybar/launch.sh @@ -15,17 +15,17 @@ module_flags=( [vpn_click_left]="$BASE_DIR/scripts/pub_ipv4.sh &" ) for module in "${!module_flags[@]}"; do - export POLYBAR_${module^^}="${module_flags[$module]}" + export POLYBAR_"${module^^}=${module_flags[$module]}" done # if there is no running instance if ! pgrep -ax polybar >/dev/null 2>&1; then # launch Polybar on every monitor # https://github.com/polybar/polybar/issues/763 - while read m; do + while read -r m; do export MONITOR="${m%%:*}" polybar --reload -c "$BASE_DIR/config" main & - done <<<$(polybar --list-monitors) + done <<<"$(polybar --list-monitors)" echo "Polybar launched..." else diff --git a/.config/polybar/scripts/battery.sh b/.config/polybar/scripts/battery.sh index 52b6423..4cfd1a0 100755 --- a/.config/polybar/scripts/battery.sh +++ b/.config/polybar/scripts/battery.sh @@ -9,7 +9,6 @@ low=20 red='%{F#f00}' green='%{F#0f0}' -end='%{F-}' bat="$(cat /sys/class/power_supply/BAT0/capacity 2>/dev/null)" || exit ac="$(cat /sys/class/power_supply/AC/online 2>/dev/null)" @@ -21,8 +20,8 @@ ramp=(          ) # display in green when over $full and a charger is connected [[ "$bat" -lt "$full" || "$ac" -eq 0 ]] || color="$green" -let "icon_index = $bat / (${#ramp[@]} - 1)" -[[ $icon_index -lt ${#ramp[@]} ]] || icond_index=10 +icon_index="$((bat / (${#ramp[@]} - 1)))" +[[ $icon_index -lt ${#ramp[@]} ]] || icon_index=10 icon="${ramp[$icon_index]}" [[ "$ac" -eq 0 ]] || charge="" diff --git a/.config/polybar/scripts/pub_ipv4.sh b/.config/polybar/scripts/pub_ipv4.sh index d6d6b54..78a4216 100755 --- a/.config/polybar/scripts/pub_ipv4.sh +++ b/.config/polybar/scripts/pub_ipv4.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo $(curl -s https://ipinfo.io/ip) +curl -s https://ipinfo.io/ip diff --git a/.config/rofi/powermenu.sh b/.config/rofi/powermenu.sh index b71537b..9961861 100755 --- a/.config/rofi/powermenu.sh +++ b/.config/rofi/powermenu.sh @@ -17,7 +17,7 @@ entries=( [reboot]="$controller reboot" [shutdown]="$controller poweroff" [suspend]="$controller suspend" - [suspend (scheduled)]="scheduled_suspend" + ["suspend (scheduled)"]="scheduled_suspend" ) declare -a rofi_args diff --git a/.local/bin/helpers.sh b/.local/bin/helpers.sh index 318b53f..991222a 100755 --- a/.local/bin/helpers.sh +++ b/.local/bin/helpers.sh @@ -9,5 +9,5 @@ # Usage: die [] [] die() { [ -z "$1" ] || >&2 printf "%s: %s\n" "$0" "$1" - exit ${2:-1} + exit "${2:-1}" }