Skip to content

Commit

Permalink
usr_bin/grml-resolution: Fix a couple of shellscript warnings
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jkirk committed Dec 3, 2021
1 parent e8b2d94 commit 4771fd1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions usr_bin/grml-resolution
Expand Up @@ -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
Expand All @@ -27,34 +27,36 @@ 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
}

while true ; do
main
done

bailout
bailout 0

# EOF #

0 comments on commit 4771fd1

Please sign in to comment.