ninja/misc/zsh-completion
Fraser Cormack d130968ecd zsh-completion: remove use of 'head' with negative offset
Some systems - like OSX - don't come with a version of head that
supports a negative value for the -n flag. Such systems get a message
such as this when tab-completing ninja's -d flag:

    ninja -dhead: illegal line count -- -1

Using sed instead should be more universally supported.
2014-12-20 00:12:52 +00:00

70 lines
2.2 KiB
Plaintext

#compdef ninja
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Add the following to your .zshrc to tab-complete ninja targets
# . path/to/ninja/misc/zsh-completion
__get_targets() {
dir="."
if [ -n "${opt_args[-C]}" ];
then
eval dir="${opt_args[-C]}"
fi
targets_command="ninja -C \"${dir}\" -t targets"
eval ${targets_command} 2>/dev/null | while read -r a b; do echo $a | cut -d ':' -f1; done;
}
__get_tools() {
ninja -t list 2>/dev/null | while read -r a b; do echo $a; done | tail -n +2
}
__get_modes() {
ninja -d list 2>/dev/null | while read -r a b; do echo $a; done | tail -n +2 | sed '$d'
}
__modes() {
local -a modes
modes=(${(fo)"$(__get_modes)"})
_describe 'modes' modes
}
__tools() {
local -a tools
tools=(${(fo)"$(__get_tools)"})
_describe 'tools' tools
}
__targets() {
local -a targets
targets=(${(fo)"$(__get_targets)"})
_describe 'targets' targets
}
_arguments \
{-h,--help}'[Show help]' \
'--version[Print ninja version]' \
'-C+[Change to directory before doing anything else]:directories:_directories' \
'-f+[Specify input build file (default=build.ninja)]:files:_files' \
'-j+[Run N jobs in parallel (default=number of CPUs available)]:number of jobs' \
'-l+[Do not start new jobs if the load average is greater than N]:number of jobs' \
'-k+[Keep going until N jobs fail (default=1)]:number of jobs' \
'-n[Dry run (do not run commands but act like they succeeded)]' \
'-v[Show all command lines while building]' \
'-d+[Enable debugging (use -d list to list modes)]:modes:__modes' \
'-t+[Run a subtool (use -t list to list subtools)]:tools:__tools' \
'*::targets:__targets'