simplify assignments and remove needless functions
This commit is contained in:
parent
8e505348f3
commit
e534d39076
102
src/_cmake
102
src/_cmake
|
|
@ -153,7 +153,7 @@ _cmake_presets() {
|
|||
invoke[$CURRENT]=()
|
||||
# TODO: remove all arguments -* except -S
|
||||
|
||||
local list_presets; list_presets=(${(f)"$(${invoke} --list-presets 2>/dev/null |
|
||||
local list_presets=(${(f)"$(${invoke} --list-presets 2>/dev/null |
|
||||
sed -n -e 's,^[[:space:]]*"\([^"]*\)"[[:space:]]*-[[:space:]]*\(.*\),\1:\2,p' \
|
||||
-e 's,^[[:space:]]*"\([^"]*\)"[[:space:]]*$,\1,p')"})
|
||||
|
||||
|
|
@ -187,45 +187,53 @@ _cmake_suggest_installdirs() {
|
|||
}
|
||||
|
||||
_cmake_on_build() {
|
||||
local build_extras;build_extras=(
|
||||
local build_extras=(
|
||||
'--[Native build tool options]'
|
||||
'--target[specify build target]'
|
||||
'--clean-first[build target clean first]'
|
||||
'--config[For multi-configuration tools]'
|
||||
'--parallel[maximum number of build processes]'
|
||||
'--use-stderr')
|
||||
'--use-stderr'
|
||||
)
|
||||
local -a undescribed_build_extras
|
||||
local i=1
|
||||
for be in $build_extras ; do
|
||||
undescribed_build_extras[$i]=$(echo $be | sed "s/\[.*//")
|
||||
(( i++ ))
|
||||
done
|
||||
local inbuild=false
|
||||
local dashdashposition=-1
|
||||
local buildat=$CURRENT
|
||||
|
||||
local in_build=false
|
||||
local dash_dash_position=-1
|
||||
local build_at=$CURRENT
|
||||
for ((i = (($CURRENT - 1)); i > 1 ; i--)); do
|
||||
if [[ $words[$i] == --build ]] ; then
|
||||
inbuild=true
|
||||
buildat=$i
|
||||
if [[ $words[$i] == --build ]]; then
|
||||
in_build=true
|
||||
build_at=$i
|
||||
(( difference = $CURRENT - $i ))
|
||||
elif [[ $words[$i] == -- ]] ; then
|
||||
dashdashposition=$i
|
||||
elif [[ $words[$i] == -- ]]; then
|
||||
dash_dash_position=$i
|
||||
fi
|
||||
done
|
||||
|
||||
# check if build mode has been left
|
||||
local outofbuild=false
|
||||
for ((i = (($CURRENT - 1)); i > (($buildat + 1)); i--)); do
|
||||
local out_of_build=false
|
||||
for ((i = (($CURRENT - 1)); i > (($build_at + 1)); i--)); do
|
||||
# don't check the word after --build (should be a directory)
|
||||
if [[ ${undescribed_build_extras[(r)$words[$i]]} == $words[$i] ]] ; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --target ]] ; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --config ]] ; then continue ; fi
|
||||
if [[ ${undescribed_build_extras[(r)$words[$i]]} == $words[$i] ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ $words[(($i - 1))] == --target ]]; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --config ]]; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --parallel ]] ; then continue ; fi
|
||||
outofbuild=true
|
||||
out_of_build=true
|
||||
done
|
||||
if (( $dashdashposition > 0 )) ; then
|
||||
_cmake_generator_options $words[(($buildat + 1))] $dashdashposition && return 0
|
||||
|
||||
if (( $dash_dash_position > 0 )) ; then
|
||||
_cmake_generator_options $words[(($build_at + 1))] $dash_dash_position && return 0
|
||||
fi
|
||||
if [[ "$inbuild" == false || "$difference" -eq 1 ]] ; then
|
||||
|
||||
if [[ "$in_build" == false || "$difference" -eq 1 ]] ; then
|
||||
# either there is no --build or completing the directory after --build
|
||||
_arguments -C -s \
|
||||
- build_opts \
|
||||
|
|
@ -234,14 +242,14 @@ _cmake_on_build() {
|
|||
"$cmake_suggest_build[@]" && return 0
|
||||
elif [[ $words[(($CURRENT - 1))] == --target ]] ; then
|
||||
# after --build <dir> --target, suggest targets
|
||||
_cmake_targets $words[(($buildat + 1))] && return 0
|
||||
_cmake_targets $words[(($build_at + 1))] && return 0
|
||||
elif [[ $words[(($CURRENT - 1))] == --config ]] ; then
|
||||
# after --build <dir> --config, no idea
|
||||
return 0
|
||||
elif [[ $words[(($CURRENT - 1))] == --parallel ]] ; then
|
||||
# after --build <dir> --parallel
|
||||
return 0
|
||||
elif [ "$outofbuild" = true ] ; then
|
||||
elif [ "$out_of_build" = true ] ; then
|
||||
# after --build <dir> --<not a --build option>, suggest other cmake_build_options (like -Wno-dev)
|
||||
_arguments "$cmake_build_options[@]" && return 0
|
||||
else
|
||||
|
|
@ -251,44 +259,49 @@ _cmake_on_build() {
|
|||
}
|
||||
|
||||
_cmake_on_install() {
|
||||
local build_extras;build_extras=(
|
||||
local build_extras=(
|
||||
'--[Native build tool options]'
|
||||
'--prefix[Override the installation prefix, CMAKE_INSTALL_PREFIX]'
|
||||
'--config[For multi-configuration generators(e.g. Visual Studio)]'
|
||||
'--component[Component-based install]'
|
||||
'--strip[Strip before installing.]'
|
||||
)
|
||||
)
|
||||
|
||||
local -a undescribed_build_extras
|
||||
local i=1
|
||||
for be in $build_extras ; do
|
||||
undescribed_build_extras[$i]=$(echo $be | sed "s/\[.*//")
|
||||
(( i++ ))
|
||||
done
|
||||
local inbuild=false
|
||||
local dashdashposition=-1
|
||||
local buildat=$CURRENT
|
||||
|
||||
local in_build=false
|
||||
local dash_dash_position=-1
|
||||
local build_at=$CURRENT
|
||||
for ((i = (($CURRENT - 1)); i > 1 ; i--)); do
|
||||
if [[ $words[$i] == --install ]] ; then
|
||||
inbuild=true
|
||||
buildat=$i
|
||||
if [[ $words[$i] == --install ]]; then
|
||||
in_build=true
|
||||
build_at=$i
|
||||
(( difference = $CURRENT - $i ))
|
||||
elif [[ $words[$i] == -- ]] ; then
|
||||
dashdashposition=$i
|
||||
elif [[ $words[$i] == -- ]]; then
|
||||
dash_dash_position=$i
|
||||
fi
|
||||
done
|
||||
local outofbuild=false
|
||||
for ((i = (($CURRENT - 1)); i > (($buildat + 1)); i--)); do
|
||||
|
||||
local out_of_build=false
|
||||
for ((i = (($CURRENT - 1)); i > (($build_at + 1)); i--)); do
|
||||
# don't check the word after --install (should be a directory)
|
||||
if [[ ${undescribed_build_extras[(r)$words[$i]]} == $words[$i] ]] ; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --prefix ]] ; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --config ]] ; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --component ]] ; then continue ; fi
|
||||
outofbuild=true
|
||||
if [[ $words[(($i - 1))] == --prefix ]]; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --config ]]; then continue ; fi
|
||||
if [[ $words[(($i - 1))] == --component ]]; then continue ; fi
|
||||
out_of_build=true
|
||||
done
|
||||
if (( $dashdashposition > 0 )) ; then
|
||||
_cmake_generator_options $words[(($buildat + 1))] $dashdashposition && return 0
|
||||
|
||||
if (( $dash_dash_position > 0 )) ; then
|
||||
_cmake_generator_options $words[(($build_at + 1))] $dash_dash_position && return 0
|
||||
fi
|
||||
if [[ "$inbuild" == false || "$difference" -eq 1 ]] ; then
|
||||
|
||||
if [[ "$in_build" == false || "$difference" -eq 1 ]] ; then
|
||||
# either there is no --install or completing the directory after --install
|
||||
_arguments -C -s \
|
||||
- build_opts \
|
||||
|
|
@ -304,7 +317,7 @@ _cmake_on_install() {
|
|||
elif [[ $words[(($CURRENT - 1))] == --component ]] ; then
|
||||
# after --build <dir> --component, no idea
|
||||
return 0
|
||||
elif [ "$outofbuild" = true ] ; then
|
||||
elif [ "$out_of_build" = true ] ; then
|
||||
# after --build <dir> --<not a --build option>, suggest other cmake_build_options (like -Wno-dev)
|
||||
_arguments "$cmake_build_options[@]" && return 0
|
||||
else
|
||||
|
|
@ -335,9 +348,6 @@ local -a cmake_help_actions=(
|
|||
'(- 1)--help-variable-list[List variables with help available and exit]'
|
||||
'(- 1)--help-variables[Print cmake-variables manual and exit]'
|
||||
)
|
||||
_cmake_help() {
|
||||
_arguments -C -s - help "$cmake_help_actions[@]"
|
||||
}
|
||||
|
||||
# -----------------
|
||||
# _cmake_list_names
|
||||
|
|
@ -612,8 +622,6 @@ elif [ $CURRENT -eq 2 ] ; then
|
|||
"$cmake_suggest_build[@]" \
|
||||
- install_cmds \
|
||||
"$cmake_suggest_install[@]" && return 0
|
||||
elif [[ $words[2] = --help* ]] ; then
|
||||
_cmake_help
|
||||
elif [[ $words[2] == --build ]] ; then
|
||||
_cmake_on_build
|
||||
elif [[ $words[2] == --install ]] ; then
|
||||
|
|
|
|||
Loading…
Reference in New Issue