[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to autocomplete after 'which'?
From: |
Eric Blake |
Subject: |
Re: How to autocomplete after 'which'? |
Date: |
Fri, 21 May 2010 10:06:48 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b1 Mnenhy/0.8.2 Thunderbird/3.0.4 |
On 05/21/2010 09:50 AM, Peng Yu wrote:
> complete -c works. I'm not familar with bash-completion package. How
> to customize search path for each command.
By using appropriate complete invocations for each command, and lots of
shell functions.
>
> For exmaple, I want search in $PYTHONPATH after the command python.
bash-completion could do that for you, too.
$ complete -p python
complete -o filenames -F _python python
$ type _python
_python is a function
_python ()
{
local prev cur i;
COMPREPLY=();
cur=`_get_cword`;
prev=${COMP_WORDS[COMP_CWORD-1]##*/};
case "$prev" in
-Q)
COMPREPLY=($( compgen -W "old new warn warnall" -- "$cur" ));
return 0
;;
-W)
COMPREPLY=($( compgen -W "ignore default all module once
error" -- "$cur" ));
return 0
;;
-c)
_filedir '@(py|pyc|pyo)';
return 0
;;
!(python|-?))
[[ ${COMP_WORDS[COMP_CWORD-2]} != -@(Q|W) ]] && _filedir
;;
esac;
for ((i=0; i < ${#COMP_WORDS[@]}-1; i++ ))
do
if [[ ${COMP_WORDS[i]} == -c ]]; then
_filedir;
fi;
done;
if [[ "$cur" != -* ]]; then
_filedir '@(py|pyc|pyo)';
else
COMPREPLY=($( compgen -W "- -d -E -h -i -O -Q -S -t -u
-U -v -V -W -x -c" -- "$cur" ));
fi;
return 0
}
Actually, I don't see any mention of PYTHONPATH in that function, so you
may want to file an enhancement request against the bash-completion
package to improve their _python() function to also consider PYTHONPATH,
rather than just *.py[co] files.
>
> BTW, where is the manual for the -c option of complete. There are too
> many 'complete' in man bash. Would you please point me which section
> is relevant to complete -c.
'help complete' is the easiest way to see the short details; other than
that, look for complete under 'SHELL BUILTIN COMMANDS' in the man page.
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
Re: How to autocomplete after 'which'?, Eric Blake, 2010/05/21
Re: How to autocomplete after 'which'?, Marc Herbert, 2010/05/21