cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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|--install|--open)
  93. _filedir -d
  94. return
  95. ;;
  96. -E)
  97. COMPREPLY=( $( compgen -W "$( cmake -E help |& sed -n \
  98. '/^ [^ ]/{s|^ \([^ ]\{1,\}\) .*$|\1|;p}' 2>/dev/null )" \
  99. -- "$cur" ) )
  100. return
  101. ;;
  102. -G)
  103. local IFS=$'\n'
  104. local quoted
  105. printf -v quoted %q "$cur"
  106. COMPREPLY=( $( compgen -W '$( cmake --help 2>/dev/null | sed -n \
  107. -e "1,/^Generators/d" \
  108. -e "/^ *[^ =]/{s|^ *\([^=]*[^ =]\).*$|\1|;s| |\\\\ |g;p}" \
  109. 2>/dev/null )' -- "$quoted" ) )
  110. return
  111. ;;
  112. --loglevel)
  113. COMPREPLY=( $(compgen -W 'error warning notice status verbose debug trace' -- $cur ) )
  114. ;;
  115. --help-command)
  116. COMPREPLY=( $( compgen -W '$( cmake --help-command-list 2>/dev/null|
  117. grep -v "^cmake version " )' -- "$cur" ) )
  118. return
  119. ;;
  120. --help-manual)
  121. COMPREPLY=( $( compgen -W '$( cmake --help-manual-list 2>/dev/null|
  122. grep -v "^cmake version " | sed -e "s/([0-9])$//" )' -- "$cur" ) )
  123. return
  124. ;;
  125. --help-module)
  126. COMPREPLY=( $( compgen -W '$( cmake --help-module-list 2>/dev/null|
  127. grep -v "^cmake version " )' -- "$cur" ) )
  128. return
  129. ;;
  130. --help-policy)
  131. COMPREPLY=( $( compgen -W '$( cmake --help-policy-list 2>/dev/null |
  132. grep -v "^cmake version " )' -- "$cur" ) )
  133. return
  134. ;;
  135. --help-property)
  136. COMPREPLY=( $( compgen -W '$( cmake --help-property-list \
  137. 2>/dev/null | grep -v "^cmake version " )' -- "$cur" ) )
  138. return
  139. ;;
  140. --help-variable)
  141. COMPREPLY=( $( compgen -W '$( cmake --help-variable-list \
  142. 2>/dev/null | grep -v "^cmake version " )' -- "$cur" ) )
  143. return
  144. ;;
  145. esac
  146. $split && return
  147. if [[ "$cur" == -* ]]; then
  148. COMPREPLY=( $(compgen -W '$( _parse_help "$1" --help )' -- ${cur}) )
  149. [[ $COMPREPLY == *= ]] && compopt -o nospace
  150. [[ $COMPREPLY ]] && return
  151. fi
  152. _filedir
  153. } &&
  154. complete -F _cmake cmake
  155. # ex: ts=4 sw=4 et filetype=sh