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