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