compton-trans: use a different workaround with getopts.

This commit is contained in:
Christopher Jeffrey 2013-05-04 17:50:31 -05:00
parent e6b973fe2f
commit c9bf88cc89
1 changed files with 8 additions and 12 deletions

View File

@ -38,6 +38,11 @@ wid=
topmost= topmost=
lineno= 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 # This takes into account the fact that getopts stops on
# any argument it doesn't recongize or errors on. This # any argument it doesn't recongize or errors on. This
# allows for things like `compton-trans -5` as well # allows for things like `compton-trans -5` as well
@ -45,10 +50,9 @@ lineno=
while test $# -gt 0; do while test $# -gt 0; do
# Reset option index # Reset option index
OPTIND=1 OPTIND=1
LASTIND=1
# Read options # Read options
while getopts ':scdgn:w:o:' option "$@"; do while getopts 'scdgn:w:o:' option "$@"; do
case "$option" in case "$option" in
s) wprefix=''; window='' ;; s) wprefix=''; window='' ;;
c) c)
@ -61,16 +65,8 @@ while test $# -gt 0; do
n) wprefix='-name'; window=$OPTARG ;; n) wprefix='-name'; window=$OPTARG ;;
w) wprefix='-id'; window=$OPTARG ;; w) wprefix='-id'; window=$OPTARG ;;
o) opacity=$OPTARG ;; o) opacity=$OPTARG ;;
\?) \?) exit 1 ;;
# 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
;;
esac esac
LASTIND=$OPTIND
done done
# Read positional arguments # Read positional arguments
@ -79,7 +75,7 @@ while test $# -gt 0; do
done done
# clean up opacity. xargs == a poor man's trim. # 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 # Validate opacity value
if test -z "$action" && ! echo "$opacity" | grep -q '^[+-]\?[0-9]\+$'; then if test -z "$action" && ! echo "$opacity" | grep -q '^[+-]\?[0-9]\+$'; then