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