Revert "compton-trans: use getopt instead of getopts."
This reverts commit 80a3c80561
.
This commit is contained in:
parent
80a3c80561
commit
b0db9f4f07
|
@ -27,8 +27,6 @@ if test -z "$(command -v xprop)" -o -z "$(command -v xwininfo)"; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
args=
|
|
||||||
arg=
|
|
||||||
active=
|
active=
|
||||||
wprefix=
|
wprefix=
|
||||||
window=
|
window=
|
||||||
|
@ -45,34 +43,36 @@ for v in "$@"; do
|
||||||
shift && set -- "$@" "$(echo "$v" | sed 's/^-\([0-9]\+%\?\)$/~\1/')"
|
shift && set -- "$@" "$(echo "$v" | sed 's/^-\([0-9]\+%\?\)$/~\1/')"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Use getopt to parse arguments.
|
# This takes into account the fact that getopts stops on
|
||||||
args=$(getopt -o 'scdgn:w:o:' -l 'select,current,delete,get,name:,window:,opacity:' -- "$@")
|
# any argument it doesn't recongize or errors on. This
|
||||||
if test $? -ne 0; then
|
# allows for things like `compton-trans -5` as well
|
||||||
echo 'Bad arguments.'
|
# as `compton-trans -c +5 -s` (contrived example).
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
eval set -- "$args"
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
while test $# -gt 0; do
|
||||||
arg=$1
|
# Reset option index
|
||||||
shift
|
OPTIND=1
|
||||||
case "$arg" in
|
|
||||||
--) break ;;
|
# Read options
|
||||||
-s | --select) wprefix=''; window='' ;;
|
while getopts 'scdgn:w:o:' option "$@"; do
|
||||||
-c | --current)
|
case "$option" in
|
||||||
|
s) wprefix=''; window='' ;;
|
||||||
|
c)
|
||||||
active=$(xprop -root -notype _NET_ACTIVE_WINDOW \
|
active=$(xprop -root -notype _NET_ACTIVE_WINDOW \
|
||||||
| sed 's/^.*\(0x\S*\).*$/\1/')
|
| sed 's/^.*\(0x\S*\).*$/\1/')
|
||||||
wprefix='-id'; window=$active
|
wprefix='-id'; window=$active
|
||||||
;;
|
;;
|
||||||
-d | --delete) action='delete' ;;
|
d) action='delete' ;;
|
||||||
-g | --get) action='get' ;;
|
g) action='get' ;;
|
||||||
-n | --name) wprefix='-name'; window=$1; shift ;;
|
n) wprefix='-name'; window=$OPTARG ;;
|
||||||
-w | --window) wprefix='-id'; window=$1; shift ;;
|
w) wprefix='-id'; window=$OPTARG ;;
|
||||||
-o | --opacity) opacity=$1; shift ;;
|
o) opacity=$OPTARG ;;
|
||||||
|
\?) exit 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
test -n "$1" && opacity=$1
|
|
||||||
|
# Read positional arguments
|
||||||
|
shift $((OPTIND - 1))
|
||||||
|
test -n "$1" && opacity=$1 && shift
|
||||||
|
done
|
||||||
|
|
||||||
# clean up opacity. xargs == a poor man's trim.
|
# clean up opacity. xargs == a poor man's trim.
|
||||||
opacity=$(echo "$opacity" | xargs | sed 's/%//g' | sed 's/^~\([0-9]\+\)$/-\1/')
|
opacity=$(echo "$opacity" | xargs | sed 's/%//g' | sed 's/^~\([0-9]\+\)$/-\1/')
|
||||||
|
|
Loading…
Reference in New Issue