help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Behavior of 'complete -o filenames' unclear


From: Chet Ramey
Subject: [Help-bash] Behavior of 'complete -o filenames' unclear
Date: Thu, 4 Oct 2018 21:15:45 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 10/4/18 11:50 AM, Michael Siegel wrote:
> Am 04.10.18 um 16:29 schrieb Chet Ramey:
>> On 10/4/18 4:46 AM, Michael Siegel wrote:
>>
>>> In that case, the shell will add a slash to the name, as if it were
>>> completing directory names within $PWD:
>>>
>>> ~/devel/sandbox/probe$ ls
>>> a_file  msiism/  tests/
>>> ~/devel/sandbox/probe$ dbm msi<Tab>  # Results in 'dbm msiism/'
>>> ~/devel/sandbox/probe$
>>>
>>> Now, the Bash Reference Manual does say that '-o filename' will "perform
>>> any filename-specific processing"[1], "like adding a slash to directory
>>> names"[1] and such. What I don't understand is why it is still adding
>>> the slash when completion is based on file names in $dbm_dir instead of
>>> $PWD.
>>
>> How would readline (because readline is adding the slash) know that the
>> possible completion should be interpreted relative to some other directory
>> and not $PWD? It's not an absolute pathname, the current working directory
>> hasn't changed, and there's not currently a way to direct readline
>> otherwise.
> 
> My understanding was that specifying a list of possible completions
> through 'compgen' would make the shell ignore $PWD for completions,
> unless you use 'complete' with the 'default' option later.

OK, that's an assumption. It just can't be verified using documentation or
evidence.

> The thing that appears odd to me here is: I'm telling the shell to use
> only the file names that exist in $dbm_dir as possible completions for
> arguments to 'dbm', but it's still looking for matches in $PWD.

How is the shell supposed to know that? You call compgen in a command
substitution subshell, which would isolate any directory change you
did (if you did one), and you take great care to cut off the path to
$dbm_dir in the returned words by piping the words through `cut'.

> Seems like I'm missing something about how these things work together.

Look at it this way. You return a list of words from your completion
function and tell readline to treat them as filenames. These filenames
are handled in the standard way: if they're not absolute, they are
relative to the current directory. These words are all relative pathnames,
since your completion function cuts $dbm_dir off the front, so when these
relative pathnames are inspected using stat(), the attributes returned are
going to depend on whether or not there is a file with that name in the
current directory.

Chet
-- 
``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]