home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / lintian < prev    next >
Encoding:
Text File  |  2010-11-16  |  5.9 KB  |  187 lines

  1. # -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
  2. # ex: ts=8 sw=8 noet filetype=sh
  3. #
  4. # bash completion for lintian(1) and lintian-info(1)
  5.  
  6. have lintian && {
  7. _lintian_tags() {
  8.     local match search tags
  9.  
  10.     tags=$( grep -e ^Tag /usr/share/lintian/checks/*.desc | cut -d\  -f2 )
  11.     if [[ "$cur" == *, ]]; then
  12.         search=${cur//,/ }
  13.         for item in $search; do
  14.             match=$(grep -nE "^Tag: $item$" /usr/share/lintian/checks/*.desc \
  15.                     | cut -d: -f1 )
  16.             tags=$( echo $tags | sed -e "s/\<$item\>//g" )
  17.         done
  18.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$tags") )
  19.     elif [[ "$cur" == *,* ]]; then
  20.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -P "${cur%,*}," -W "$tags" -- \
  21.                                       "${cur##*,}") )
  22.     else
  23.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$tags" -- "$cur") )
  24.     fi
  25.     return 0
  26. }
  27.  
  28. _lintian_checks() {
  29.     local match search todisable checks
  30.  
  31.     checks=$(grep -e ^Check-Script -e ^Abbrev \
  32.              /usr/share/lintian/checks/*.desc | cut -d\  -f2 )
  33.     if [[ "$cur" == *, ]]; then
  34.         search=${cur//,/ }
  35.         for item in $search; do
  36.             match=$(grep -nE "^(Check-Script|Abbrev): $item$" \
  37.                     /usr/share/lintian/checks/*.desc | cut -d: -f1 )
  38.             todisable=$(grep -e ^Check-Script -e ^Abbrev $match | \
  39.                         cut -d\  -f2 )
  40.             for name in $todisable; do
  41.                 checks=$( echo $checks | sed -e "s/\<$name\>//g" )
  42.             done
  43.         done
  44.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$checks") )
  45.     elif [[ "$cur" == *,* ]]; then
  46.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -P "${cur%,*}," -W "$checks" \
  47.                                       -- "${cur##*,}") )
  48.     else
  49.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$checks" -- "$cur") )
  50.     fi
  51.     return 0
  52. }
  53.  
  54. _lintian_infos() {
  55.     local match search infos
  56.  
  57.     infos=$(grep -e ^Collector /usr/share/lintian/collection/*.desc \
  58.             | cut -d\  -f2 )
  59.     if [[ "$cur" == *, ]]; then
  60.         search=${cur//,/ }
  61.         for item in $search; do
  62.             match=$( grep -nE "^Collector: $item$" \
  63.                     /usr/share/lintian/collection/*.desc | cut -d: -f1 )
  64.             infos=$( echo $infos | sed -e "s/\<$item\>//g" )
  65.         done
  66.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$infos") )
  67.     elif [[ "$cur" == *,* ]]; then
  68.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -P "${cur%,*}," -W "$infos" \
  69.                                       -- "${cur##*,}") )
  70.     else
  71.         COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$infos" -- "$cur") )
  72.     fi
  73.     return 0
  74. }
  75.  
  76. _lintian_arches() {
  77.     return 0
  78. }
  79.  
  80. _lintian() {
  81.     local cur prev action lint_actions general_opts behaviour_opts \
  82.           configuration_opts selection_opts
  83.  
  84.     _get_comp_words_by_ref cur prev
  85.  
  86.     lint_actions="--setup-lab --remove-lab --check --check-part --tags \
  87.                   --tags-from-file --ftp-master-rejects --dont-check-part \
  88.                   --unpack --remove"
  89.     general_opts="--help --version --print-version --verbose --debug --quiet"
  90.     behaviour_opts="--info --display-info --display-experimental --pedantic \
  91.                     --display-level --suppress-tags --unpack-level \
  92.                     --suppress-tags-from-file --no-override --show-overrides \
  93.                     --color --unpack-info --md5sums --checksums --allow-root \
  94.                     --fail-on-warnings --keep-lab"
  95.     configuration_opts="--cfg --lab --archivedir --dist --area --section \
  96.                         --arch --root"
  97.     selection_opts="--all --binary --source --udeb --packages-file"
  98.  
  99.     if [[ "$prev" = -* ]]; then
  100.         case $prev in
  101.             -C|--check-part|-X|--dont-check-part)
  102.                 _lintian_checks
  103.                 ;;
  104.             -T|--tags|--suppress-tags)
  105.                 _lintian_tags
  106.                 ;;
  107.             --tags-from-file|--suppress-tags-from-file|--cfg|-p|\
  108.             --packages-file)
  109.                 _filedir
  110.                 ;;
  111.             --lab|--archivedir|--dist|--root)
  112.                 _filedir -d
  113.                 ;;
  114.             -l|--unpack-level)
  115.                 COMPREPLY=($(compgen -W "0 none 1 basic 2 contents" -- \
  116.                              "$cur"))
  117.                 ;;
  118.             --color)
  119.                 COMPREPLY=($(compgen -W "never always auto html" -- "$cur"))
  120.                 ;;
  121.             -U|--unpack-info)
  122.                 _lintian_infos
  123.                 ;;
  124.             --area|--section)
  125.                 COMPREPLY=($(compgen -W "main contrib non-free" -- "$cur"))
  126.                 ;;
  127.             --arch)
  128.                 ;;
  129.         esac
  130.     fi
  131.  
  132.     case "$cur" in
  133.         --*)
  134.             COMPREPLY=($(compgen -W "$lint_actions $general_opts \
  135.                          $behaviour_opts $configuration_opts" -- "$cur"))
  136.             ;;
  137.         *,)
  138.             # If we're here, the user is trying to complete on
  139.             # --action tag,tag,<TAB>
  140.             # Only few actions permit that, re-complete them now.
  141.             echo $prev
  142.             case "$prev" in
  143.                 -C|--check-part|-X|--dont-check-part)
  144.                     _lintian_checks
  145.                     ;;
  146.                 -T|--tags|--suppress-tags)
  147.                     _lintian_tags
  148.                     ;;
  149.                 -U|--unpack-info)
  150.                     _lintian_infos
  151.                     ;;
  152.             esac
  153.             ;;
  154.         *)
  155.             _filedir '@(?(u)deb|changes|dsc)'
  156.             ;;
  157.     esac
  158.     return 0
  159. }
  160.  
  161. _lintian_info() {
  162.     local cur prev
  163.  
  164.     _get_comp_words_by_ref cur prev
  165.  
  166.     case "$prev" in
  167.         -t|--tags)
  168.             _lintian_tags
  169.             return 0
  170.             ;;
  171.     esac
  172.  
  173.     case "$cur" in
  174.         --*)
  175.             COMPREPLY=($(compgen -W "--annotate --help --tags" -- "$cur"))
  176.             ;;
  177.         *)
  178.             _filedir
  179.             ;;
  180.     esac
  181.     return 0
  182. }
  183.  
  184. complete -F _lintian -o filenames lintian
  185. complete -F _lintian_info -o filenames lintian-info
  186. }
  187.