From c9bf88cc89a60d1cd465ed8ca994c1d3c2985f34 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 4 May 2013 17:50:31 -0500 Subject: [PATCH] compton-trans: use a different workaround with getopts. --- bin/compton-trans | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/bin/compton-trans b/bin/compton-trans index 91714f9..7b2ac7d 100755 --- a/bin/compton-trans +++ b/bin/compton-trans @@ -38,6 +38,11 @@ wid= topmost= lineno= +# Workaround: replace '-5' with '~5' so as not to confuse getopts. +for v in "$@"; do + shift && set -- "$@" "$(echo "$v" | sed 's/^-\([0-9]\+%\?\)$/~\1/')" +done + # This takes into account the fact that getopts stops on # any argument it doesn't recongize or errors on. This # allows for things like `compton-trans -5` as well @@ -45,10 +50,9 @@ lineno= while test $# -gt 0; do # Reset option index OPTIND=1 - LASTIND=1 # Read options - while getopts ':scdgn:w:o:' option "$@"; do + while getopts 'scdgn:w:o:' option "$@"; do case "$option" in s) wprefix=''; window='' ;; c) @@ -61,16 +65,8 @@ while test $# -gt 0; do n) wprefix='-name'; window=$OPTARG ;; w) wprefix='-id'; window=$OPTARG ;; o) opacity=$OPTARG ;; - \?) - # For some reason single char options `-x` stop on the OPTIND after the - # argument index, whereas two or more character options (`-foo`) stop - # on the argument's index, so we use LASTIND here instead. If OPTIND is - # not equal to LASTIND, this means -x was used instead of -xx. - OPTIND=$LASTIND - break - ;; + \?) exit 1 ;; esac - LASTIND=$OPTIND done # Read positional arguments @@ -79,7 +75,7 @@ while test $# -gt 0; do done # clean up opacity. xargs == a poor man's trim. -opacity=$(echo "$opacity" | sed 's/%//g' | xargs) +opacity=$(echo "$opacity" | xargs | sed 's/%//g' | sed 's/^~\([0-9]\+\)$/-\1/') # Validate opacity value if test -z "$action" && ! echo "$opacity" | grep -q '^[+-]\?[0-9]\+$'; then