Salome HOME
e2c9bfc66517ab781567635b74604207093e4420
[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 $opts2)
36             ;;
37         jobs)
38             opts2=$(echo --jobs_config --only_jobs --list --no_label --test_connection --publish $opts2)
39             ;;
40         shell)
41             opts2=$(echo --command --sat $opts2)
42             ;;
43     esac
44
45     COMPREPLY=( $(compgen -W "${opts2}" -- ${cur}) )
46 }
47
48 _show_products()
49 {
50     if [[ $appli != $prev ]]
51     then
52         opts=$(for x in `$SAT_PATH/sat -s config $appli -nv APPLICATION.products`
53             do echo ${x}; done)
54
55         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
56    fi
57 }
58
59 _salomeTools_complete()
60 {
61     if [[ "${SAT_PATH}x" == "x" ]]
62     then
63         return 0
64     fi
65
66     local cur opts args command
67     COMPREPLY=()
68     argc="${COMP_CWORD}"
69     cur="${COMP_WORDS[COMP_CWORD]}"
70     
71     # second argument => show available APPLICATION
72     if [[ ${argc} > 1 ]]
73     then
74         command="${COMP_WORDS[1]}"
75     fi
76
77     if [[ ${argc} > 1 ]]
78     then
79         if [[ ${command%%-*} == "" ]]
80         then
81             command="${COMP_WORDS[2]}"
82             argc="$((( argc - 1)))"
83         fi
84     fi
85
86     # first argument => show available commands
87     if [[ ${argc} == 1 ]]
88     then
89         opts="config log testcommand source patch prepare environ clean configure make makeinstall compile launcher run jobs shell --help"
90         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
91         return 0
92     fi
93
94     if [[ ${argc} == 2 ]]
95     then
96         # get list of APPLICATIONS
97         _show_applications
98         return 0
99     fi
100     
101     # option depending on command
102     local prev="${COMP_WORDS[COMP_CWORD-1]}"
103     
104     if [[ ${prev} == "--value" || ${prev} == "-v" ]]
105     then
106         if [[ ${argc} == 4 ]]
107         then
108             # with application
109             opts=$(for x in `$SAT_PATH/sat config ${COMP_WORDS[COMP_CWORD-2]} -s ${COMP_WORDS[COMP_CWORD]}`
110                 do echo ${x} ; done)
111             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
112         else
113             # without application
114             opts=$(for x in `$SAT_PATH/sat config -s ${COMP_WORDS[COMP_CWORD]}`
115                 do echo ${x} ; done)
116             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
117         fi
118         
119         return 0
120     fi
121       
122     # show list of products
123     if [[ ${prev} == "--product" || ${prev} == "-p" ]]
124     then
125         appli="${COMP_WORDS[2]}"
126         if [[ ${command} != "source" ]]
127         then
128             opts=$(for x in `$SAT_PATH/sat config $appli -nv APPLICATION.products`
129                 do echo ${x}; done)
130
131                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
132             return 0
133         fi
134     fi
135
136     # show argument for each command
137     case "${command}" in
138         config)
139             opts="--value --list --copy --edit --no_label --info"
140             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
141             return 0        
142             ;;
143         log)
144             opts="--clean --last --terminal --last"
145             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
146             return 0
147             ;;
148         clean)
149             opts="--products --sources --build --install --all --sources_without_dev"
150             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
151             return 0
152             ;;
153         source)
154             opts="--products"
155             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
156             return 0
157             ;;
158         patch)
159             opts="--products"
160             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
161             return 0
162             ;;
163         prepare)
164             opts="--products --force --force_patch"
165             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
166             return 0
167             ;;
168         environ)
169             opts="--products --shell --prefix --target"
170             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
171             return 0
172             ;;
173         configure)
174             opts="--products --option"
175             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
176             return 0
177             ;;
178         make)
179             opts="--products --option"
180             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
181             return 0
182             ;;
183         makeinstall)
184             opts="--products"
185             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
186             return 0
187             ;;
188         compile)
189             opts="--products --with_fathers --with_children --clean_all --make_flags --show --stop_first_fail"
190             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
191             return 0
192             ;;
193         launcher)
194             opts="--name --catalog --gencat"
195             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
196             return 0
197             ;;
198         jobs)
199             opts="--jobs_config --only_jobs --list --no_label --test_connection --publish"
200             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
201             return 0
202             ;;
203         shell)
204             opts="--command --sat"
205             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
206             return 0
207             ;;
208         *) return 0 ;;
209     esac
210     
211 }
212
213 # activation of auto-completion for the sat command
214 complete -F _salomeTools_complete sat
215 complete -F _salomeTools_complete ./sat
216