help-bash
[Top][All Lists]
Advanced

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

Re: Exclude builtins from command completion


From: Chet Ramey
Subject: Re: Exclude builtins from command completion
Date: Sat, 18 Jan 2020 19:05:46 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.3.1

On 1/17/20 4:18 PM, kaycee gb wrote:
> Le Fri, 17 Jan 2020 13:59:14 -0500,
> Chet Ramey <address@hidden> a écrit :
> 
>> On 1/17/20 12:18 PM, kaycee gb wrote:
>>
>>> When I was trying to achieve that, by accident I entered a colon ":" at an
>>> empty prompt. I expected that it will do nothing but in fact that lists all
>>> files in the current directory.

Did you try and complete the `:' or after inserting a space or similar?
If you try and complete the `:', what happens depends on whether you have
a programmable completion function set.

Either way, since readline considers `:' a word separator character, the
colon it is not part of the word readline wants to be completed.

>>
>> This comes up every now and then.
>>
>> http://lists.gnu.org/archive/html/bug-bash/2003-01/msg00088.html
>> https://lists.gnu.org/archive/html/bug-bash/2016-12/msg00029.html
>> https://lists.gnu.org/archive/html/bug-bash/2019-06/msg00038.html
>>
>> In this case, readline completes an empty filename.

That's the default readline behavior.

If there are programmable completions installed, bash runs through the
programmable completion code attempting to complete the word readline
asks it to (the empty string). It's not in a command position, though,
so it won't run the -I compspec. It finds that `:' is the command name,
but it finds that there's no separator between the end of the command
name and the word readline wants to complete, so there's no reason to
call its programmable completion. At that point, it attempts the default
bash completion given the text readline asked for it to complete -- the
empty string. That doesn't do anything special, so readline performs
its default filename completion.

> Removing colon from wordbreaks COMP_WORDBREAKS=${COMP_WORDBREAKS//:} now do
> nothing. 

Now, readline wants ":" as the word to be completed. In this case, bash
will call the -I compspec, if any, and ask to complete `:'. If you have
your command name completion function that ignores builtins, it will find
no matches and do nothing. If you have some other -I compspec, it will
insert whatever that returns as usual. If you use the default bash
completion, it will complete the `:' and insert a space.

> 
> By curiousity, why other breakwords do not have the same comportment ? Some do
> nothing, some list files from CWD, some list all commands from my custom list.
> Is there a place where I can have simple information for that ?

It depends on the character and the meaning it has to the shell. `>' will
perform filename completion if you have it in COMP_WORDBREAKS and do
nothing if you don't, since you probably don't have any commands or
filenames beginning with `>'. `|' will do command completion, since the
(empty) word readline wants to complete is in a command position. In
general, if the character is in COMP_WORDBREAKS, you'll get readline
trying completion on the empty string, and whether that is command or
filename completion depends on whether the character is one that separates
commands; if it's not, readline will attempt to complete a word starting
with that character.

> Moreover, the links above talks about filename completion. In this case isn't
> it command completion ? Shouldn't it behave differently ? Or like in E13,
> filename completion and command completion enter in word completion in
> general ? 

As above, yes or no.

> 
> And last, with COMP_WORDBREAKS empty, quote and double quote continue to list
> files from CWD. Others do nothing. Shouldn't all do nothing ?

Readline understands how to complete within quoted strings regardless of
the value of COMP_WORDBREAKS/rl_completer_word_break_characters. This is
controlled  by a separate application-settable variable,
rl_completer_quote_characters. Bash sets that to the usual set of shell
quoting characters.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

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