help-bash
[Top][All Lists]
Advanced

[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



reply via email to

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