summaryrefslogtreecommitdiffstats
path: root/scratch/bash-3.1/examples/complete/complete.gnu-longopt
diff options
context:
space:
mode:
authorPete Travis <immanetize@fedoraproject.org>2014-09-26 14:42:22 -0600
committerPete Travis <immanetize@fedoraproject.org>2014-09-26 14:42:22 -0600
commit46c50fce0354d81d347a8055314a688fc8aa9f52 (patch)
treeb7f6c49e1225f949a9c21da6afa52fd04a2484fd /scratch/bash-3.1/examples/complete/complete.gnu-longopt
parentfe5673aed2053463a7164ec5e7b609877340c0fa (diff)
downloadrpmbuild-obs-product.tar.gz
rpmbuild-obs-product.tar.xz
rpmbuild-obs-product.zip
bash sourcesobs-product
Diffstat (limited to 'scratch/bash-3.1/examples/complete/complete.gnu-longopt')
-rw-r--r--scratch/bash-3.1/examples/complete/complete.gnu-longopt43
1 files changed, 43 insertions, 0 deletions
diff --git a/scratch/bash-3.1/examples/complete/complete.gnu-longopt b/scratch/bash-3.1/examples/complete/complete.gnu-longopt
new file mode 100644
index 0000000..c55b436
--- /dev/null
+++ b/scratch/bash-3.1/examples/complete/complete.gnu-longopt
@@ -0,0 +1,43 @@
+#
+# Originally from:
+#
+#Message-ID: <3B13EC65.179451AE@wanadoo.fr>
+#Date: Tue, 29 May 2001 20:37:25 +0200
+#From: Manu Rouat <emmanuel.rouat@wanadoo.fr>
+#Subject: [bash] Universal command options completion?
+#
+#
+#In the recent versions of bash (after 2.04) programmable
+#completion is available. A useful completion function
+#is , for a particular command, to enumerate all flags
+#that can be used in the command. Now, most GNU unix
+#commands have so-called 'long options' for example:
+#
+#ls --color=always --no-group --size
+#
+#and these are all listed when you issue a '--help' flag.
+#So the idea is to use that, then parse the output of the
+#'--help' and reinject this to compgen. The basis of the
+#following 'universal' completion funtion was the _configure_func'
+#written by Ian McDonnald (or is it Chet Ramey ?)
+#A dedicated function will always be better, but this is quite
+#convenient. I chose to use 'long options' because they are
+#easy to parse and explicit too (it's the point I guess...)
+#Lots of room for improvement !
+
+_longopt_func ()
+{
+ case "$2" in
+ -*) ;;
+ *) return ;;
+ esac
+
+ case "$1" in
+ \~*) eval cmd=$1 ;;
+ *) cmd="$1" ;;
+ esac
+ COMPREPLY=( $("$cmd" --help | sed -e '/--/!d' -e 's/.*--\([^ ]*\).*/--\1/'| \
+grep ^"$2" |sort -u) )
+}
+
+complete -o default -F _longopt_func ldd wget bash id info # some examples that work