From 4771fd182a04f38e6ca37c22c3dda04eedb4d8e1 Mon Sep 17 00:00:00 2001 From: Darshaka Pathirana Date: Fri, 4 Dec 2020 12:22:58 +0100 Subject: [PATCH] usr_bin/grml-resolution: Fix a couple of shellscript warnings - Ignore SC2086: dialog needs $STRING to be splitted, so that the values are listed in the menu - SC2120: bailout references arguments, but none are ever passed - Ignore SC2015: Note that A && B || C is not if-then-else. C may run when A is true --- usr_bin/grml-resolution | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/usr_bin/grml-resolution b/usr_bin/grml-resolution index c30111e..5b334d7 100755 --- a/usr_bin/grml-resolution +++ b/usr_bin/grml-resolution @@ -6,13 +6,13 @@ # License: This file is licensed under the GPL v2. ################################################################################ -PN=$(basename $0) +PN="$(basename "$0")" RESOLUTION=$(mktemp) ERROR=$(mktemp) bailout(){ - rm -f $RESOLUTION $ERROR - exit $1 + rm -f "$RESOLUTION" "$ERROR" + exit "$1" } trap bailout 1 2 3 15 @@ -27,27 +27,29 @@ CURRENT_NUM=$(xrandr | awk '/\*/ {print $1}' | tr -d '*') CURRENT_RESOLUTION=$(xrandr | awk '/\*/ {print $2 $3 $4}') # menu -for i in $(xrandr | awk {'print $2$3$4'} | grep "^[0-9]") ; do +for i in $(xrandr | awk '{print $2$3$4}' | grep "^[0-9]") ; do STRING="$STRING $COUNTER $i" ((COUNTER++)) done # Menu Tool -dialog --title "$PN" --menu "Change X resolution via xrandr (current resolution: $CURRENT_RESOLUTION):" 0 0 0 $STRING 2>$RESOLUTION +# shellcheck disable=SC2086 +dialog --title "$PN" --menu "Change X resolution via xrandr (current resolution: $CURRENT_RESOLUTION):" 0 0 0 $STRING 2>"$RESOLUTION" retval=$? case $retval in (1) echo "Cancel pressed." ; exit 1 ;; (255) echo "ESC pressed." ; exit 1 ;; esac -CHOSE=$(cat $RESOLUTION) +CHOSE=$(cat "$RESOLUTION") if [ "$CHOSE" = "$CURRENT_NUM" ] ; then dialog --title "$PN" --msgbox "Chosen resolution corresponds to current resolution. No changes needed." 0 0 elif [ -n "$CHOSE" ] ; then - xrandr -s $CHOSE 2>$ERROR && \ +# shellcheck disable=SC2015 + xrandr -s "$CHOSE" 2>"$ERROR" && \ dialog --title "$PN" --msgbox "Running xrandr with resolution was succesful." 0 0 || \ - dialog --title "$PN" --msgbox "Error when running xrandr with resolution $CHOSE: `cat $ERROR`" 0 0 + dialog --title "$PN" --msgbox "Error when running xrandr with resolution $CHOSE: $(cat "$ERROR")" 0 0 fi } @@ -55,6 +57,6 @@ while true ; do main done -bailout +bailout 0 # EOF # -- 2.1.4