[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Non-filename completions containing slashes and -o filenames
From: |
Ville Skyttä |
Subject: |
Re: Non-filename completions containing slashes and -o filenames |
Date: |
Mon, 15 Jun 2009 21:13:46 +0300 |
User-agent: |
KMail/1.11.3 (Linux/2.6.29.3-60.fc10.x86_64; KDE/4.2.3; x86_64; ; ) |
On Monday 15 June 2009, Chet Ramey wrote:
> Ville Skyttä wrote:
> > Hello,
> >
> > Apologies if this is not an appropriate list to post a question like this
> > (pointers elsewhere welcome), but here goes:
> >
> > I'm trying to figure out how to do the right thing with non-filename
> > completions containing slashes in a function that was passed to complete
> > along with -o filenames.
Thanks for the reply, Chet.
> I can't think, off the top of my head, how the completion function is
> supposed to distinguish between the two. There's no real difference
> between a string with slashes and a filename -- they are identical.
I don't know if it helps, but in my scenario, when I want to complete on non-
filename things containing slashes, filename completion is not necessary nor
wanted. To illustrate:
_foo()
{
if $something ; then
# Non-filename completion with stuff containing slashes desirable,
# no filename completion needed nor wanted
COMPREPLY=( $( compgen -W 'a/b c/d e/f/g' -- ${COMP_WORDS[COMP_CWORD]} ) )
return 0
fi
# Else filename completion as usual
}
complete -F _foo -o filenames foo
If you're interested in the actual case I'm asking this for, see _rpm_groups()
in contrib/rpm at http://git.debian.org/?p=bash-completion/bash-
completion.git;a=tree
> You could, I suppose, stat the arguments to see which correspond to
> real pathnames, but that isn't guaranteed accurate. Since you don't
> have control over what is passed to the completion function, trying to
> quote the slashes in a non-pathname argument won't work, either.
I've tried quoting the slashes in various ways, and failed to get it to make
any difference. But because I know whenever I want to complete on non-
filename things containing slashes and not filenames, and given your stat
thought above, do I understand correctly that there would at least
theoretically be a way to accomplish what I want?