[Bash-completion-devel] Completing $something-separated lists

David Paleino dapal at debian.org
Sun Dec 27 22:55:53 UTC 2009


Hello people,
I'm writing a completion for lintian (oh, well, improving one I already wrote 
and put in Debian's BTS for reference), and I'm at the point of needing to 
complete comma-separated lists.

I've come up with this, but it has a drawback (paths abbreviated for wrapping 
purposes):

_lintian_checks() {
  local match search todisable checks

  checks=$( grep -e ^Check-Script -e ^Abbrev *.desc | cut -d\  -f2 )
  if [[ "$cur" == *, ]]; then
    search=${cur//,/ }
    for item in $search; do
      match=$( grep -nE "^(Check-Script|Abbrev): $item$" *.desc | \
          cut -d: -f1 )
      todisable=$( grep -e ^Check-Script -e ^Abbrev $match | cut -d\  -f2 )
      for name in $todisable; do
        checks=$( echo $checks | sed -e "s/\<$name\>//g" )
      done
    done
    COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$checks") )
  elif [[ "$cur" == *,* ]]; then
[*] COMPREPLY=( ${COMPREPLY[@]} $(compgen -P "${cur%,*}," -W "$checks" -- 
"${cur##*,}") )
  else
    COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$checks" -- "$cur") )
  fi
  return 0
}

The "culprit" of the thing working/the drawback is the line marked with [*]. 
In fact, without adding -P "..", $cur is set to the last word of the list, 
i.e.:

  $ foo --bar a,b,c<TAB>

returns

  $ foo --bar c

To overcome this, I added -P, but unfortunately this gives: 


$ lintian --check-part cruft,description,drm,etcfiles,f<TAB>
cruft,description,drm,etcfiles,fields
cruft,description,drm,etcfiles,fil
cruft,description,drm,etcfiles,files
cruft,description,drm,etcfiles,fld


Any idea on how to solve this? :)

David

-- 
 . ''`.   Debian developer | http://wiki.debian.org/DavidPaleino
 : :'  : Linuxer #334216 --|-- http://www.hanskalabs.net/
 `. `'`  GPG: 1392B174 ----|---- http://snipr.com/qa_page
   `-   2BAB C625 4E66 E7B8 450A C3E1 E6AA 9017 1392 B174
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20091227/a3f59554/attachment.pgp>


More information about the Bash-completion-devel mailing list