vbuilder-bash-completion.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. [ -z "$BASH_VERSION" ] && return
  2. _filedir()
  3. {
  4. local IFS=$'\t\n' xspec #glob
  5. #glob=$(set +o|grep noglob) # save glob setting.
  6. #set -f # disable pathname expansion (globbing)
  7. xspec=${1:+"!*.$1"} # set only if glob passed in as $1
  8. COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \
  9. $( compgen -d -- "$cur" ) )
  10. #eval "$glob" # restore glob setting.
  11. }
  12. _vbuilder()
  13. {
  14. local opts cur prev first
  15. COMPREPLY=()
  16. cur="${COMP_WORDS[COMP_CWORD]}"
  17. prev="${COMP_WORDS[COMP_CWORD-1]}"
  18. first="${COMP_WORDS[1]}"
  19. ## The basic options we'll complete.
  20. options="--version --arch --dist-upgrade --target --with-compat32"
  21. actions="--clean --build --build-rpm --install-rpm --remove-rpm"
  22. opts="$options $actions"
  23. _arch=$(rpm --eval %_arch)
  24. in_options=0
  25. ## Complete the arguments to some of the basic commands.
  26. case "${prev}" in
  27. --version)
  28. if [ "$_arch" = "x86_64" ]; then
  29. local running="VineSeed VineSeed_i386 5.0 5.0_i386 4.2_i386"
  30. else
  31. local running="VineSeed 5.0 4.2"
  32. fi
  33. COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
  34. ;;
  35. --arch)
  36. local running="i386 ppc x86_64"
  37. COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
  38. ;;
  39. --target)
  40. local running="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
  41. COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
  42. ;;
  43. --build-rpm)
  44. if [ $COMP_CWORD -eq 1 -o "${COMPREPLY+set}" != "set" ]; then
  45. _filedir 'src.rpm'
  46. fi
  47. ;;
  48. --install-rpm|--remove-rpm)
  49. if [ $COMP_CWORD -eq 1 -o "${COMPREPLY+set}" != "set" ]; then
  50. _filedir 'rpm'
  51. fi
  52. ;;
  53. *)
  54. COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
  55. #return 0
  56. ;;
  57. esac
  58. if [[ "${cur}" == -* ]] ; then
  59. COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
  60. #return 0
  61. fi
  62. }
  63. complete -o filenames -o nospace -F _vbuilder vbuilder
  64. ### end of file