forked from webflo/drush_zsh_completion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
drush_zsh.drush.inc
164 lines (141 loc) · 4.4 KB
/
drush_zsh.drush.inc
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
// $Id:
/**
* @file
* Some commands for zsh completion
*/
/**
* Implementation of hook_drush_command().
*
* @See drush_parse_command() for a list of recognized keys.
*
* @return
* An associative array describing each command.
*/
function drush_zsh_drush_command() {
$items = array();
$items['zsh-commands'] = array(
'description' => 'Return all drush commands.',
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'hidden' => TRUE,
);
$items['zsh-options'] = array(
'description' => 'Return command options.',
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'hidden' => TRUE,
);
$items['zsh-features-list'] = array(
'description' => 'Return all features',
'hidden' => TRUE,
);
return $items;
}
/**
* Drush zsh-commands callback.
*/
function drush_drush_zsh_zsh_commands() {
$phases = _drush_bootstrap_phases();
// For speed, only bootstrap up to DRUSH_BOOTSTRAP_DRUPAL_SITE+1.
$phases = array_slice($phases, 0, DRUSH_BOOTSTRAP_DRUPAL_SITE+1);
$printed_rows = $rows = array();
$phase_index = DRUSH_BOOTSTRAP_DRUSH;
foreach ($phases as $phase_index) {
if (drush_bootstrap_validate($phase_index)) {
if ($phase_index > drush_get_context('DRUSH_BOOTSTRAP_PHASE')) {
drush_bootstrap($phase_index);
}
$commands = drush_get_commands();
// Filter by command file if specified.
if ($commandfile = drush_get_option('filter')) {
foreach ($commands as $key => $candidate) {
if ($candidate['commandfile'] != $commandfile) {
unset($commands[$key]);
}
}
}
$rows = array();
ksort($commands);
foreach($commands as $key => $command) {
if (!$command['hidden']) {
if (!array_key_exists('is_alias', $command) || !$command['is_alias']) {
if (!array_key_exists($key, $printed_rows)) {
$name = $command['aliases'] ? $key . ' (' . implode(', ', $command['aliases']) . ')': $key;
$rows[$key] = array($name, $command['description']);
$command_completion[] = $key . ':' . $command['description'];
foreach($command['aliases'] as $alias) {
$command_completion[] = $alias . ':' . $command['description'];
}
}
}
}
}
$printed_rows = array_merge($printed_rows, $rows);
}
else {
break;
}
}
// Newline-delimited list for zsh completion. Set the --commands option.
if (isset($command_completion)) {
drush_print_pipe($command_completion);
}
return;
}
/**
* Drush zsh-options callback.
*/
function drush_drush_zsh_zsh_options() {
$command = func_get_args();
$completion = array();
if (!empty($command)) {
// Drush command. Get specific options
$commandstring = array_shift($command);
$commands = drush_get_commands();
if (array_key_exists($commandstring, $commands)) {
$command = $commands[$commandstring];
$completion = drush_zsh_extract_options($command);
}
} else {
// No drush command. Get global options
foreach(drush_get_global_options() as $option => $info) {
if (is_array($info)) {
switch ($option) {
case 'root':
$function = ':directory:_path_files -/';
$option .= '=';
break;
default:
$function = '';
}
if ($info['short-form']) {
$completion[] = '(-' . $info['short-form'] . ')-' . $info['short-form'] . '['. $info['description'] . ']' . $function;
}
$completion[] = '(--' . $option . ')--' . $option . '[' . $info['description'] . ']' . $function;
} else {
$completion[] = '(--' . $option .')--' . $option . '[' . $info . ']' . $function;
}
}
}
drush_print_pipe($completion);
}
function drush_zsh_extract_options($command) {
$row = array();
if (is_array($command['options'])) {
foreach($command['options'] as $option => $description) {
$aliases = explode(',' , $option);
foreach($aliases as $alias) {
$row[] = '(--' . trim($alias) .')--' . trim($alias). '['. $description .']';
}
}
}
return $row;
}
function drush_drush_zsh_zsh_features_list() {
module_load_include('inc', 'features', 'features.export');
$rows = array();
foreach (features_get_features(NULL, TRUE) as $k => $m) {
$rows[] = $m->name;
}
$rows = implode(',', $rows);
drush_print_pipe($rows);
}