Re: shell completion support for optparse/optik
Martin Blais <[email protected]> Tue, 16 Sep 2003 22:14:33 -0400
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Organization | Furius |
| Message-ID | <[email protected]> |
On Tuesday 16 September 2003 21:37, Greg Ward wrote: > On 16 September 2003, Martin Blais said: > > i've just had an idea, not sure if it's already been discussed for > > your optik package, just wondering what you think: > > > > i was thinking that given that the parser has a pretty complete > > description of the input parameters, it would probably be possible to > > write a single bash function for all optparse-using programs, to > > perform completion by invoking the program with a particular option, > > something like "--perform-complete"; the option parser, given it has > > seen that option, instead of returning, would return the completion > > string to the shell. > > Cute idea! And AFAIK you're the first to come up with it. > > > also, to deal with the arguments, we could give it some object/method to > > deal with completion for the arguments, say something like this:: > > > > parser = optparse.OptionParser(\ > > complete=optparse.GlobCompletion(['*.tar.gz', > > '*.tar.bz2']) > > I don't understand what the point of tihs is. e.g. if you press tab after that script, only the *.tar.gz and *.tar.bz2 files would be listed in the completion list. if there is a single "*.tar.gz" file in the directory, if will be appended to the command line. i called it GlobCompletion, as in "the list of valid input files for the script is described by the following list of globbing patterns". i can imagine more fancy methods, regular expressions, methods that depend on the parameters already specified on the cmdline, methods that check for specific files or names somewhere, etc. > > > any thoughts? do you think this is implementable? > > Dunno -- I don't know how programmable shell completion works. Feel > free to submit a patch, but keep it short and simple. And don't make it > specific to bash -- some of use zsh. ;-) (And being able to query an > OptionParser about what options it supports might be useful in other > contexts.) i think it goes like this in bash: you write a shell function, then you register it for completion with patterns. it has a specific set of inputs (i think parameters already specified on the cmdline at the moment TAB is pressed) and you set COMPREPLY variable for reply, which gets printed by the shell. i'll ask Ian from the bash-programmable completion fame, i'm sure he would have some interesting input regarding the feasibility of this, i'm not an expert either, but i think i could hack something together, if you're not using this already, it's a nice thing to have if you use bash: http://freshmeat.net/projects/bashcompletion/ cheers, ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf