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