README: document nit_env.sh
[nit.git] / misc / bash_completion / nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Bash completion for nit commands
16 # Put (or link) this file into `/etc/bash_completion.d/`
17 # or source it in `~/.bash_completion`.
18
19 _nit_lazy() {
20         # Check if a valid command
21         which $1 > /dev/null || return 1
22
23         # Drop possible directories to get the command name
24         local cmd=`basename $1`
25
26         # Generate the bash-completion
27         # and setup a new `complete` for the command
28         eval "$($1 --bash-completion)"
29
30         if [[ $(type -t _$cmd) == function ]]; then
31                 # All if fine, finish the job by invoking the function _$cmd
32                 _$cmd
33                 return $?
34         else
35                 # Problem, no function _$cmd
36                 return 1
37         fi
38 } &&
39 complete -F _nit_lazy -o default nit nitc nitdoc nitlight nitls nitmetrics nitunit nitx