Skip to content

Commit 6e8755f

Browse files
committed
docs: autocompletion
1 parent 1152671 commit 6e8755f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Framework agnostic Command Line Interface utilities and helpers for PHP. Build C
2121

2222
**IO:** [Colorizer](#color) · [Cursor manipulator](#cursor) · [Stream writer](#writer) · [Stream reader](#reader)
2323

24+
**Other:** [Autocompletion](#autocompletion)
25+
2426
## Installation
2527
```bash
2628
composer require adhocore/cli
@@ -489,6 +491,48 @@ Whenever an exception is caught by `Application::handle()`, it will show a beaut
489491

490492
![Exception Preview](https://user-images.githubusercontent.com/2908547/44401057-8b350880-a577-11e8-8ca6-20508d593d98.png "Exception trace")
491493

494+
### Autocompletion
495+
496+
Any console line apps that are built on top of **adhocore/cli** can entertain autocomplete of commands and options in zsh shell with oh-my-zsh.
497+
498+
All you have to do is add one line to the end of `~/.oh-my-zsh/custom/plugins/phpcli/phpcli.plugin.zsh`:
499+
500+
> `compdef _phpcli <appname>`
501+
502+
Example: `compdef _phpcli phint` for [phint](https://github.com/adhocore/phint).
503+
504+
That is cumbersome to perform manually, here's a complete command you can copy/paste/run:
505+
506+
#### One time setup
507+
508+
```sh
509+
mkdir -p ~/.oh-my-zsh/custom/plugins/phpcli && cd ~/.oh-my-zsh/custom/plugins/phpcli
510+
[ -f ./phpcli.plugin.zsh ] || curl -sSLo ./phpcli.plugin.zsh https://raw.githubusercontent.com/adhocore/php-cli/master/phpcli.plugin.zsh
511+
chmod +x ./phpcli.plugin.zsh && cd -
512+
```
513+
514+
#### Registering app
515+
516+
```sh
517+
# replace appname with real name eg: phint
518+
echo compdef _phpcli appname >> ~/.oh-my-zsh/custom/plugins/phpcli/phpcli.plugin.zsh
519+
```
520+
521+
> Of course you can add multiple apps, just change appname in above command
522+
523+
Then either restart the shell or source the plugin like so:
524+
525+
```sh
526+
source ~/.oh-my-zsh/custom/plugins/phpcli/phpcli.plugin.zsh
527+
```
528+
529+
#### Trigger autocomplete
530+
531+
```sh
532+
appname <tab> # autocompletes commands (phint <tab>)
533+
appname subcommand <tab> # autocompletes options for subcommand (phint init <tab>)
534+
```
535+
492536
### Related
493537

494538
- [adhocore/phalcon-ext](https://github.com/adhocore/phalcon-ext) Phalcon extension using `adhocore/cli`

0 commit comments

Comments
 (0)