mirror of
https://github.com/yshui/picom.git
synced 2024-11-18 13:55:36 -05:00
compton-trans: use a different workaround with getopts.
This commit is contained in:
parent
e6b973fe2f
commit
c9bf88cc89
1 changed files with 8 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue