home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20110725.etc.tar.gz / bradford.20110725.etc.tar / etc / bash_completion.d / yast2-completion.sh
Text File  |  2006-06-21  |  3KB  |  103 lines

  1. # yast2 completion
  2. # A Christmas gift from Carsten Hoeger
  3.  
  4. YAST=/sbin/yast
  5. # build a list of know yast modules
  6. MODLIST=($(LC_ALL=C $YAST -l| grep '^[a-z]' | grep -v "Available"))
  7.  
  8. _yast2 ()
  9. {
  10.         local cur prevprev prev len idx mod MODOPTS line opt rest
  11.         MODOPTS=()
  12.  
  13.     if [[ ${#COMP_WORDS[@]} -gt 4 ]]; then
  14.         return 0
  15.     fi
  16.         cur=${COMP_WORDS[COMP_CWORD]}
  17.         prev=${COMP_WORDS[COMP_CWORD-1]}
  18.     if [[ ${#COMP_WORDS[@]} -ge 3 ]]; then
  19.         prevprev=${COMP_WORDS[COMP_CWORD-2]}
  20.     fi
  21.         if [[ $cur == '-' ]]; then
  22.                 COMPREPLY=(-h -l -g -s)
  23.                 return 0
  24.         fi
  25.  
  26.     # iterate through all yast modules
  27.     for mod in ${MODLIST[@]}; do
  28.         # if argument before last argument is a yast module, 
  29.         # check it's available options
  30.         if [[ -n $prevprev && $prevprev == $mod ]]; then
  31.         # build option list
  32.         # prev is a module option
  33.                 while read line ; do
  34.                     case "$line" in
  35.                         Options:*)
  36.                         while read opt rest ; do
  37.                             case "$opt" in
  38.                                 "") break 2 ;;
  39.                                 *)  MODOPTS=("${MODOPTS[@]}" "$opt")
  40.                             esac
  41.                         done
  42.                         ;;
  43.                     esac
  44.                 done < <(LC_ALL=C $YAST $mod $prev help 2>&1)
  45.         len=${#cur}
  46.         idx=0
  47.         for pval in ${MODOPTS[@]}; do
  48.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  49.                         COMPREPLY[$idx]=$pval
  50.                         idx=$[$idx+1]
  51.             fi
  52.         done
  53.         return 0
  54.         fi
  55.         # previous option is a known yast module?
  56.         if [[ $prev == $mod ]]; then
  57.         # build option list
  58.                 while read line ; do
  59.                     case "$line" in
  60.                         Basic\ Syntax:*)
  61.                         while read rest rest opt rest ; do
  62.                             case "$opt" in
  63.                                 \<*\>) ;;
  64.                                 "") break ;;
  65.                                 *)  MODOPTS=("${MODOPTS[@]}" "$opt")
  66.                             esac
  67.                         done
  68.                         ;;
  69.                         Commands:*)
  70.                         while read opt rest ; do
  71.                             case "$opt" in
  72.                                 "") break 2 ;;
  73.                                 *)  MODOPTS=("${MODOPTS[@]}" "$opt")
  74.                             esac
  75.                         done
  76.                         ;;
  77.                     esac
  78.                 done < <(LC_ALL=C $YAST $mod help 2>&1)
  79.         len=${#cur}
  80.         idx=0
  81.         for pval in ${MODOPTS[@]}; do
  82.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  83.                         COMPREPLY[$idx]=$pval
  84.                         idx=$[$idx+1]
  85.             fi
  86.         done
  87.         return 0
  88.         fi
  89.     done
  90.  
  91.         len=${#cur}
  92.         idx=0
  93.         for pval in ${MODLIST[@]}; do
  94.                 if [[ "$cur" == "${pval:0:$len}" ]]; then
  95.                         COMPREPLY[$idx]=$pval
  96.                         idx=$[$idx+1]
  97.                 fi
  98.         done
  99.         return 0
  100. }
  101. complete -F _yast2 yast2
  102. complete -F _yast2 yast
  103.