cmake-completion 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. --help-command)
  52. local running=$(for x in `cmake --help-command-list`; do echo ${x} ; done )
  53. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  54. return 0
  55. ;;
  56. --help-module)
  57. local running=$(for x in `cmake --help-module-list`; do echo ${x} ; done )
  58. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  59. return 0
  60. ;;
  61. --help-policy)
  62. local running=$(for x in `cmake --help-policies | grep "^ CMP"`; do echo ${x} ; done )
  63. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  64. return 0
  65. ;;
  66. --help-property)
  67. local running=$(for x in `cmake --help-property-list`; do echo ${x} ; done )
  68. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  69. return 0
  70. ;;
  71. --help-variable)
  72. local running=$(for x in `cmake --help-variable-list`; do echo ${x} ; done )
  73. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  74. return 0
  75. ;;
  76. *)
  77. ;;
  78. esac
  79. #
  80. # Complete the arguments to some of
  81. # the most commonly used commands (Level 2).
  82. # ?? How to do that ..
  83. #
  84. # Complete the option (Level 0 - right after cmake)
  85. #
  86. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  87. } &&
  88. complete -F _cmake -o default cmake
  89. #
  90. # cpack command
  91. #
  92. #have cpack &&
  93. _cpack()
  94. {
  95. local cur prev opts words cword
  96. COMPREPLY=()
  97. cur="${COMP_WORDS[COMP_CWORD]}"
  98. prev="${COMP_WORDS[COMP_CWORD-1]}"
  99. # seems to be only available on bash-completion 1.2
  100. #_get_comp_words_by_ref cur prev
  101. # cpack command line option we want to complete
  102. opts=`cpack --help | grep "^ \-.*=\ .*" | cut -d" " -f 3 | cut -d= -f 1`
  103. opts="${opts} --help -V"
  104. #
  105. # Complete the arguments to some of
  106. # the most commonly used commands (Level 1).
  107. #
  108. case "${prev}" in
  109. -G)
  110. local running=$(for x in `cpack --help | grep "^ .*=\ .*" | grep -v "^ -" | cut -d" " -f 3`; do echo ${x} ; done )
  111. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  112. return 0
  113. ;;
  114. --config)
  115. COMPREPLY=( $(compgen -f ${cur}) )
  116. return 0
  117. ;;
  118. *)
  119. ;;
  120. esac
  121. #
  122. # Complete the option (Level 0 - right after cmake)
  123. #
  124. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  125. } &&
  126. complete -F _cpack -o default cpack
  127. #
  128. # cmake command
  129. #
  130. # have ctest &&
  131. _ctest()
  132. {
  133. local cur prev opts words cword
  134. COMPREPLY=()
  135. cur="${COMP_WORDS[COMP_CWORD]}"
  136. prev="${COMP_WORDS[COMP_CWORD-1]}"
  137. # seems to be only available on bash-completion 1.2
  138. #_get_comp_words_by_ref cur prev
  139. # cmake command line option we want to complete
  140. opts=`ctest --help | grep "\-\-.*" | cut -d" " -f 3 | sed s/,/\\\n/g`
  141. #
  142. # Complete the arguments to some of
  143. # the most commonly used commands (Level 1).
  144. #
  145. case "${prev}" in
  146. --help-command)
  147. local running=$(for x in `ctest --help-command-list`; do echo ${x} ; done )
  148. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  149. return 0
  150. ;;
  151. -R)
  152. local running=$(for x in `ctest -N 2> /dev/null | grep "^ Test" | cut -d: -f 2`; do echo ${x} ; done )
  153. COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
  154. return 0
  155. ;;
  156. *)
  157. ;;
  158. esac
  159. #
  160. # Complete the arguments to some of
  161. # the most commonly used commands (Level 2).
  162. # ?? How to do that ..
  163. #
  164. # Complete the option (Level 0 - right after cmake)
  165. #
  166. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  167. } &&
  168. complete -F _ctest -o default ctest
  169. # Local variables:
  170. # mode: shell-script
  171. # sh-basic-offset: 4
  172. # sh-indent-comment: t
  173. # indent-tabs-mode: nil
  174. # End:
  175. # ex: ts=4 sw=4 et filetype=sh