[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Command completion with * in the middle?
From: |
Koichi Murase |
Subject: |
Re: [Help-bash] Command completion with * in the middle? |
Date: |
Sun, 27 Jan 2019 10:45:12 +0900 |
> But I feel the completion is sluggish. I think this is due to the
> subshell involved in $(). Is it? Is there a way to directly write the
> output of compgen to COMPREPLY without invoking another process?
>
> f() { COMPREPLY=($(compgen -c -X '!'"$3")); }
If you don't want to invoke another process, for example, you can
write the `compgen' output to a temporary file and then read it into
`COMPREPLY' using `mapfile' builtin.
f() {
compgen -c -X '!'"$3" > your-temporary-file
mapfile -t COMPREPLY < your-temporary-file
}
But here the bottleneck seems to be `compgen' itself but not the
command substitution. In my environment, the following additional
arguments to `compgen' significantly improved the performance:
f() {
local globchars='*?['
shopt -q extglob && globchars+='address@hidden'
local head=${3%%["$globchars"]*}
COMPREPLY=($(compgen -c -X '!'"$3" -- "$head"))
}
Best regards,
Koichi
- Re: [Help-bash] Command completion with * in the middle?, (continued)
- Re: [Help-bash] Command completion with * in the middle?, Chet Ramey, 2019/01/20
- Re: [Help-bash] Command completion with * in the middle?, Grisha Levit, 2019/01/20
- Re: [Help-bash] Command completion with * in the middle?, Chet Ramey, 2019/01/20
- Re: [Help-bash] Command completion with * in the middle?, Peng Yu, 2019/01/22
- Re: [Help-bash] Command completion with * in the middle?, Chet Ramey, 2019/01/22
- Re: [Help-bash] Command completion with * in the middle?, Peng Yu, 2019/01/22
- Re: [Help-bash] Command completion with * in the middle?, Chet Ramey, 2019/01/22
- Re: [Help-bash] Command completion with * in the middle?, Peng Yu, 2019/01/22
- Re: [Help-bash] Command completion with * in the middle?, Chet Ramey, 2019/01/22
- Re: [Help-bash] Command completion with * in the middle?, Peng Yu, 2019/01/22
- Re: [Help-bash] Command completion with * in the middle?,
Koichi Murase <=
- Re: [Help-bash] Command completion with * in the middle?, Peng Yu, 2019/01/26
- Re: [Help-bash] Command completion with * in the middle?, Peng Yu, 2019/01/28
- Re: [Help-bash] Command completion with * in the middle?, doark, 2019/01/26
- Re: [Help-bash] Command completion with * in the middle?, Koichi Murase, 2019/01/26
Re: [Help-bash] Command completion with * in the middle?, Peng Yu, 2019/01/22
Re: [Help-bash] Command completion with * in the middle?, Greg Wooledge, 2019/01/21