compton-trans: use getopt instead of getopts.

This commit is contained in:
Christopher Jeffrey 2013-05-04 17:51:00 -05:00
parent c9bf88cc89
commit 80a3c80561
1 changed files with 28 additions and 28 deletions

View File

@ -27,6 +27,8 @@ if test -z "$(command -v xprop)" -o -z "$(command -v xwininfo)"; then
fi fi
# Variables # Variables
args=
arg=
active= active=
wprefix= wprefix=
window= window=
@ -43,36 +45,34 @@ for v in "$@"; do
shift && set -- "$@" "$(echo "$v" | sed 's/^-\([0-9]\+%\?\)$/~\1/')" shift && set -- "$@" "$(echo "$v" | sed 's/^-\([0-9]\+%\?\)$/~\1/')"
done done
# This takes into account the fact that getopts stops on # Use getopt to parse arguments.
# any argument it doesn't recongize or errors on. This args=$(getopt -o 'scdgn:w:o:' -l 'select,current,delete,get,name:,window:,opacity:' -- "$@")
# allows for things like `compton-trans -5` as well if test $? -ne 0; then
# as `compton-trans -c +5 -s` (contrived example). echo 'Bad arguments.'
while test $# -gt 0; do exit 1
# Reset option index fi
OPTIND=1
# Read options eval set -- "$args"
while getopts 'scdgn:w:o:' option "$@"; do
case "$option" in while test $# -gt 0; do
s) wprefix=''; window='' ;; arg=$1
c) shift
case "$arg" in
--) break ;;
-s | --select) wprefix=''; window='' ;;
-c | --current)
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) action='delete' ;; -d | --delete) action='delete' ;;
g) action='get' ;; -g | --get) action='get' ;;
n) wprefix='-name'; window=$OPTARG ;; -n | --name) wprefix='-name'; window=$1; shift ;;
w) wprefix='-id'; window=$OPTARG ;; -w | --window) wprefix='-id'; window=$1; shift ;;
o) opacity=$OPTARG ;; -o | --opacity) opacity=$1; shift ;;
\?) exit 1 ;;
esac esac
done
# Read positional arguments
shift $((OPTIND - 1))
test -n "$1" && opacity=$1 && shift
done done
test -n "$1" && opacity=$1
# 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/')