[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 45182e180964c36aa8ac60feb1eafa8194cdda0a

Ville Skyttä ville.skytta at iki.fi
Tue Apr 14 20:16:51 UTC 2009


The following commit has been merged in the master branch:
commit 45182e180964c36aa8ac60feb1eafa8194cdda0a
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Tue Apr 14 23:16:47 2009 +0300

    Add _split_longopt() helper for improved handling of long options that take arguments in both "--foo bar" and "--foo=bar" formats.

diff --git a/CHANGES b/CHANGES
index 78e8d76..c424bd7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,8 @@ bash-completion (1.x)
   * Use POSIX compliant arguments to tail in mkisofs completion.
   * Protect various completions from unusual user input by not embedding the
     input in external command arguments.
+  * Add _split_longopt() helper for improved handling of long options that
+    take arguments in both "--foo bar" and "--foo=bar" formats.
 
   [ Todd Zullinger ]
   * Make yum complete on filenames after install, deplist, update and upgrade
diff --git a/bash_completion b/bash_completion
index b01eba5..07827fb 100644
--- a/bash_completion
+++ b/bash_completion
@@ -317,6 +317,23 @@ _filedir()
 	COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )
 }
 
+# This function splits $cur=--foo=bar into $prev=--foo, $cur=bar, making it
+# easier to support both "--foo bar" and "--foo=bar" style completions.
+# Returns 0 if current option was split, 1 otherwise.
+#
+_split_longopt()
+{
+	if [[ "$cur" == --?*=* ]]; then
+		# Cut also backslash before '=' in case it ended up there
+		# for some reason.
+		prev="${cur%%?(\\)=*}"
+		cur="${cur#*=}"
+		return 0
+	fi
+
+	return 1
+}
+
 # This function tries to parse the output of $command --help
 #
 _parse_help() {

-- 
bash-completion



More information about the Bash-completion-commits mailing list