Fixed long-option argument parsing

Arguments of long-options (e.g. --program-flags='--foo=bar') may contain
equal sign characters (=). Before this fix, these kind of options were
split up into "program-flags" and "--foo" removing the last part of the
argument. This was because only the first two colums from `awk -F= ...`
were used.

Now these kind of options will be split up correctly using Bash parameter
expansion: "program-flags" and "--foo=bar".

See man bash > Parameter Expansion for details.

Tested with:
sudo cp tdrop /usr/bin/tdrop
tdrop -W --program-flags='-e tmux --role=tdropwindow'   termite
tdrop -W              -f '-e tmux --role=tdropwindow'   termite
tdrop --normal-window -f '-e tmux --role=tdropwindow'   termite

It also works for boolen long-option flags without argument. In this
case both OPTION and OPTARG are set to the long-option name. Boolean
options don't use the OPTARG so it doesn't matter.
long-opts
Jakob Schöttl 9 years ago
parent ef9e436252
commit 21e8aa2522

@ -91,8 +91,8 @@ do
a) auto_detect_wm=true;; a) auto_detect_wm=true;;
m) monitor_aware=true;; m) monitor_aware=true;;
-) -)
OPTION=$(echo "$OPTARG" | awk -F '=' '{print $1}') OPTION=${OPTARG%%=*}
OPTARG=$(echo "$OPTARG" | awk -F '=' '{print $2}') OPTARG=${OPTARG#*=}
case $OPTION in case $OPTION in
height) height=$OPTARG;; height) height=$OPTARG;;
width) width=$OPTARG;; width) width=$OPTARG;;

Loading…
Cancel
Save