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: Peng Yu
Subject: Re: [Help-bash] Command completion with * in the middle?
Date: Mon, 28 Jan 2019 13:12:01 -0600

> > f() {
> >   local globchars='*?['
> >   shopt -q extglob && globchars+='address@hidden'
> >   local head=${3%%["$globchars"]*}
> >   COMPREPLY=($(compgen -c -X '!'"$3" -- "$head"))
> > }
>
> Indeed. This is much faster. Thanks.

This is buggy. I type bash<TAB>, I will miss commands starting with bash.

So I fix it with a test.

function __pattern_complete {
  local globchars='*?['
  shopt -q extglob && globchars+='address@hidden'
  local head=${3%%["$globchars"]*}
  if [[ $3 == $head ]]; then
    COMPREPLY=($(compgen -c -- "$head"))
  else
    COMPREPLY=($(compgen -c -X '!'"$3" -- "$head"))
  fi
}

complete -I -F __pattern_complete -o bashdefault

-- 
Regards,
Peng



reply via email to

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