some comments

This commit is contained in:
Paul Seyfert 2016-09-26 07:51:17 +02:00
parent cd11b579cf
commit 2af78f9407
1 changed files with 25 additions and 18 deletions

View File

@ -98,7 +98,7 @@ _cmake_targets() {
local -a targets local -a targets
if [ -f $1/Makefile ] if [ -f $1/Makefile ]
then then
# make help doesn't work for Makefiles in general, but for cmake generated makefiles # `make help` doesn't work for Makefiles in general, but for cmake generated makefiles it does.
i=1 i=1
for target in $(make help | \grep -e "\.\.\." | sed "s/\.\.\. //" | sed "s/ (the default.*//") ; do for target in $(make help | \grep -e "\.\.\." | sed "s/\.\.\. //" | sed "s/ (the default.*//") ; do
targets[$i]=$target targets[$i]=$target
@ -106,6 +106,7 @@ _cmake_targets() {
done done
elif [ -f $1/build.ninja ] elif [ -f $1/build.ninja ]
then then
# `ninja help` doesn't seem to be the list of targets we're interested in
i=1 i=1
for target in $(ninja -C $1 -t targets all 2&>/dev/null | awk -F: '{print $1}') ; do for target in $(ninja -C $1 -t targets all 2&>/dev/null | awk -F: '{print $1}') ; do
targets[$i]="$target" targets[$i]="$target"
@ -158,14 +159,19 @@ _cmake_on_build() {
- build_cmds \ - build_cmds \
"$cmake_suggest_build[@]" && return 0 "$cmake_suggest_build[@]" && return 0
elif [ $difference -eq 1 ] ; then elif [ $difference -eq 1 ] ; then
# directly after --build comes the build directory
_alternative ':current directory:(.)' 'directory::_directories' && return 0 _alternative ':current directory:(.)' 'directory::_directories' && return 0
elif [[ $words[(($CURRENT - 1))] == --target ]] ; then elif [[ $words[(($CURRENT - 1))] == --target ]] ; then
# after --build <dir> --target, suggest targets
_cmake_targets $words[(($buildat + 1))] && return 0 _cmake_targets $words[(($buildat + 1))] && return 0
elif [[ $words[(($CURRENT - 1))] == --config ]] ; then elif [[ $words[(($CURRENT - 1))] == --config ]] ; then
# after --build <dir> --config, no idea
return 0 return 0
elif [ "$outofbuild" = true ] ; then elif [ "$outofbuild" = true ] ; then
# 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
# after --build <dir>, suggest other cmake_build_options (like -Wno-dev) or --build options (like --clean-first)
_arguments "$build_extras[@]" "$cmake_build_options[@]" && return 0 _arguments "$build_extras[@]" "$cmake_build_options[@]" && return 0
fi fi
} }
@ -401,24 +407,25 @@ local cmake_suggest_build;cmake_suggest_build=(
'--build[build]' '--build[build]'
) )
#_alternative 'foobar::_cmake_on_build' _cmake() {
if [ $CURRENT -eq 2 ] ; then if [ $CURRENT -eq 2 ] ; then
_arguments -C -s \ _arguments -C -s \
- help \ - help \
"$cmake_help_actions[@]" \ "$cmake_help_actions[@]" \
- command \ - command \
"$cmake_command_actions[@]" \ "$cmake_command_actions[@]" \
- build_opts \ - build_opts \
"$cmake_build_options[@]" \ "$cmake_build_options[@]" \
- build_cmds \ - build_cmds \
"$cmake_suggest_build[@]" && return 0 "$cmake_suggest_build[@]" && return 0
# - build_cmds \ elif [[ $words[2] = --help* ]] ; then
# "$cmake_build_commands[@]" # some help messages continue after the --help*
#_alternative -C -s 'helps::_cmake_help' '::_cmake_on_build' 'command mode::_cmake_command' && return 0 _cmake_help
elif [[ $words[2] = --help* ]] ; then elif [[ $words[2] != -E ]] ; then
_cmake_help _cmake_on_build
elif [[ $words[2] != -E ]] ; then else
_cmake_on_build _cmake_command
else fi
_cmake_command }
fi
_cmake "$@"