4 #Message-ID: <3B13EC65.179451AE@wanadoo.fr>
5 #Date: Tue, 29 May 2001 20:37:25 +0200
6 #From: Manu Rouat <emmanuel.rouat@wanadoo.fr>
7 #Subject: [bash] Universal command options completion?
10 #In the recent versions of bash (after 2.04) programmable
11 #completion is available. A useful completion function
12 #is , for a particular command, to enumerate all flags
13 #that can be used in the command. Now, most GNU unix
14 #commands have so-called 'long options' for example:
16 #ls --color=always --no-group --size
18 #and these are all listed when you issue a '--help' flag.
19 #So the idea is to use that, then parse the output of the
20 #'--help' and reinject this to compgen. The basis of the
21 #following 'universal' completion funtion was the _configure_func'
22 #written by Ian McDonnald (or is it Chet Ramey ?)
23 #A dedicated function will always be better, but this is quite
24 #convenient. I chose to use 'long options' because they are
25 #easy to parse and explicit too (it's the point I guess...)
26 #Lots of room for improvement !
39 COMPREPLY=( $("$cmd" --help | sed -e '/--/!d' -e 's/.*--\([^ ]*\).*/--\1/'| \
40 grep ^"$2" |sort -u) )
43 complete -o default -F _longopt_func ldd wget bash id info # some examples that work