bug-bash
[Top][All Lists]
Advanced

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

Re: Enable compgen even when programmable completions are not available?


From: Fabien Orjollet
Subject: Re: Enable compgen even when programmable completions are not available?
Date: Tue, 27 Jun 2023 18:37:37 +0200

I'm far from having the skills of the people here. However, I found the
problem interesting. I think I've come up with a reasonable solution
(you tell me). Although it's not as short as Kerin Millar's, I think it
offers some improvements. I hope there are no particular weaknesses.
If it's of any use to anyone.


declare-P() {
   local curVar
   declare -a curVars

   readarray -t curVars <<<"$1"
   curVars=( "${curVars[@]%%=*}" )
   curVars=( "${curVars[@]##* }" )

   for curVar in "${curVars[@]}"; do
      ### unfortunately, we cannot use [[ -v "$curVar" ]]
      [[ "${curVar//[a-zA-Z0-9_]}" || \
         "${curVar:0:1}" == [0-9] || \
         ! "$curVar" =~ $2 ]] || printf '%s\n' "$curVar"
   done
}

declare-P "$(declare -p)"
echo "##################"
declare-P "$(declare -p)" "TERM"
echo "##################"
declare-P "$(declare -p)" "^BASH|^SHELL"



reply via email to

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