vbuilder-bash-completion.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 --unionfs --target --with-compat32"
  21. actions="--clean --build --build-rpm --install-rpm --remove-rpm \
  22. clean build build-rpm install-rpm remove-rpm"
  23. opts="$options $actions"
  24. _arch=$(rpm --eval %_arch)
  25. in_options=0
  26. ## Complete the arguments to some of the basic commands.
  27. case "${prev}" in
  28. --version)
  29. if [ "$_arch" = "x86_64" ]; then
  30. local running="VineSeed VineSeed_i386 5.1 5.1_i386 4.2_i386"
  31. else
  32. local running="VineSeed 5.1 4.2"
  33. fi
  34. COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
  35. ;;
  36. --arch)
  37. local running="i386 ppc x86_64"
  38. COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
  39. ;;
  40. --target)
  41. local running="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
  42. COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
  43. ;;
  44. --build-rpm|build-rpm)
  45. if [ $COMP_CWORD -eq 1 -o "${COMPREPLY+set}" != "set" ]; then
  46. _filedir 'src.rpm'
  47. fi
  48. ;;
  49. --install-rpm|install-rpm|--remove-rpm|remove-rpm)
  50. if [ $COMP_CWORD -eq 1 -o "${COMPREPLY+set}" != "set" ]; then
  51. _filedir 'rpm'
  52. fi
  53. ;;
  54. *)
  55. COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
  56. #return 0
  57. ;;
  58. esac
  59. if [[ "${cur}" == -* ]] ; then
  60. COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
  61. #return 0
  62. fi
  63. }
  64. complete -o filenames -o nospace -F _vbuilder vbuilder
  65. ### end of file