usr_bin/grml-resolution: Fix a couple of shellscript warnings
authorDarshaka Pathirana <dpat@syn-net.org>
Fri, 4 Dec 2020 11:22:58 +0000 (12:22 +0100)
committerDarshaka Pathirana <dpat@syn-net.org>
Fri, 3 Dec 2021 11:54:54 +0000 (12:54 +0100)
- 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

index c30111e..5b334d7 100755 (executable)
@@ -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 #