bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling complete within completion


From: Marcus Harnisch
Subject: Calling complete within completion
Date: Fri, 2 May 2003 22:36:22 -0400

Hi *,

I tried to bootstrap command completion using a method that is more
appropriate for me than loading all completions at once. The code from
the bash completion project, which checks the path first, doesn't work
for me simply because a lot of commands I use are not in my PATH when
I start the shell, while I don't care about a lot of other commands
that *are* in my PATH.

My idea was to have a function _init that is used to "complete" every
command. When I hit <TAB> to complete the command, _init would load
the actual completion code for a particular command from a file. That
code would also take care of switching the completion the actual
completion function to be eventually used.

When I tried that, bash (2.05b+patches) crashes badly.

Is it a bug that the completion function for a command cannot be
changed from within the current completion function? If it is a
feature, I would certainly prefer an error message over a crashing
shell ;-)

It'd be great if we could get that functionality, because it would
provide a very elegant (IMHO) completion-on-demand.

Example (simplified, I actually have a more sophisticated version):

,----[ $HOME/.bash_completion ]
| _init () {
|       cmd=${COMP_WORDS[0]}
|       test -f $HOME/.bash_completion.d/$cmd \
|          && . $HOME/.bash_completion.d/$cmd
| }
| 
| complete -F _init foo
| complete -F _init bar
`----

,----[ $HOME/.bash_completion.d/foo ]
| _foo () {
|      cur=${COMP_WORDS[$COMP_CWORD]}
|      COMPREPLY=( $(compgen -W 'quux quax' -- $cur) )
| }
| 
| complete -F _foo foo
`----

Does anyone know of a workaround?

Best regards,
     Marcus




reply via email to

[Prev in Thread] Current Thread [Next in Thread]