| 1 |
#compdef ninja |
| 2 |
# Copyright 2011 Google Inc. All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
# Add the following to your .zshrc to tab-complete ninja targets |
| 17 |
# fpath=(path/to/ninja/misc/zsh-completion $fpath) |
| 18 |
|
| 19 |
(( $+functions[_ninja-get-targets] )) || _ninja-get-targets() { |
| 20 |
dir="." |
| 21 |
if [ -n "${opt_args[-C]}" ]; |
| 22 |
then |
| 23 |
eval dir="${opt_args[-C]}" |
| 24 |
fi |
| 25 |
file="build.ninja" |
| 26 |
if [ -n "${opt_args[-f]}" ]; |
| 27 |
then |
| 28 |
eval file="${opt_args[-f]}" |
| 29 |
fi |
| 30 |
targets_command="ninja -f \"${file}\" -C \"${dir}\" -t targets all" |
| 31 |
eval ${targets_command} 2>/dev/null | cut -d: -f1 |
| 32 |
} |
| 33 |
|
| 34 |
(( $+functions[_ninja-get-tools] )) || _ninja-get-tools() { |
| 35 |
# remove the first line; remove the leading spaces; replace spaces with colon |
| 36 |
ninja -t list 2> /dev/null | sed -e '1d;s/^ *//;s/ \+/:/' |
| 37 |
} |
| 38 |
|
| 39 |
(( $+functions[_ninja-get-modes] )) || _ninja-get-modes() { |
| 40 |
# remove the first line; remove the last line; remove the leading spaces; replace spaces with colon |
| 41 |
ninja -d list 2> /dev/null | sed -e '1d;$d;s/^ *//;s/ \+/:/' |
| 42 |
} |
| 43 |
|
| 44 |
(( $+functions[_ninja-modes] )) || _ninja-modes() { |
| 45 |
local -a modes |
| 46 |
modes=(${(fo)"$(_ninja-get-modes)"}) |
| 47 |
_describe 'modes' modes |
| 48 |
} |
| 49 |
|
| 50 |
(( $+functions[_ninja-tools] )) || _ninja-tools() { |
| 51 |
local -a tools |
| 52 |
tools=(${(fo)"$(_ninja-get-tools)"}) |
| 53 |
_describe 'tools' tools |
| 54 |
} |
| 55 |
|
| 56 |
(( $+functions[_ninja-targets] )) || _ninja-targets() { |
| 57 |
local -a targets |
| 58 |
targets=(${(fo)"$(_ninja-get-targets)"}) |
| 59 |
_describe 'targets' targets |
| 60 |
} |
| 61 |
|
| 62 |
_arguments \ |
| 63 |
'(- *)'{-h,--help}'[Show help]' \ |
| 64 |
'(- *)--version[Print ninja version]' \ |
| 65 |
'-C+[Change to directory before doing anything else]:directories:_directories' \ |
| 66 |
'-f+[Specify input build file (default=build.ninja)]:files:_files' \ |
| 67 |
'-j+[Run N jobs in parallel (default=number of CPUs available)]:number of jobs' \ |
| 68 |
'-l+[Do not start new jobs if the load average is greater than N]:number of jobs' \ |
| 69 |
'-k+[Keep going until N jobs fail (default=1)]:number of jobs' \ |
| 70 |
'-n[Dry run (do not run commands but act like they succeeded)]' \ |
| 71 |
'(-v --verbose --quiet)'{-v,--verbose}'[Show all command lines while building]' \ |
| 72 |
"(-v --verbose --quiet)--quiet[Don't show progress status, just command output]" \ |
| 73 |
'-d+[Enable debugging (use -d list to list modes)]:modes:_ninja-modes' \ |
| 74 |
'-t+[Run a subtool (use -t list to list subtools)]:tools:_ninja-tools' \ |
| 75 |
'*::targets:_ninja-targets' |