gbs.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/bash
  2. # copy this file to /etc/bash_completion.d/
  3. # or copy it to your home directory, rename it as .gbs.bash and add '. .gbs.bash' to ~/.bashrc
  4. __gbscomp ()
  5. {
  6. local cur_="${3-$cur}"
  7. case "$cur_" in
  8. --*=)
  9. COMPREPLY=()
  10. ;;
  11. *)
  12. local IFS=$'\n'
  13. COMPREPLY=($(compgen -P "${2-}"\
  14. -W "$(__gbscomp_1 "${1-}" "${4-}")"\
  15. -- "$cur_"))
  16. ;;
  17. esac
  18. }
  19. __gbscomp_1 ()
  20. {
  21. local c IFS=$' \t\n'
  22. for c in $1; do
  23. c="$c$2"
  24. case $c in
  25. --*=*|*.) ;;
  26. *) c="$c " ;;
  27. esac
  28. printf '%s\n' "$c"
  29. done
  30. }
  31. __gbs_main ()
  32. {
  33. COMPREPLY=()
  34. local cur prev cword cfgdir=/usr/share/gbs
  35. local -a words
  36. if declare -F _get_comp_words_by_ref &>/dev/null ; then
  37. _get_comp_words_by_ref cur prev words cword
  38. else
  39. cur=$2 prev=$3 words=("${COMP_WORDS[@]}") cword=$COMP_CWORD
  40. fi
  41. local i c=1 command
  42. while [ $c -lt $cword ]; do
  43. i="${words[c]}"
  44. case "$i" in
  45. --help) command="help"; break;;
  46. -c) let c++ ;;
  47. -*) ;;
  48. *) command="$i"; break;;
  49. esac
  50. let c++
  51. done
  52. __gbs && return
  53. }
  54. __gbs_find_on_cmdline ()
  55. {
  56. local word subcommand c=1
  57. while [ $c -lt $cword ]; do
  58. word="${words[c]}"
  59. for subcommand in $1; do
  60. if [ "$subcommand" = "$word" ]; then
  61. echo "$subcommand"
  62. return
  63. fi
  64. done
  65. let c++
  66. done
  67. }
  68. __gbs ()
  69. {
  70. subcommands="
  71. build createimage remotebuild submit import export changelog chroot clone pull
  72. "
  73. common_opts="--upstream-tag= --upstream-branch= --squash-patches-until=
  74. --packaging-dir= --no-patch-export"
  75. lb_opts="
  76. --arch= --repository= --dist= --buildroot= --clean
  77. --include-all --extra-packs= --spec= --commit= --cache
  78. --skip-conf-repos --profile= --noinit --keep-packs
  79. --clean-repos --define --baselibs
  80. "
  81. cr_opts="
  82. --profile= --tmpfs --ks-file
  83. "
  84. rb_opts="
  85. --base-obsprj= --target-obsprj= --spec= --commit= --include-all
  86. --status --buildlog --profile= --arch= --repository=
  87. "
  88. sr_opts="
  89. --msg= --target= --commit= --spec= --sign --user-key= --remote= --tag=
  90. "
  91. im_opts="
  92. --merge --upstream-branch= --upstream-tag= --author-email= --author-name= --no-pristine-tar
  93. --packaging-dir= --upstream-vcs-tag= --allow-same-version --native
  94. --filter= --no-patch-import
  95. "
  96. ex_opts="
  97. --source-rpm --include-all --commit= --spec= --outdir=
  98. "
  99. ch_opts="--message= --since= --packaging-dir="
  100. chr_opts="--root"
  101. lbex_opts="--no-configure --exclude-from-file= --exclude= --binary-list= --binary-from-file=\
  102. --threads= --package-list= --package-from-file= --incremental --overwrite \
  103. --clean-once --debug --deps --rdeps $lb_opts"
  104. cl_opts="--upstream-branch= --all --depth="
  105. pull_opts="--upstream-branch= --force --depth="
  106. subcommand="$(__gbs_find_on_cmdline "$subcommands")"
  107. if [ -z "$subcommand" ]; then
  108. case $cur in
  109. --*)
  110. __gbscomp "--version --help --verbose --debug"
  111. ;;
  112. *)
  113. __gbscomp "$subcommands"
  114. ;;
  115. esac
  116. else
  117. case "${subcommand},$cur" in
  118. build,--*)
  119. __gbscomp "$lb_opts $lbex_opts $common_opts"
  120. ;;
  121. createimage,--*)
  122. __gbscomp "$cr_opts"
  123. ;;
  124. remotebuild,--*)
  125. __gbscomp "$rb_opts $common_opts"
  126. ;;
  127. import,--*)
  128. __gbscomp "$im_opts"
  129. ;;
  130. export,--*)
  131. __gbscomp "$ex_opts $common_opts"
  132. ;;
  133. submit,--*)
  134. __gbscomp "$sr_opts"
  135. ;;
  136. changelog,--*)
  137. __gbscomp "$ch_opts"
  138. ;;
  139. chroot,--*)
  140. __gbscomp "$chr_opts"
  141. ;;
  142. clone,--*)
  143. __gbscomp "$cl_opts"
  144. ;;
  145. pull,--*)
  146. __gbscomp "$pull_opts"
  147. ;;
  148. *)
  149. COMPREPLY=()
  150. ;;
  151. esac
  152. fi
  153. }
  154. complete -F __gbs_main -o bashdefault -o default -o nospace gbs