vbuilder-bash-completion.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 --category --dist-upgrade --unionfs --target --with-compat32"
  21. actions="clean build build-rpm install-rpm remove-rpm show-info"
  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.1 5.1_i386 4.2_i386"
  30. else
  31. local running="VineSeed 5.1 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. --category)
  40. local running="main proposed-updates,main plus,main nonfree,plus,main test,nonfree,plus,main test,plus,main test,main"
  41. COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
  42. ;;
  43. --target)
  44. local running="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
  45. COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
  46. ;;
  47. --build-rpm|build-rpm)
  48. if [ $COMP_CWORD -eq 1 -o "${COMPREPLY+set}" != "set" ]; then
  49. _filedir 'src.rpm'
  50. fi
  51. ;;
  52. --install-rpm|install-rpm|--remove-rpm|remove-rpm)
  53. if [ $COMP_CWORD -eq 1 -o "${COMPREPLY+set}" != "set" ]; then
  54. _filedir 'rpm'
  55. fi
  56. ;;
  57. *)
  58. COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
  59. #return 0
  60. ;;
  61. esac
  62. if [[ "${cur}" == -* ]] ; then
  63. COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
  64. #return 0
  65. fi
  66. }
  67. complete -o filenames -o nospace -F _vbuilder vbuilder
  68. ### end of file