github.com/maruel/nin@v0.0.0-20220112143044-f35891e3ce7e/misc/zsh-completion (about) 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 __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 __get_tools() { 35 ninja -t list 2>/dev/null | while read -r a b; do echo $a; done | tail -n +2 36 } 37 38 __get_modes() { 39 ninja -d list 2>/dev/null | while read -r a b; do echo $a; done | tail -n +2 | sed '$d' 40 } 41 42 __modes() { 43 local -a modes 44 modes=(${(fo)"$(__get_modes)"}) 45 _describe 'modes' modes 46 } 47 48 __tools() { 49 local -a tools 50 tools=(${(fo)"$(__get_tools)"}) 51 _describe 'tools' tools 52 } 53 54 __targets() { 55 local -a targets 56 targets=(${(fo)"$(__get_targets)"}) 57 _describe 'targets' targets 58 } 59 60 _arguments \ 61 {-h,--help}'[Show help]' \ 62 '--version[Print ninja version]' \ 63 '-C+[Change to directory before doing anything else]:directories:_directories' \ 64 '-f+[Specify input build file (default=build.ninja)]:files:_files' \ 65 '-j+[Run N jobs in parallel (default=number of CPUs available)]:number of jobs' \ 66 '-l+[Do not start new jobs if the load average is greater than N]:number of jobs' \ 67 '-k+[Keep going until N jobs fail (default=1)]:number of jobs' \ 68 '-n[Dry run (do not run commands but act like they succeeded)]' \ 69 '-v[Show all command lines while building]' \ 70 '-d+[Enable debugging (use -d list to list modes)]:modes:__modes' \ 71 '-t+[Run a subtool (use -t list to list subtools)]:tools:__tools' \ 72 '*::targets:__targets'