compgen not displaying all expected suggestions

109 Views Asked by At

I need to add some bash shell completion with words read from a json file:

...
{
    'bundle': 'R20_B1002_ORDERSB1_FROMB1',
    'version':'0.1',
    'envs': ['DEV','QUAL','PREPROD2'],
},
{
    'bundle': 'R201_QA069_ETIQETTENS_FROMSAP',
    'version': '0.1',
    'envs': ['DEV','QUAL','QUAL2','PREPROD'],
}
...

To get a words list I can run this command line and it returns all expected words from my file :

grep  'bundle' liste_routes.py | sed "s/'bundle': '//" | sed "s/',//" | grep -v '#' 

for instance, with an addtional "grep R20" it returns :

R20_B1002_ORDERSB1_FROMB1
R201_QA069_ETIQETTENS_FROMSAP
R202_LOG287_LIVRAISONSORTANTE_FROMLSP
R203_PP052_FULLSTOCKSAP_FROMSAP
R204_CO062_PRIXTRANSF_FROMOLGA
R206_LOG419_NOMENCLBOMPROD_FROMTDX
R207_CERTIFNFGAZ
R208_SAL363_ARTICLEPRICING_FROMSAP
R209_LOG451_WHSCON_FROMTDX

Now I put this in this compgen file and source it i my bash session.

_find_routenames()
{
search="$cur"
grep  'bundle' liste_routes.py | sed "s/'bundle': '//" | sed "s/',//" | sed "s/\r//g" |  grep -v '#' | awk '{$1=$1;print}'
}

_esbdeploy_completions()
{
#local IFS=$'\n'

COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
cur="${COMP_WORDS[1]}"
COMPREPLY=( $( compgen -W "$(_find_routenames)" -- "$cur" ) )

#####  COMPREPLY=($(compgen -W "$(grep  'bundle' liste_routes.py | sed \"s/'bundle': '//\" | sed \"s/',//\" | grep -v '#')" -- "${COMP_WORDS}"))
}

complete -F _esbdeploy_completions d.py
complete -F _esbdeploy_completions deploy_karaf_v4.py
complete -F _esbdeploy_completions show.py

The problem is when I type

./d.py R20<TAB>

I get thoses suggestions :

R201_QA069_ETIQETTENS_FROMSAP          R203_PP052_FULLSTOCKSAP_FROMSAP        R206_LOG419_NOMENCLBOMPROD_FROMTDX     R208_SAL363_ARTICLEPRICING_FROMSAP
R202_LOG287_LIVRAISONSORTANTE_FROMLSP  R204_CO062_PRIXTRANSF_FROMOLGA         R207_CERTIFNFGAZ                       R209_LOG451_WHSCON_FROMTDX

It misses R20_B1002_ORDERSB1_FROMB1 from my first grep test. I don't think it deals with the underscore , as other tests with "./d.py R10" do suggests "R10_xxxx".

0

There are 0 best solutions below