1695b41eeSopenharmony_ci#compdef ninja
2695b41eeSopenharmony_ci# Copyright 2011 Google Inc. All Rights Reserved.
3695b41eeSopenharmony_ci#
4695b41eeSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
5695b41eeSopenharmony_ci# you may not use this file except in compliance with the License.
6695b41eeSopenharmony_ci# You may obtain a copy of the License at
7695b41eeSopenharmony_ci#
8695b41eeSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
9695b41eeSopenharmony_ci#
10695b41eeSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
11695b41eeSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
12695b41eeSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13695b41eeSopenharmony_ci# See the License for the specific language governing permissions and
14695b41eeSopenharmony_ci# limitations under the License.
15695b41eeSopenharmony_ci
16695b41eeSopenharmony_ci# Add the following to your .zshrc to tab-complete ninja targets
17695b41eeSopenharmony_ci#   fpath=(path/to/ninja/misc/zsh-completion $fpath)
18695b41eeSopenharmony_ci
19695b41eeSopenharmony_ci(( $+functions[_ninja-get-targets] )) || _ninja-get-targets() {
20695b41eeSopenharmony_ci  dir="."
21695b41eeSopenharmony_ci  if [ -n "${opt_args[-C]}" ];
22695b41eeSopenharmony_ci  then
23695b41eeSopenharmony_ci    eval dir="${opt_args[-C]}"
24695b41eeSopenharmony_ci  fi
25695b41eeSopenharmony_ci  file="build.ninja"
26695b41eeSopenharmony_ci  if [ -n "${opt_args[-f]}" ];
27695b41eeSopenharmony_ci  then
28695b41eeSopenharmony_ci    eval file="${opt_args[-f]}"
29695b41eeSopenharmony_ci  fi
30695b41eeSopenharmony_ci  targets_command="ninja -f \"${file}\" -C \"${dir}\" -t targets all"
31695b41eeSopenharmony_ci  eval ${targets_command} 2>/dev/null | cut -d: -f1
32695b41eeSopenharmony_ci}
33695b41eeSopenharmony_ci
34695b41eeSopenharmony_ci(( $+functions[_ninja-get-tools] )) || _ninja-get-tools() {
35695b41eeSopenharmony_ci  # remove the first line; remove the leading spaces; replace spaces with colon
36695b41eeSopenharmony_ci  ninja -t list 2> /dev/null | sed -e '1d;s/^ *//;s/ \+/:/'
37695b41eeSopenharmony_ci}
38695b41eeSopenharmony_ci
39695b41eeSopenharmony_ci(( $+functions[_ninja-get-modes] )) || _ninja-get-modes() {
40695b41eeSopenharmony_ci  # remove the first line; remove the last line; remove the leading spaces; replace spaces with colon
41695b41eeSopenharmony_ci  ninja -d list 2> /dev/null | sed -e '1d;$d;s/^ *//;s/ \+/:/'
42695b41eeSopenharmony_ci}
43695b41eeSopenharmony_ci
44695b41eeSopenharmony_ci(( $+functions[_ninja-modes] )) || _ninja-modes() {
45695b41eeSopenharmony_ci  local -a modes
46695b41eeSopenharmony_ci  modes=(${(fo)"$(_ninja-get-modes)"})
47695b41eeSopenharmony_ci  _describe 'modes' modes
48695b41eeSopenharmony_ci}
49695b41eeSopenharmony_ci
50695b41eeSopenharmony_ci(( $+functions[_ninja-tools] )) || _ninja-tools() {
51695b41eeSopenharmony_ci  local -a tools
52695b41eeSopenharmony_ci  tools=(${(fo)"$(_ninja-get-tools)"})
53695b41eeSopenharmony_ci  _describe 'tools' tools
54695b41eeSopenharmony_ci}
55695b41eeSopenharmony_ci
56695b41eeSopenharmony_ci(( $+functions[_ninja-targets] )) || _ninja-targets() {
57695b41eeSopenharmony_ci  local -a targets
58695b41eeSopenharmony_ci  targets=(${(fo)"$(_ninja-get-targets)"})
59695b41eeSopenharmony_ci  _describe 'targets' targets
60695b41eeSopenharmony_ci}
61695b41eeSopenharmony_ci
62695b41eeSopenharmony_ci_arguments \
63695b41eeSopenharmony_ci  '(- *)'{-h,--help}'[Show help]' \
64695b41eeSopenharmony_ci  '(- *)--version[Print ninja version]' \
65695b41eeSopenharmony_ci  '-C+[Change to directory before doing anything else]:directories:_directories' \
66695b41eeSopenharmony_ci  '-f+[Specify input build file (default=build.ninja)]:files:_files' \
67695b41eeSopenharmony_ci  '-j+[Run N jobs in parallel (default=number of CPUs available)]:number of jobs' \
68695b41eeSopenharmony_ci  '-l+[Do not start new jobs if the load average is greater than N]:number of jobs' \
69695b41eeSopenharmony_ci  '-k+[Keep going until N jobs fail (default=1)]:number of jobs' \
70695b41eeSopenharmony_ci  '-n[Dry run (do not run commands but act like they succeeded)]' \
71695b41eeSopenharmony_ci  '(-v --verbose --quiet)'{-v,--verbose}'[Show all command lines while building]' \
72695b41eeSopenharmony_ci  "(-v --verbose --quiet)--quiet[Don't show progress status, just command output]" \
73695b41eeSopenharmony_ci  '-d+[Enable debugging (use -d list to list modes)]:modes:_ninja-modes' \
74695b41eeSopenharmony_ci  '-t+[Run a subtool (use -t list to list subtools)]:tools:_ninja-tools' \
75695b41eeSopenharmony_ci  '*::targets:_ninja-targets'
76