From 21e8aa2522da88723b4e046bdc9366f445dee103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Sch=C3=B6ttl?= Date: Sat, 23 Jan 2016 22:03:46 -0800 Subject: [PATCH 1/3] 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. --- tdrop | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tdrop b/tdrop index 32dedce..0c5d978 100755 --- a/tdrop +++ b/tdrop @@ -91,8 +91,8 @@ do a) auto_detect_wm=true;; m) monitor_aware=true;; -) - OPTION=$(echo "$OPTARG" | awk -F '=' '{print $1}') - OPTARG=$(echo "$OPTARG" | awk -F '=' '{print $2}') + OPTION=${OPTARG%%=*} + OPTARG=${OPTARG#*=} case $OPTION in height) height=$OPTARG;; width) width=$OPTARG;; From 0c63e94588e646cbf894c67e3f6ed903af38e574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Sch=C3=B6ttl?= Date: Sat, 23 Jan 2016 22:35:40 -0800 Subject: [PATCH 2/3] Minor refactoring Should have exactly the same effect now. In case of no options: one white space after a shell command don't change anything. --- tdrop | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tdrop b/tdrop index 0c5d978..582f590 100755 --- a/tdrop +++ b/tdrop @@ -438,12 +438,7 @@ maybe_cancel_auto_show() { # term_create() { - local term_command - if [[ -n $program_flags ]]; then - term_command="$term $program_flags" - else - term_command=$term - fi + local term_command="$term $program_flags" if [[ $term == terminix ]]; then sleep_term_time=0.3 fi @@ -471,12 +466,7 @@ term_create() { } win_create() { - local win_command - if [[ -n $program_flags ]]; then - win_command="$term $program_flags" - else - win_command=$term - fi + local win_command="$term $program_flags" $win_command & # need to wait for window to be created sleep $sleep_win_time From 8cf2d6cc6ab57f88e6d7963f986fb74e7e9058ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Sch=C3=B6ttl?= Date: Sat, 23 Jan 2016 22:46:04 -0800 Subject: [PATCH 3/3] Avoid glob expansion on rhs and linter warning! --- tdrop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdrop b/tdrop index 582f590..4827d68 100755 --- a/tdrop +++ b/tdrop @@ -225,7 +225,7 @@ update_geometry_settings_for_monitor() { local last_monitor last_monitor=$(< /tmp/tdrop/last_monitor) echo "$current_monitor" > /tmp/tdrop/last_monitor - if [[ $current_monitor != $last_monitor ]]; then + if [[ $current_monitor != "$last_monitor" ]]; then monitor_changed=true fi }