Salome HOME
products completion after --products or -p
[tools/sat.git] / complete_sat.sh
1 #!/bin/bash
2 #  Copyright (C) 2010-2012  CEA/DEN
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17
18 # Completion Function for salomeTools (sat)
19
20 export SAT_PATH=$(cd `dirname "${BASH_SOURCE}"` && pwd)
21
22 _show_applications()
23 {
24     local opts2=$(for x in `$SAT_PATH/sat config -nl`
25         do
26             echo ${x}
27         done)
28
29     # additional options for command working without applications
30     case "${command}" in
31         config)
32             opts2=$(echo --list --value --edit --info $opts2)
33             ;;
34         log)
35             opts2=$(echo --clean --full --last --terminal --no_browser $opts2)
36             ;;
37         jobs)
38             opts2=$(echo --name --only_jobs --list --completion --test_connection --input_boards --publish $opts2)
39             ;;
40         shell)
41             opts2=$(echo --command --sat $opts2)
42             ;;
43         job)
44             opts2=$(echo --jobs_config --name $opts2)
45             ;;
46         test)
47             opts2=$(echo --base --display --grid --launcher --session $opts2)
48             ;;
49         package)
50             opts2=$(echo --name --project --salometools $opts2)
51             ;;
52         find_duplicates)
53             opts2=$(echo --path --exclude-file --exclude-extension --exclude-path $opts2)
54             ;;
55         template)
56             opts2=$(echo --name --template --target --param --info $opts2)
57             ;;
58         base)
59             opts2=$(echo --set $opts2)
60             ;;
61     esac
62
63     COMPREPLY=( $(compgen -W "${opts2}" -- ${cur}) )
64 }
65
66 _show_products()
67 {
68     if [[ $appli != $prev ]]
69     then
70         opts=$(for x in `$SAT_PATH/sat config $appli --completion`
71             do echo ${x}; done)
72
73         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
74    fi
75 }
76
77 _salomeTools_complete()
78 {
79     if [[ "${SAT_PATH}x" == "x" ]]
80     then
81         return 0
82     fi
83
84     local cur opts args command
85     COMPREPLY=()
86     argc="${COMP_CWORD}"
87     cur="${COMP_WORDS[COMP_CWORD]}"
88     
89     # second argument => show available APPLICATION
90     if [[ ${argc} > 1 ]]
91     then
92         command="${COMP_WORDS[1]}"
93     fi
94
95     if [[ ${argc} > 1 ]]
96     then
97         if [[ ${command%%-*} == "" ]]
98         then
99             command="${COMP_WORDS[2]}"
100             argc="$((( argc - 1)))"
101         fi
102     fi
103
104     # first argument => show available commands
105     if [[ ${argc} == 1 ]]
106     then
107         opts="config log testcommand source patch prepare environ clean configure make makeinstall compile launcher run jobs job shell test package generate find_duplicates application template base profile script --help"
108         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
109         return 0
110     fi
111
112     if [[ ${argc} == 2 ]]
113     then
114         # get list of APPLICATIONS
115         _show_applications
116         return 0
117     fi
118     
119     # option depending on command
120     local prev="${COMP_WORDS[COMP_CWORD-1]}"
121     
122     if [[ ${prev} == "--value" || ${prev} == "-v" ]]
123     then
124         if [[ ${argc} == 4 ]]
125         then
126             # with application
127             opts=$(for x in `$SAT_PATH/sat config ${COMP_WORDS[COMP_CWORD-2]} -s ${COMP_WORDS[COMP_CWORD]}`
128                 do echo ${x} ; done)
129             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
130         else
131             # without application
132             opts=$(for x in `$SAT_PATH/sat config -s ${COMP_WORDS[COMP_CWORD]}`
133                 do echo ${x} ; done)
134             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
135         fi
136         
137         return 0
138     fi
139       
140     # show list of products
141     if [[ ${prev} == "--product" || ${prev} == "-p" || ${prev} == "--info" || ${prev} == "-i" ]]
142     then
143         appli="${COMP_WORDS[2]}"
144         if [[ ${command} != "source" ]]
145         then
146             opts=$(for x in `$SAT_PATH/sat config $appli --completion`
147                 do echo ${x}; done)
148
149                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
150             return 0
151         fi
152     fi
153
154     # show argument for each command
155     case "${command}" in
156         config)
157             opts="--value --list --copy --edit --no_label --info --show_patchs"
158             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
159             return 0        
160             ;;
161         log)
162             opts="--clean --last --terminal --last --no_browser"
163             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
164             return 0
165             ;;
166         clean)
167             opts="--products --sources --build --install --all --sources_without_dev --properties"
168             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
169             return 0
170             ;;
171         source)
172             opts="--products"
173             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
174             return 0
175             ;;
176         patch)
177             opts="--products"
178             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
179             return 0
180             ;;
181         prepare)
182             opts="--products --force --force_patch"
183             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
184             return 0
185             ;;
186         environ)
187             opts="--products --shell --prefix --target"
188             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
189             return 0
190             ;;
191         configure)
192             opts="--products --option"
193             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
194             return 0
195             ;;
196         make)
197             opts="--products --option"
198             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
199             return 0
200             ;;
201         makeinstall)
202             opts="--products"
203             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
204             return 0
205             ;;
206         compile)
207             opts="--products --with_fathers --with_children --clean_all --make_flags --show --stop_first_fail --check"
208             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
209             return 0
210             ;;
211         launcher)
212             opts="--name --catalog --gencat"
213             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
214             return 0
215             ;;
216         jobs)
217             opts="--name --only_jobs --list --completion --test_connection --input_boards --publish"
218             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
219             return 0
220             ;;
221         shell)
222             opts="--command"
223             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
224             return 0
225             ;;
226         job)
227             opts="--jobs_config --name"
228             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
229             return 0
230             ;;
231         test)
232             opts="--base --launcher --grid --session --display"
233             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
234             return 0
235             ;;
236         package)
237             opts="--name --binaries --sources --project --salometools --with_vcs --without_commercial --without_property"
238             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
239             return 0
240             ;;
241         generate)
242             opts="--products --yacsgen"
243             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
244             return 0
245             ;;
246         find_duplicates)
247             opts="--path --sources --exclude-file --exclude-extension --exclude-path"
248             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
249             return 0
250             ;;
251         application)
252             opts="--name --catalog --target --gencat --module"
253             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
254             return 0
255             ;;
256         template)
257             opts="--name --template --target --param --info"
258             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
259             return 0
260             ;;
261         base)
262             opts="--set"
263             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
264             return 0
265             ;;
266         profile)
267             opts="--prefix --name --force --no_update --version --slogan"
268             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
269             return 0
270             ;;
271         script)
272             opts="--products --nb_proc"
273             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
274             return 0
275             ;;
276         *) return 0 ;;
277     esac
278     
279 }
280
281 # activation of auto-completion for the sat command
282 complete -F _salomeTools_complete sat
283 complete -F _salomeTools_complete ./sat
284