-
Notifications
You must be signed in to change notification settings - Fork 2
/
modx_completion.sh
executable file
·72 lines (63 loc) · 1.78 KB
/
modx_completion.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# bash completion support for symfony2 console
#
# Copyright (C) 2011 Matthieu Bontemps <[email protected]>
# Distributed under the GNU General Public License, version 2.0.
_console()
{
local cur prev script
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
script="${COMP_WORDS[0]}"
# Define site so we can grab command savailable for the instance
site=""
for var in "$@"
do
# if [[ $var == "-s" ]]; then
# #echo "Looking for instances names"
# names=$(${script} config:list | sed 's/|/ /' | awk '{print $1}')
# echo $names;
# return 0;
# COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
# return 0;
# fi
if [[ $var == "-s"* ]] || [[ $var == "--site"* ]]; then
site="$var"
fi
done
if [[ ${cur} == -* ]] ; then
# Get options
PHP=$(cat <<'HEREDOC'
array_shift($argv);
$script = array_shift($argv);
$command = '';
foreach ($argv as $v) {
if (0 !== strpos($v, '-')) {
$command = $v;
break;
}
}
$xmlHelp = shell_exec($script.' help --xml ' . $command);
$options = array();
if (!$xml = @simplexml_load_string($xmlHelp)) {
exit(0);
}
foreach ($xml->xpath('/command/options/option') as $option) {
$options[] = (string) $option['name'];
}
echo implode(' ', $options);
HEREDOC
)
args=$(printf "%s " "${COMP_WORDS[@]}")
options=$($(which php) -r "$PHP" ${args});
COMPREPLY=($(compgen -W "${options}" -- ${cur}))
return 0
fi
commands=$(${script} list --raw "${site}" | sed -E 's/(([^ ]+ )).*/\1/')
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0;
}
complete -F _console modx
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}