/bash_completion.d/bzr

http://github.com/brinkman83/bashrc · #! · 104 lines · 88 code · 16 blank · 0 comment · 0 complexity · 142eb79e59b2317fc7acc423bcc84291 MD5 · raw file

  1. # Programmable completion for the Bazaar-NG bzr command under bash. Source
  2. # this file (or on some systems add it to ~/.bash_completion and start a new
  3. # shell) and bash's completion mechanism will know all about bzr's options!
  4. # Known to work with bash 2.05a with programmable completion and extended
  5. # pattern matching enabled (use 'shopt -s extglob progcomp' to enable
  6. # these if they are not already enabled).
  7. # Based originally on the svn bash completition script.
  8. # Customized by Sven Wilhelm/Icecrash.com
  9. _bzr ()
  10. {
  11. local cur cmds cmdOpts opt helpCmds optBase i
  12. COMPREPLY=()
  13. cur=${COMP_WORDS[COMP_CWORD]}
  14. cmds='status diff commit ci checkin move remove log info check ignored'
  15. if [[ $COMP_CWORD -eq 1 ]] ; then
  16. COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
  17. return 0
  18. fi
  19. # if not typing an option, or if the previous option required a
  20. # parameter, then fallback on ordinary filename expansion
  21. helpCmds='help|--help|h|\?'
  22. if [[ ${COMP_WORDS[1]} != @($helpCmds) ]] && \
  23. [[ "$cur" != -* ]] ; then
  24. return 0
  25. fi
  26. cmdOpts=
  27. case ${COMP_WORDS[1]} in
  28. status)
  29. cmdOpts="--all --show-ids"
  30. ;;
  31. diff)
  32. cmdOpts="-r --revision --diff-options"
  33. ;;
  34. commit|ci|checkin)
  35. cmdOpts="-r --message -F --file -v --verbose"
  36. ;;
  37. move)
  38. cmdOpts=""
  39. ;;
  40. remove)
  41. cmdOpts="-v --verbose"
  42. ;;
  43. log)
  44. cmdOpts="--forward --timezone -v --verbose --show-ids -r --revision"
  45. ;;
  46. info)
  47. cmdOpts=""
  48. ;;
  49. ignored)
  50. cmdOpts=""
  51. ;;
  52. check)
  53. cmdOpts=""
  54. ;;
  55. help|h|\?)
  56. cmdOpts="$cmds $qOpts"
  57. ;;
  58. *)
  59. ;;
  60. esac
  61. cmdOpts="$cmdOpts --help -h"
  62. # take out options already given
  63. for (( i=2; i<=$COMP_CWORD-1; ++i )) ; do
  64. opt=${COMP_WORDS[$i]}
  65. case $opt in
  66. --*) optBase=${opt/=*/} ;;
  67. -*) optBase=${opt:0:2} ;;
  68. esac
  69. cmdOpts=" $cmdOpts "
  70. cmdOpts=${cmdOpts/ ${optBase} / }
  71. # take out alternatives
  72. case $optBase in
  73. -v) cmdOpts=${cmdOpts/ --verbose / } ;;
  74. --verbose) cmdOpts=${cmdOpts/ -v / } ;;
  75. -h) cmdOpts=${cmdOpts/ --help / } ;;
  76. --help) cmdOpts=${cmdOpts/ -h / } ;;
  77. -r) cmdOpts=${cmdOpts/ --revision / } ;;
  78. --revision) cmdOpts=${cmdOpts/ -r / } ;;
  79. esac
  80. # skip next option if this one requires a parameter
  81. if [[ $opt == @($optsParam) ]] ; then
  82. ((++i))
  83. fi
  84. done
  85. COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )
  86. return 0
  87. }
  88. complete -F _bzr -o default bzr