You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit refactors hook generation into its own class, and includes the
ZSH completion hook I wrote a few months ago for stecman/composer-bash-completion-plugin.
Copy file name to clipboardExpand all lines: README.md
+19-11Lines changed: 19 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# BASH completion for Symfony Console applications
2
2
3
-
This package provides automatic BASH completion for Symfony Console Component based applications. With zero configuration, this package allows completion of available command names and the options they provide. Custom completion behaviour can be added for option and argument values by name.
3
+
This package provides automatic (tab) completion in BASH and ZSH for Symfony Console Component based applications. With zero configuration, this package allows completion of available command names and the options they provide. Custom completion behaviour can be added for option and argument values by name.
4
4
5
5
Example of zero-config use with Composer:
6
6
@@ -12,20 +12,28 @@ If you don't need any custom completion behaviour, all you need to do is add the
12
12
13
13
1. Install `stecman/symfony-console-completion` through composer
14
14
2. Add an instance of `CompletionCommand` to your application's `Application::getDefaultCommands()` method:
15
-
```php
16
-
protected function getDefaultCommands()
17
-
{
18
-
//...
19
-
$commands[] = new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand();
20
-
//...
21
-
}
22
-
```
23
-
24
-
3. Run `eval $([program] _completion --generate-hook)` in a terminal, replacing `[program]` with the command you use to run your application (eg. 'composer'). By default this registers completion for the absolute path to you application; you can specify a command name to complete for instead using the `-p` option.
15
+
```php
16
+
protected function getDefaultCommands()
17
+
{
18
+
//...
19
+
$commands[] = new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand();
20
+
//...
21
+
}
22
+
```
23
+
24
+
3. Run the following in a terminal, replacing `[program]` with the command you use to run your application (eg. 'composer'):
By default this registers completion for the absolute path to you application. You can specify a command name to complete for instead using the `-p` option, which is useful if you're using an alias to run the program. Under BASH, an alternative command is `eval $([program] _completion --generate-hook)`, however the command above is recommended as it works for both BASH and ZSH.
25
31
4. Add the command from step 3 to your bash profile if you want the completion to apply automatically for all new terminal sessions.
26
32
27
33
Note: If `[program]` is an alias you will need to specify the aliased name with the `-p|--program` option, as completion may not work otherwise: `_completion --generate-hook -p [myalias]`.
28
34
35
+
Second note: The type of shell (ZSH/BASH) is automatically detected using the `SHELL` environment variable at run time. In some circumstances, you may need to explicitly set the shell type using the `--shell` option.
36
+
29
37
### How it works
30
38
31
39
The `--generate-hook` option of `CompletionCommand` generates a few lines of BASH that, when executed, register your application as a completion handler for your itself in the current shell session. When you request completion for your program (by pressing tab), the completion command on your application is run with no arguments: `[program] _completion`. This uses environment variables set by BASH to get the current command line contents and cursor position, then completes from your console command definitions.
0 commit comments