cmake 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # bash completion for cmake(1) -*- shell-script -*-
  2. _cmake()
  3. {
  4. local cur prev words cword split=false
  5. _init_completion -n := || return
  6. # Workaround for options like -DCMAKE_BUILD_TYPE=Release
  7. local prefix=
  8. if [[ $cur == -D* ]]; then
  9. prev=-D
  10. prefix=-D
  11. cur="${cur#-D}"
  12. elif [[ $cur == -U* ]]; then
  13. prev=-U
  14. prefix=-U
  15. cur="${cur#-U}"
  16. fi
  17. case "$prev" in
  18. -D)
  19. if [[ $cur == *=* ]]; then
  20. # complete values for variables
  21. local var type value
  22. var="${cur%%[:=]*}"
  23. value="${cur#*=}"
  24. if [[ $cur == CMAKE_BUILD_TYPE* ]]; then # most widely used case
  25. COMPREPLY=( $( compgen -W 'Debug Release RelWithDebInfo
  26. MinSizeRel' -- "$value" ) )
  27. return
  28. fi
  29. if [[ $cur == *:* ]]; then
  30. type="${cur#*:}"
  31. type="${type%%=*}"
  32. else # get type from cache if it's not set explicitly
  33. type=$( cmake -LA -N 2>/dev/null | grep "$var:" \
  34. 2>/dev/null )
  35. type="${type#*:}"
  36. type="${type%%=*}"
  37. fi
  38. case "$type" in
  39. FILEPATH)
  40. cur="$value"
  41. _filedir
  42. return
  43. ;;
  44. PATH)
  45. cur="$value"
  46. _filedir -d
  47. return
  48. ;;
  49. BOOL)
  50. COMPREPLY=( $( compgen -W 'ON OFF TRUE FALSE' -- \
  51. "$value" ) )
  52. return
  53. ;;
  54. STRING|INTERNAL)
  55. # no completion available
  56. return
  57. ;;
  58. esac
  59. elif [[ $cur == *:* ]]; then
  60. # complete types
  61. local type="${cur#*:}"
  62. COMPREPLY=( $( compgen -W 'FILEPATH PATH STRING BOOL INTERNAL'\
  63. -S = -- "$type" ) )
  64. compopt -o nospace
  65. else
  66. # complete variable names
  67. COMPREPLY=( $( compgen -W '$( cmake -LA -N | tail -n +2 |
  68. cut -f1 -d: )' -P "$prefix" -- "$cur" ) )
  69. compopt -o nospace
  70. fi
  71. return
  72. ;;
  73. -U)
  74. COMPREPLY=( $( compgen -W '$( cmake -LA -N | tail -n +2 |
  75. cut -f1 -d: )' -P "$prefix" -- "$cur" ) )
  76. return
  77. ;;
  78. esac
  79. _split_longopt && split=true
  80. case "$prev" in
  81. -C|-P|--graphviz|--system-information)
  82. _filedir
  83. return
  84. ;;
  85. --build)
  86. _filedir -d
  87. return
  88. ;;
  89. -E)
  90. COMPREPLY=( $( compgen -W "$( cmake -E help |& sed -n \
  91. '/^ /{s|^ \([^ ]\{1,\}\) .*$|\1|;p}' 2>/dev/null )" \
  92. -- "$cur" ) )
  93. return
  94. ;;
  95. -G)
  96. # FIXME: doesn't work properly
  97. local IFS=$'\n'
  98. COMPREPLY=( $( compgen -W '$( cmake --help 2>/dev/null | sed -n \
  99. "/^.*[^ ].*= Generates/{s|^ *\(.*[^ ]\) *= Generates.*$|\1|;s| |\\\\ |g;p}" \
  100. 2>/dev/null )' -- "$cur" ) )
  101. return
  102. ;;
  103. --help-command)
  104. COMPREPLY=( $( compgen -W '$( cmake --help-command-list 2>/dev/null|
  105. tail -n +2 )' -- "$cur" ) )
  106. return
  107. ;;
  108. --help-module)
  109. COMPREPLY=( $( compgen -W '$( cmake --help-module-list 2>/dev/null|
  110. tail -n +2 )' -- "$cur" ) )
  111. return
  112. ;;
  113. --help-policy)
  114. COMPREPLY=( $( compgen -W '$( cmake --help-policies 2>/dev/null |
  115. grep "^ CMP" 2>/dev/null )' -- "$cur" ) )
  116. return
  117. ;;
  118. --help-property)
  119. COMPREPLY=( $( compgen -W '$( cmake --help-property-list \
  120. 2>/dev/null | tail -n +2 )' -- "$cur" ) )
  121. return
  122. ;;
  123. --help-variable)
  124. COMPREPLY=( $( compgen -W '$( cmake --help-variable-list \
  125. 2>/dev/null | tail -n +2 )' -- "$cur" ) )
  126. return
  127. ;;
  128. esac
  129. $split && return
  130. if [[ "$cur" == -* ]]; then
  131. COMPREPLY=( $(compgen -W '$( _parse_help "$1" --help )' -- ${cur}) )
  132. [[ $COMPREPLY == *= ]] && compopt -o nospace
  133. [[ $COMPREPLY ]] && return
  134. fi
  135. _filedir
  136. } &&
  137. complete -F _cmake cmake
  138. # ex: ts=4 sw=4 et filetype=sh