-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrupal.complete.sh
150 lines (123 loc) · 3.93 KB
/
drupal.complete.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#===============================================================================
# DrupalRC completions
#===============================================================================
# shellcheck disable=SC2155
# shellcheck disable=SC2207
#-------------------------------------------------------------------------------
# dcd completion.
#-------------------------------------------------------------------------------
_complete_dcd() {
COMPREPLY=()
# Complete only fist argument.
if [[ $COMP_CWORD -gt 1 ]]; then
return 0
fi
local DRUPAL_ROOT
if ! DRUPAL_ROOT=$(droot); then
return 1
fi
if [[ $(_dversion "$DRUPAL_ROOT") -lt 8 ]]; then
return 1
fi
TARGET_DIRS="$DRUPAL_ROOT/core/modules $DRUPAL_ROOT/core/themes $DRUPAL_ROOT/modules $DRUPAL_ROOT/themes"
# shellcheck disable=SC2086
DIRS=$(find \
$TARGET_DIRS \
-maxdepth 4 \
-path "*engines" -prune -o \
-path "*js" -prune -o \
-path "*css" -prune -o \
-path "*tests" -prune -o \
-path "*templates" -prune -o \
-path "*config" -prune -o \
-path "*src" -prune -o \
-path "*.git" -prune -o \
-name "*.info.yml"\
-printf '%f\n')
local SUGGESTIONS=$(_dcd_dirs)" "${DIRS//.info.yml}
local CUR="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$SUGGESTIONS" -- "$CUR") )
}
complete -o plusdirs -F _complete_dcd dcd
#-------------------------------------------------------------------------------
# dconf completion.
#-------------------------------------------------------------------------------
_complete_dconf() {
COMPREPLY=()
# Complete only fist argument.
if [[ $COMP_CWORD -gt 1 ]]; then
return 0
fi
local DRUPAL_ROOT
if ! DRUPAL_ROOT=$(droot); then
return 1
fi
local PROJECT_ROOT
if ! PROJECT_ROOT=$(_dproject "$DRUPAL_ROOT"); then
return 1
fi
local SUGGESTIONS=$(find "$DRUPAL_ROOT"/sites/default -maxdepth 1 -type f -printf '%f\n')
if [[ -f $PROJECT_ROOT/composer.json ]]; then
SUGGESTIONS="$SUGGESTIONS composer.json"
fi
if [[ -f $PROJECT_ROOT/package.json ]]; then
SUGGESTIONS="$SUGGESTIONS package.json"
fi
if [[ -f $PROJECT_ROOT/phpcs.xml ]]; then
SUGGESTIONS="$SUGGESTIONS phpcs.xml"
fi
if [[ -f $PROJECT_ROOT/phpunit.xml ]]; then
SUGGESTIONS="$SUGGESTIONS phpunit.xml"
fi
local CUR="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$SUGGESTIONS" -- "$CUR") )
}
complete -F _complete_dconf dconf
#-------------------------------------------------------------------------------
# dbin completion.
#-------------------------------------------------------------------------------
_complete_dbin() {
COMPREPLY=()
# Complete only fist argument.
if [[ $COMP_CWORD -gt 1 ]]; then
return
fi
local DRUPAL_ROOT
if ! DRUPAL_ROOT=$(droot); then
return 1;
fi
local BIN_DIR
if ! BIN_DIR=$(_dbin "$DRUPAL_ROOT"); then
return 1
fi
local SUGGESTIONS=$(find "$BIN_DIR" -mindepth 1 -maxdepth 1 -executable -printf '%f\n')
local CUR="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$SUGGESTIONS" -- "$CUR") )
}
complete -o default -F _complete_dbin dbin
#-------------------------------------------------------------------------------
# dunit completion.
#-------------------------------------------------------------------------------
_complete_dunit() {
COMPREPLY=()
local DRUPAL_ROOT
if ! DRUPAL_ROOT=$(droot); then
return 1;
fi
local FILE=$(_dbin "$DRUPAL_ROOT")/phpunit
if [[ ! -x $FILE ]]; then
return 1
fi
local CUR="${COMP_WORDS[COMP_CWORD]}"
# Only options can be completed.
if [[ ${CUR:0:1} != '-' ]]; then
return 0
fi
local SUGGESTIONS=$($FILE --help | grep -oE ' --[a-z-]+')
COMPREPLY=( $(compgen -W "$SUGGESTIONS" -- "$CUR") )
}
complete -o default -F _complete_dunit dunit
#-------------------------------------------------------------------------------
# dcomposer completion.
#-------------------------------------------------------------------------------
complete -F _composer dcomposer