[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Behavior of 'complete -o filenames' unclear
From: |
Michael Siegel |
Subject: |
Re: [Help-bash] Behavior of 'complete -o filenames' unclear |
Date: |
Tue, 9 Oct 2018 17:07:03 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:60.0) Gecko/20100101 Thunderbird/60.0 |
Am 05.10.18 um 03:15 schrieb Chet Ramey:
> On 10/4/18 11:50 AM, Michael Siegel wrote:
>
>> 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.
Ok, thanks for clarifying that. So, I cannot rely on '-o filenames' to
do the escaping of shell special characters in the file names I put into
COMPREPLY, but will have to implement that myself. What would be the
best way to do this? I was thinking of piping the output of 'compgen' to
'sed' (after 'cut').
Apropos putting file names into COMPREPLY: After some further discussion
in #bash on Freenode, I have now sanitized the way this is done:
while IFS=$'\n' read -r line
do
COMPREPLY+=("$line")
done < <(compgen -f -- "$dbm_dir/${COMP_WORDS[COMP_CWORD]}" | \
cut -d '/' -f 5)
The reason I didn't use 'mapfile' is that I wanted to keep the script
compatible with Bash 3.x.
msi