cmake 6.7 KB

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