Salome HOME
68beb5af3ebe14558f11918ea4b7d91f580d2f2e
[modules/kernel.git] / bin / appliskel / .salome-completion.sh
1 #!/bin/bash
2
3 # Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 # Bash completion support for salome command.
23 #
24 # How to use this file?
25 # 1. If you have a root access, copy the file to /etc/bash_completion.d/
26 # 2. If you do not have root access or want to make a user-speficic installation:
27 #    2.1. Copy this file to somewhere (e.g. ~/.salome-completion.sh).
28 #    2.2. Add the following line to your .bashrc:
29 #         source ~/.salome-completion.sh
30 #
31
32 _salome_long_options()
33 {
34     case $1 in
35         --show-desktop|--splash|--catch-exceptions|--shutdown-servers|--foreground)
36             options='1 0'
37             ;;
38         --server-launch-mode)
39             options='daemon fork'
40             ;;
41     esac
42     COMPREPLY=( $( compgen -W "$options" -- "$2" ) )
43 }
44
45 # Function used to compute the completion
46 _salome()
47 {
48     # COMP_WORDS is an array that contains all command line elements (the script and its arguments)
49     # COMP_CWORD is the index of current element in command line
50     # COMPREPLY is an array of strings that are the proposals as returned by auto-completion
51     local cur prev command options
52     COMPREPLY=( )
53     _get_comp_words_by_ref -n = cur prev
54     commands='start context shell connect kill killall test info help coffee car'
55
56     # Algorithm:
57     # If cursor is at index 1
58     #    Complete with commands
59     # Else
60     #    Find current command
61     #    If word under cursor starts with '-'
62     #       Complete options regarding current command
63
64     if [[ $COMP_CWORD -eq 1 ]] ; then
65         COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
66     elif [[ "$cur" == --*=* ]]; then
67         _split_longopt
68         _salome_long_options "$prev" "$cur"
69     elif [[ "$cur" == -* ]]; then
70         command=${COMP_WORDS[1]}
71         if [[ "$cur" == -* ]]; then
72             case $command in
73                 start)
74                     options='-t --terminal -g --gui -d --show-desktop= -o --hide-desktop -b --batch -l --logger -f --log-file= -r --resources= -x --xterm -m --modules= -e --embedded= -s --standalone= -p --portkill -k --killall -i --interp= -z --splash= -c --catch-exceptions= --print-port --nosave-config --pinter --ns-port-log= --test= --play= --gdb-session --ddd-session --valgrind-session -w --shutdown-servers= --foreground= --wake-up-session --server-launch-mode= --port= --version -h --help --with-mpi-module= --config= --extra_env='
75                     ;;
76                 shell)
77                     options='-h --help -p --port= -m --machine= -d --directory= -u --user= --with-mpi-module= --config= --extra_env='
78                     ;;
79                 info)
80                     options='-h --help -p --ports -s --softwares -v --version'
81                     ;;
82                 connect)
83                     options='-h --help -c -p'
84                     ;;
85                 test)
86                     options='-h --help --print-labels'
87                     ;;
88             esac
89             COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
90         fi
91     fi
92
93 }
94
95 # The-F option gives the name of the function that calculates the completion; moreover it tells the complete command that it must seek the results in the COMPREPLY variable.
96 complete -o bashdefault -o default -o nospace -F _salome salome 2>/dev/null \
97     || complete -o default -o nospace -F _salome salome
98
99 # The following are necessary only for Cygwin, and only are needed
100 # when the user has tab-completed the executable name and consequently
101 # included the '.exe' suffix.
102 #
103 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
104 complete -o bashdefault -o default -o nospace -F _salome salome.exe 2>/dev/null \
105     || complete -o default -o nospace -F _salome salome.exe
106 fi