[Top][All Lists]

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

Re: Exclude builtins from command completion

From: Chet Ramey
Subject: Re: Exclude builtins from command completion
Date: Fri, 10 Jan 2020 09:57:52 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.3.1

On 1/9/20 3:17 PM, kaycee gb wrote:

For one of my projects which works with bash completion, I'm looking for a way
to exclude bash builtin commands from the completion proposals. I already had
success with exclusion of commands from PATH.

After playing with options for complete -b/-c, compgen -b/-c, these commands are
still displayed when I type first 2 letters then <TAB><TAB>

# sh<TAB><TAB>
shift shopt show

I want that it matches just the last one.

I even tried with actions from complete enabled/disabled builtins without luck.
I'm not sure how actions work.

My bash version is 4.2.053-x86_64-2_slack14.1.

How can I achieve what I want to do ?

You can't do it on bash-4.2 (which is approximately nine years old) without
a lot of work.

It's pretty easy to do in bash-5.0. This script will do pretty much what you want:


set -- $(printf "%q " $(compgen -b -k "$1")) # to leave reserved words, omit -k
        [ $# -gt 0 ] && builtins_pat='@('"$(IFS='|' ; echo "$*")"')'

        local builtins_pat w

        buildpat "$w"
        if [ -n "$builtins_pat" ]; then
                COMPREPLY=( $(shopt -s extglob ; compgen -c -X "$builtins_pat" 
"$w") )
                COMPREPLY=( $(compgen -c "$w") )

complete -I -F commandcomp

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden

reply via email to

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