Salome HOME
[FORUM 505] prepare command fix on windows
[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 --last_compile --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         init)
62             opts2=$(echo --base --workdir --VCS --tag --log_dir --add_project --reset_projects $opts2)
63             ;;
64     esac
65
66     COMPREPLY=( $(compgen -W "${opts2}" -- ${cur}) )
67 }
68
69 _show_products()
70 {
71     if [[ $appli != $prev ]]
72     then
73         opts=$(for x in `$SAT_PATH/sat config $appli --completion`
74             do echo ${x}; done)
75
76         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
77    fi
78 }
79
80 _salomeTools_complete()
81 {
82     if [[ "${SAT_PATH}x" == "x" ]]
83     then
84         return 0
85     fi
86
87     local cur opts args command
88     COMPREPLY=()
89     argc="${COMP_CWORD}"
90     cur="${COMP_WORDS[COMP_CWORD]}"
91     
92     # second argument => show available APPLICATION
93     if [[ ${argc} > 1 ]]
94     then
95         command="${COMP_WORDS[1]}"
96     fi
97
98     if [[ ${argc} > 1 ]]
99     then
100         if [[ ${command%%-*} == "" ]]
101         then
102             command="${COMP_WORDS[2]}"
103             argc="$((( argc - 1)))"
104         fi
105     fi
106
107     # first argument => show available commands
108     if [[ ${argc} == 1 ]]
109     then
110         opts="config log source patch prepare environ clean configure make makeinstall compile launcher run jobs job shell test package generate find_duplicates application template base check profile script init --help --overwrite --debug --verbose --batch --all_in_terminal --logs_paths_in_file"
111         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
112         return 0
113     fi
114
115     if [[ ${argc} == 2 ]]
116     then
117         # get list of APPLICATIONS
118         _show_applications
119         return 0
120     fi
121     
122     # option depending on command
123     local prev="${COMP_WORDS[COMP_CWORD-1]}"
124     
125     if [[ ${prev} == "--value" || ${prev} == "-v" ]]
126     then
127         if [[ ${argc} == 4 ]]
128         then
129             # with application
130             opts=$(for x in `$SAT_PATH/sat config ${COMP_WORDS[COMP_CWORD-2]} -s ${COMP_WORDS[COMP_CWORD]}`
131                 do echo ${x} ; done)
132             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
133         else
134             # without application
135             opts=$(for x in `$SAT_PATH/sat config -s ${COMP_WORDS[COMP_CWORD]}`
136                 do echo ${x} ; done)
137             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
138         fi
139         
140         return 0
141     fi
142       
143     # show list of products
144     if [[ ${prev} == "--products" || ${prev} == "-p" || ${prev} == "--info" || ${prev} == "-i" ]]
145     then
146         appli="${COMP_WORDS[2]}"
147         if [[ ${command} != "source" ]]
148         then
149             opts=$(for x in `$SAT_PATH/sat config $appli --completion`
150                 do echo ${x}; done)
151
152                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
153             return 0
154         fi
155     fi
156
157     # show argument for each command
158     case "${command}" in
159         config)
160             opts="--value --list --copy --edit --no_label --info --check_system --show_patchs --show_dependencies --show_install --show_properties"
161             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
162             return 0        
163             ;;
164         log)
165             opts="--clean --last --terminal --last --last_compile --no_browser"
166             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
167             return 0
168             ;;
169         clean)
170             opts="--products --sources --build --install --generated --package --all --sources_without_dev --properties"
171             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
172             return 0
173             ;;
174         source)
175             opts="--products --properties"
176             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
177             return 0
178             ;;
179         patch)
180             opts="--products --properties"
181             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
182             return 0
183             ;;
184         prepare)
185             opts="--products --properties --force --force_patch --complete"
186             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
187             return 0
188             ;;
189         environ)
190             opts="--products --shell --prefix --target"
191             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
192             return 0
193             ;;
194         configure)
195             opts="--products --option"
196             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
197             return 0
198             ;;
199         make)
200             opts="--products --option"
201             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
202             return 0
203             ;;
204         makeinstall)
205             opts="--products"
206             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
207             return 0
208             ;;
209         compile)
210             opts="--products --force --properties --with_fathers --with_children --clean_all --clean_make --install_flags --show --stop_first_fail --check --clean_build_after"
211             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
212             return 0
213             ;;
214         launcher)
215             opts="--products --name --exe --catalog --gencat --no_path_init --use_mesa"
216             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
217             return 0
218             ;;
219         jobs)
220             opts="--name --only_jobs --list --completion --test_connection --input_boards --publish"
221             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
222             return 0
223             ;;
224         shell)
225             opts="--command"
226             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
227             return 0
228             ;;
229         job)
230             opts="--jobs_config --name"
231             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
232             return 0
233             ;;
234         test)
235             opts="--base --launcher --grid --session --display"
236             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
237             return 0
238             ;;
239         package)
240             opts="--name --binaries --sources --exe --project --salometools --force_creation --add_files --with_vcs --ftp --without_property"
241             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
242             return 0
243             ;;
244         generate)
245             opts="--products --yacsgen"
246             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
247             return 0
248             ;;
249         find_duplicates)
250             opts="--path --sources --exclude-file --exclude-extension --exclude-path"
251             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
252             return 0
253             ;;
254         application)
255             opts="--name --catalog --target --gencat --module"
256             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
257             return 0
258             ;;
259         template)
260             opts="--name --template --target --param --info"
261             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
262             return 0
263             ;;
264         base)
265             opts="--set"
266             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
267             return 0
268             ;;
269         profile)
270             opts="--prefix --name --force --no_update --version --slogan"
271             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
272             return 0
273             ;;
274         script)
275             opts="--products --nb_proc"
276             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
277             return 0
278             ;;
279         check)
280             opts="--products"
281             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
282             return 0
283             ;;
284         init)
285             opts="--base --workdir --VCS --tag --log_dir --add_project --reset_projects"
286             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
287             return 0
288             ;;
289         *) return 0 ;;
290     esac
291     
292 }
293
294 # activation of auto-completion for the sat command
295 complete -F _salomeTools_complete sat
296 complete -F _salomeTools_complete ./sat
297