cmake-completion 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #
  2. # bash-completion file for CMake
  3. # Provided by Eric NOULARD - [email protected]
  4. #
  5. # see http://bash-completion.alioth.debian.org/
  6. # and http://www.cmake.org
  7. #
  8. # We will try to complete cmake commands options
  9. # at 2 (or may be 3 levels)
  10. # [cmake|cpack|ctest] <level0> <level1> <level2>
  11. #
  12. # level0 is top level cmake/cpack/ctest options
  13. # level1 is the first argument of level0 option
  14. # level2 is the seconf argument of level1 argument
  15. # FIXME: I don't know how to handle level2
  16. #
  17. # The file has been proposed for inclusion in the bash-completion package
  18. # https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=312632&group_id=100114
  19. # In the meantime,
  20. # 1) If you want to test bash completion for cmake/cpack/ctest
  21. # just source the current file at bash prompt
  22. # . ./cmake-completion
  23. #
  24. # 2) If you want to install it for good copy this file to
  25. # cp cmake-completion /etc/bash_completion.d/cmake
  26. #
  27. #
  28. # cmake command
  29. #
  30. # have cmake &&
  31. _cmake()
  32. {
  33. local cur prev opts words cword
  34. COMPREPLY=()
  35. cur="${COMP_WORDS[COMP_CWORD]}"
  36. prev="${COMP_WORDS[COMP_CWORD-1]}"
  37. # seems to be only available on bash-completion 1.2
  38. #_get_comp_words_by_ref cur prev
  39. # cmake command line option we want to complete
  40. opts=`cmake --help | grep "^ \-.*=\ .*" | cut -d" " -f 3 | cut -d= -f 1 | cut -d[ -f 1`
  41. #
  42. # Complete the arguments to some of
  43. # the most commonly used commands (Level 1).
  44. #
  45. case "${prev}" in
  46. -E)
  47. local running=$(for x in `cmake -E |& grep "^ " | cut -d" " -f 3`; do echo ${x} ; done )
  48. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  49. return 0
  50. ;;
  51. # FIXME: don't know how to handle multi words completion
  52. # or more precisely word that contains space in them like "Unix Makefiles"
  53. # -G)
  54. # local running=$(for x in `cmake --help | grep "^ .*=\ .*" | grep -v "^ -" | cut -d"=" -f 1 | grep -v "^ "`; do echo \"${x}\" ; done )
  55. # COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  56. # return 0
  57. # ;;
  58. --help-command)
  59. local running=$(for x in `cmake --help-command-list | grep -v "cmake version"`; do echo ${x} ; done )
  60. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  61. return 0
  62. ;;
  63. --help-module)
  64. local running=$(for x in `cmake --help-module-list | grep -v "cmake version"`; do echo ${x} ; done )
  65. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  66. return 0
  67. ;;
  68. --help-policy)
  69. local running=$(for x in `cmake --help-policies | grep "^ CMP"`; do echo ${x} ; done )
  70. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  71. return 0
  72. ;;
  73. --help-property)
  74. local running=$(for x in `cmake --help-property-list | grep -v "cmake version"`; do echo ${x} ; done )
  75. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  76. return 0
  77. ;;
  78. --help-variable)
  79. local running=$(for x in `cmake --help-variable-list | grep -v "cmake version"`; do echo ${x} ; done )
  80. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  81. return 0
  82. ;;
  83. *)
  84. ;;
  85. esac
  86. #
  87. # Complete the arguments to some of
  88. # the most commonly used commands (Level 2).
  89. # ?? How to do that ..
  90. #
  91. # Complete the option (Level 0 - right after cmake)
  92. #
  93. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  94. } &&
  95. complete -F _cmake -o default cmake
  96. #
  97. # cpack command
  98. #
  99. #have cpack &&
  100. _cpack()
  101. {
  102. local cur prev opts words cword
  103. COMPREPLY=()
  104. cur="${COMP_WORDS[COMP_CWORD]}"
  105. prev="${COMP_WORDS[COMP_CWORD-1]}"
  106. # seems to be only available on bash-completion 1.2
  107. #_get_comp_words_by_ref cur prev
  108. # cpack command line option we want to complete
  109. opts=`cpack --help | grep "^ \-.*=\ .*" | cut -d" " -f 3 | cut -d= -f 1`
  110. opts="${opts} --help -V"
  111. #
  112. # Complete the arguments to some of
  113. # the most commonly used commands (Level 1).
  114. #
  115. case "${prev}" in
  116. -G)
  117. local running=$(for x in `cpack --help | grep "^ .*=\ .*" | grep -v "^ -" | cut -d" " -f 3`; do echo ${x} ; done )
  118. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  119. return 0
  120. ;;
  121. --config)
  122. COMPREPLY=( $(compgen -f ${cur}) )
  123. return 0
  124. ;;
  125. --help-variable)
  126. local running=$(for x in `cpack --help-variable-list | grep -v "cpack version" `; do echo ${x} ; done )
  127. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  128. return 0
  129. ;;
  130. --help-command)
  131. local running=$(for x in `cpack --help-command-list | grep -v "cpack version" `; do echo ${x} ; done )
  132. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  133. return 0
  134. ;;
  135. *)
  136. ;;
  137. esac
  138. #
  139. # Complete the option (Level 0 - right after cpack)
  140. #
  141. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  142. } &&
  143. complete -F _cpack -o default cpack
  144. #
  145. # ctest command
  146. #
  147. # have ctest &&
  148. _ctest()
  149. {
  150. local cur prev opts words cword
  151. COMPREPLY=()
  152. cur="${COMP_WORDS[COMP_CWORD]}"
  153. prev="${COMP_WORDS[COMP_CWORD-1]}"
  154. # seems to be only available on bash-completion 1.2
  155. #_get_comp_words_by_ref cur prev
  156. # cmake command line option we want to complete
  157. opts=`ctest --help | grep "\-\-.*" | cut -d" " -f 3 | sed s/,/\\\n/g`
  158. #
  159. # Complete the arguments to some of
  160. # the most commonly used commands (Level 1).
  161. #
  162. case "${prev}" in
  163. --help-command)
  164. local running=$(for x in `ctest --help-command-list | grep -v "ctest version" `; do echo ${x} ; done )
  165. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  166. return 0
  167. ;;
  168. -R|-E)
  169. local running=$(for x in `ctest -N 2> /dev/null | grep "^ Test" | cut -d: -f 2`; do echo ${x} ; done )
  170. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  171. return 0
  172. ;;
  173. *)
  174. ;;
  175. esac
  176. #
  177. # Complete the arguments to some of
  178. # the most commonly used commands (Level 2).
  179. # ?? How to do that ..
  180. #
  181. # Complete the option (Level 0 - right after cmake)
  182. #
  183. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  184. } &&
  185. complete -F _ctest -o default ctest
  186. # Local variables:
  187. # mode: shell-script
  188. # sh-basic-offset: 4
  189. # sh-indent-comment: t
  190. # indent-tabs-mode: nil
  191. # End:
  192. # ex: ts=4 sw=4 et filetype=sh