cmake 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. # bash completion for cmake(1) -*- shell-script -*-
  2. _cmake()
  3. {
  4. local is_old_completion=false
  5. local is_init_completion=false
  6. local cur prev words cword split was_split
  7. if type -t _comp_initialize >/dev/null; then
  8. _comp_initialize -s || return
  9. elif type -t _init_completion >/dev/null; then
  10. _init_completion -s || return
  11. is_init_completion=true
  12. else
  13. # manual initialization for older bash completion versions
  14. COMPREPLY=()
  15. cur="${COMP_WORDS[COMP_CWORD]}"
  16. prev="${COMP_WORDS[COMP_CWORD-1]}"
  17. is_old_completion=true
  18. split=false
  19. fi
  20. # Workaround for options like -DCMAKE_BUILD_TYPE=Release
  21. local prefix=
  22. if [[ $cur == -D* ]]; then
  23. prev=-D
  24. prefix=-D
  25. cur="${cur#-D}"
  26. elif [[ $cur == -U* ]]; then
  27. prev=-U
  28. prefix=-U
  29. cur="${cur#-U}"
  30. fi
  31. case "$prev" in
  32. -D)
  33. if [[ $cur == *=* ]]; then
  34. # complete values for variables
  35. local var type value
  36. var="${cur%%[:=]*}"
  37. value="${cur#*=}"
  38. if [[ $cur == CMAKE_BUILD_TYPE* ]]; then # most widely used case
  39. COMPREPLY=( $( compgen -W 'Debug Release RelWithDebInfo
  40. MinSizeRel' -- "$value" ) )
  41. return
  42. fi
  43. if [[ $cur == *:* ]]; then
  44. type="${cur#*:}"
  45. type="${type%%=*}"
  46. else # get type from cache if it's not set explicitly
  47. type=$( cmake -LA -N 2>/dev/null | grep "$var:" \
  48. 2>/dev/null )
  49. type="${type#*:}"
  50. type="${type%%=*}"
  51. fi
  52. case "$type" in
  53. FILEPATH)
  54. cur="$value"
  55. _filedir
  56. return
  57. ;;
  58. PATH)
  59. cur="$value"
  60. _filedir -d
  61. return
  62. ;;
  63. BOOL)
  64. COMPREPLY=( $( compgen -W 'ON OFF TRUE FALSE' -- \
  65. "$value" ) )
  66. return
  67. ;;
  68. STRING|INTERNAL)
  69. # no completion available
  70. return
  71. ;;
  72. esac
  73. elif [[ $cur == *:* ]]; then
  74. # complete types
  75. local type="${cur#*:}"
  76. COMPREPLY=( $( compgen -W 'FILEPATH PATH STRING BOOL INTERNAL'\
  77. -S = -- "$type" ) )
  78. compopt -o nospace
  79. else
  80. # complete variable names
  81. COMPREPLY=( $( compgen -W '$( cmake -LA -N 2>/dev/null |
  82. tail -n +2 | cut -f1 -d: )' -P "$prefix" -- "$cur" ) )
  83. compopt -o nospace
  84. fi
  85. return
  86. ;;
  87. -U)
  88. COMPREPLY=( $( compgen -W '$( cmake -LA -N | tail -n +2 |
  89. cut -f1 -d: )' -P "$prefix" -- "$cur" ) )
  90. return
  91. ;;
  92. esac
  93. if $is_old_completion; then
  94. _split_longopt && split=true
  95. fi
  96. case "$prev" in
  97. -C|-P|--graphviz|--system-information)
  98. _filedir
  99. return
  100. ;;
  101. --build)
  102. # Seed the reply with non-directory arguments that we know are
  103. # allowed to follow --build. _filedir will then prepend any valid
  104. # directory matches to these.
  105. COMPREPLY=( $( compgen -W "--preset --list-presets" -- "$cur" ) )
  106. _filedir -d
  107. return
  108. ;;
  109. --install|--open)
  110. _filedir -d
  111. return
  112. ;;
  113. -E)
  114. COMPREPLY=( $( compgen -W "$( cmake -E help |& sed -n \
  115. '/^ [^ ]/{s|^ \([^ ]\{1,\}\) .*$|\1|;p}' 2>/dev/null )" \
  116. -- "$cur" ) )
  117. return
  118. ;;
  119. -G)
  120. local IFS=$'\n'
  121. local quoted
  122. printf -v quoted %q "$cur"
  123. COMPREPLY=( $( compgen -W '$( cmake --help 2>/dev/null | sed -n \
  124. -e "1,/^Generators/d" \
  125. -e "/^ *[^ =]/{s|^ *\([^=]*[^ =]\).*$|\1|;s| |\\\\ |g;p}" \
  126. 2>/dev/null )' -- "$quoted" ) )
  127. return
  128. ;;
  129. --loglevel)
  130. COMPREPLY=( $(compgen -W 'error warning notice status verbose debug trace' -- $cur ) )
  131. ;;
  132. --help-command)
  133. COMPREPLY=( $( compgen -W '$( cmake --help-command-list 2>/dev/null|
  134. grep -v "^cmake version " )' -- "$cur" ) )
  135. return
  136. ;;
  137. --help-manual)
  138. COMPREPLY=( $( compgen -W '$( cmake --help-manual-list 2>/dev/null|
  139. grep -v "^cmake version " | sed -e "s/([0-9])$//" )' -- "$cur" ) )
  140. return
  141. ;;
  142. --help-module)
  143. COMPREPLY=( $( compgen -W '$( cmake --help-module-list 2>/dev/null|
  144. grep -v "^cmake version " )' -- "$cur" ) )
  145. return
  146. ;;
  147. --help-policy)
  148. COMPREPLY=( $( compgen -W '$( cmake --help-policy-list 2>/dev/null |
  149. grep -v "^cmake version " )' -- "$cur" ) )
  150. return
  151. ;;
  152. --help-property)
  153. COMPREPLY=( $( compgen -W '$( cmake --help-property-list \
  154. 2>/dev/null | grep -v "^cmake version " )' -- "$cur" ) )
  155. return
  156. ;;
  157. --help-variable)
  158. COMPREPLY=( $( compgen -W '$( cmake --help-variable-list \
  159. 2>/dev/null | grep -v "^cmake version " )' -- "$cur" ) )
  160. return
  161. ;;
  162. --list-presets)
  163. local IFS=$'\n'
  164. local quoted
  165. printf -v quoted %q "$cur"
  166. if [[ ! "${IFS}${COMP_WORDS[*]}${IFS}" =~ "${IFS}--build${IFS}" ]]; then
  167. COMPREPLY=(
  168. $( compgen -W "configure${IFS}build${IFS}package${IFS}test${IFS}workflow${IFS}all" -- "$quoted" )
  169. )
  170. fi
  171. return
  172. ;;
  173. --preset)
  174. local IFS=$'\n'
  175. local quoted
  176. printf -v quoted %q "$cur"
  177. local preset_type
  178. if [[ "${IFS}${COMP_WORDS[*]}${IFS}" =~ "${IFS}--workflow${IFS}" ]]; then
  179. preset_type="workflow"
  180. elif [[ "${IFS}${COMP_WORDS[*]}${IFS}" =~ "${IFS}--build${IFS}" ]]; then
  181. preset_type="build"
  182. else
  183. preset_type="configure"
  184. fi
  185. local presets=$( cmake --list-presets="$preset_type" 2>/dev/null |
  186. grep -o "^ \".*\"" | sed \
  187. -e "s/^ //g" \
  188. -e "s/\"//g" \
  189. -e 's/ /\\\\ /g' )
  190. COMPREPLY=( $( compgen -W "$presets" -- "$quoted" ) )
  191. return
  192. ;;
  193. --workflow)
  194. local quoted
  195. printf -v quoted %q "$cur"
  196. # Options allowed right after `--workflow`
  197. local workflow_options='--preset --list-presets --fresh'
  198. if [[ "$cur" == -* ]]; then
  199. COMPREPLY=( $( compgen -W "$workflow_options" -- "$quoted" ) )
  200. else
  201. local presets=$( cmake --list-presets=workflow 2>/dev/null |
  202. grep -o "^ \".*\"" | sed \
  203. -e "s/^ //g" \
  204. -e "s/\"//g" \
  205. -e 's/ /\\\\ /g' )
  206. COMPREPLY=( $( compgen -W "$presets $workflow_options" -- "$quoted" ) )
  207. fi
  208. return
  209. ;;
  210. esac
  211. if ($is_old_completion || $is_init_completion); then
  212. $split && return
  213. else
  214. [[ $was_split ]] && return
  215. fi
  216. if [[ "$cur" == -* ]]; then
  217. # FIXME(#26100): `cmake --help` is missing some options and does not
  218. # have any mode-specific options like `cmake --build`'s `--config`.
  219. COMPREPLY=( $(compgen -W '$( _parse_help "$1" --help )' -- ${cur}) )
  220. [[ $COMPREPLY == *= ]] && compopt -o nospace
  221. [[ $COMPREPLY ]] && return
  222. fi
  223. _filedir
  224. } &&
  225. complete -F _cmake cmake
  226. # ex: ts=4 sw=4 et filetype=sh