forked from plumed/plumed2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash.completion
47 lines (42 loc) · 1.35 KB
/
bash.completion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Experimental script for bash completion. Just "source" it.
# In perspective, this script should be generated automatically by the plumed
# executable on the basis of the implemented CLTools.
#
_plumed()
{
local cur prev opts cmds
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# these options can be combined with other commands
opts="--load"
# only one of these commands should be used
cmds="help driver info manual simplemd mklib newcv patch -h --help --has-mpi"
local cmd_found i cmd_test
# check if one of the previous keywords is a command
for((i=1;i<COMP_CWORD;i++)); do
cmd_found=""
for cmd_test in $cmds ; do
if [[ "$cmd_test" == "${COMP_WORDS[i]}" ]] ; then
COMPREPLY=( $(compgen -f -- $cur ) )
return 0
fi
done
if [[ $cmd_found == 1 ]]; then
break
fi
done
# if previous is --load, autocomplete with dynamic library
if [[ "${prev}" == --load ]] ; then
COMPREPLY=( $(compgen -f -X '!*.@(dylib|so)' -- $cur ) )
return 0
fi
# complete with options or commands
case "${cur}" in
# show options only if completing a "-"
(-*) COMPREPLY=( $(compgen -W "${opts} ${cmds}" -- ${cur}) ) ;;
(*) COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) ) ;;
esac
return 0
}
complete -d -F _plumed plumed