[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: programmable completion: completing filenames with default Readline
From: |
Jeremy Lin |
Subject: |
Re: programmable completion: completing filenames with default Readline behavior |
Date: |
Tue, 1 Oct 2013 13:55:46 -0700 |
On Tue, Oct 1, 2013 at 1:35 PM, Chet Ramey <chet.ramey@case.edu> wrote:
> On 9/27/13 3:57 AM, Jeremy Lin wrote:
>> I'm writing a completion where, in some cases, I'd like to use
>> COMPREPLY=() to indicate that no more arguments to a command are
>> expected, but in other cases, I'd like to offer the default Readline
>> behavior for filename completions.
>>
>> So, if I have a directory 'foo', I'd like the shell to first complete
>> with 'foo/' and then offer to complete files under 'foo'. But if I do
>> something like COMPREPLY=($(compgen -f -- "$cur")), then I simply get
>> a completion of 'foo' (with a space appended).
>>
>> I know I can pass "-o default" to get Readline's default filename
>> completion when COMPREPLY is empty, but then that seems to preclude
>> using COMPREPLY=() to deny completions.
>
> The `compopt' builtin was intended to add this kind of dynamism to
> programmable completion shell functions. You can install a completion
> without -o default and turn it on using compopt when the completion
> function is executed. It appears to be lightly used, so there are
> probably some usability improvements to be made there. For instance, I
> think that options, once set using compopt, remain set and need to be
> manually disabled. I'm waiting for some more reports from people using
> it before I decide how (or whether) to change it.
>
> Chet
Thanks, I actually ended up with the same solution (for Bash 4.0 and above,
where 'compopt' is available, anyway). I just set '+o default' at the top of the
completion function and then set '-o default' as needed. Unfortunately, for
earlier versions of Bash, the workaround I mentioned previously seems to be
about as good as it gets.
In future versions of Bash, it would be nice if the default Readline completion
could be invoked explicitly, rather than requiring this 'compopt' workaround.
Jeremy