bug-bash
[Top][All Lists]
Advanced

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

Re: How to autocomplete after 'which'?


From: Peng Yu
Subject: Re: How to autocomplete after 'which'?
Date: Fri, 21 May 2010 11:41:43 -0500

On Fri, May 21, 2010 at 11:06 AM, Eric Blake <eblake@redhat.com> wrote:
> 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.

I see the following error. What is wrong with my bash?

$ complete -p python
bash: complete: python: no completion specification
$ type _python
bash: type: _python: not found

-- 
Regards,
Peng



reply via email to

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