[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:
Hello,
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:
buildpat()
{
builtins_pat=
set -- $(printf "%q " $(compgen -b -k "$1")) # to leave reserved words,
omit -k
[ $# -gt 0 ] && builtins_pat='@('"$(IFS='|' ; echo "$*")"')'
}
commandcomp()
{
local builtins_pat w
w="$2"
buildpat "$w"
if [ -n "$builtins_pat" ]; then
COMPREPLY=( $(shopt -s extglob ; compgen -c -X "$builtins_pat"
"$w") )
else
COMPREPLY=( $(compgen -c "$w") )
fi
}
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 http://tiswww.cwru.edu/~chet/
- Exclude builtins from command completion, kaycee gb, 2020/01/09
- Re: Exclude builtins from command completion,
Chet Ramey <=
- Re: Exclude builtins from command completion, kaycee gb, 2020/01/10
- Re: Exclude builtins from command completion, Greg Wooledge, 2020/01/13
- Re: Exclude builtins from command completion, kaycee gb, 2020/01/13
- Re: Exclude builtins from command completion, kaycee gb, 2020/01/17
- Re: Exclude builtins from command completion, Chet Ramey, 2020/01/17
- Re: Exclude builtins from command completion, kaycee gb, 2020/01/17
- Re: Exclude builtins from command completion, Chet Ramey, 2020/01/18
- Re: Exclude builtins from command completion, kaycee gb, 2020/01/23
- Re: Exclude builtins from command completion, Chet Ramey, 2020/01/23
- Re: Exclude builtins from command completion, kaycee gb, 2020/01/23