Skip to content

Commit 7b4481c

Browse files
author
Sushil Gupta
authored
Merge branch 'master' into develop
2 parents 573d3c1 + 269fea1 commit 7b4481c

File tree

4 files changed

+117
-5
lines changed

4 files changed

+117
-5
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## [0.3.2] 2018-09-06 15:09:22 UTC
2+
3+
- [6e8755f](https://github.com/adhocore/php-cli/commit/6e8755f) docs: autocompletion (Jitendra Adhikari)
4+
- [1152671](https://github.com/adhocore/php-cli/commit/1152671) chore(zsh.plugin): auto complete provider for zsh with oh-my-zsh (Jitendra Adhikari)
5+
6+
## [0.3.1] 2018-09-06 00:09:23 UTC
7+
8+
- [f390b6b](https://github.com/adhocore/php-cli/commit/f390b6b) refactor: remove redundant codeCoverageIgnore (Sushil Gupta)
9+
- [cd8d109](https://github.com/adhocore/php-cli/commit/cd8d109) refactor: minor refactor on messages + add isWindows() method using DIRECTORY_SEPARATOR check to set pipes (Sushil Gupta)
10+
111
## [0.3.0] 2018-09-04 15:09:50 UTC
212

313
- [a1c2c30](https://github.com/adhocore/php-cli/commit/a1c2c30) docs: add shell section and contributors (Jitendra Adhikari)

README.md

Lines changed: 64 additions & 4 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
@@ -227,7 +229,7 @@ Same version number is passed to all attached Commands. So you can trigger versi
227229

228230
### Shell
229231

230-
Very thing shell wrapper that provides convenience methods around `proc_open()`.
232+
Very thin shell wrapper that provides convenience methods around `proc_open()`.
231233

232234
#### Basic usage
233235

@@ -489,11 +491,69 @@ 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 applications 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/ahccli/ahccli.plugin.zsh`:
499+
500+
> `compdef _ahccli <appname>`
501+
502+
Example: `compdef _ahccli 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/ahccli && cd ~/.oh-my-zsh/custom/plugins/ahccli
510+
511+
[ -f ./ahccli.plugin.zsh ] || curl -sSLo ./ahccli.plugin.zsh https://raw.githubusercontent.com/adhocore/php-cli/master/ahccli.plugin.zsh
512+
513+
chmod 760 ./ahccli.plugin.zsh && cd -
514+
```
515+
516+
##### Load ahccli plugin
517+
518+
> This is also one time setup.
519+
520+
```sh
521+
# Open .zshrc
522+
nano ~/.zshrc
523+
524+
# locate plugins=(... ...) and add ahccli
525+
plugins=(git ... ... ahccli)
526+
527+
# ... then save it (Ctrl + O)
528+
```
529+
530+
#### Registering app
531+
532+
```sh
533+
# replace appname with real name eg: phint
534+
echo compdef _ahccli appname >> ~/.oh-my-zsh/custom/plugins/ahccli/ahccli.plugin.zsh
535+
```
536+
537+
> Of course you can add multiple apps, just change appname in above command
538+
539+
Then either restart the shell or source the plugin like so:
540+
541+
```sh
542+
source ~/.oh-my-zsh/custom/plugins/ahccli/ahccli.plugin.zsh
543+
```
544+
545+
#### Trigger autocomplete
546+
547+
```sh
548+
appname <tab> # autocompletes commands (phint <tab>)
549+
appname subcommand <tab> # autocompletes options for subcommand (phint init <tab>)
550+
```
551+
492552
### Related
493553

494-
- [adhocore/phalcon-ext](https://github.com/adhocore/phalcon-ext) Phalcon extension using `adhocore/cli`
495-
- [adhocore/phint](https://github.com/adhocore/phint) PHP project scaffolding app using `adhocore/cli`
496-
- [adhocore/type-hinter](https://github.com/adhocore/php-type-hinter) Auto PHP7 typehinter tool using `adhocore/cli`
554+
- [adhocore/phalcon-ext](https://github.com/adhocore/phalcon-ext) &middot; Phalcon extension using `adhocore/cli`
555+
- [adhocore/phint](https://github.com/adhocore/phint) &middot; PHP project scaffolding app using `adhocore/cli`
556+
- [adhocore/type-hinter](https://github.com/adhocore/php-type-hinter) &middot; Auto PHP7 typehinter tool using `adhocore/cli`
497557

498558
### Contributors
499559

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
0.3.2

ahccli.plugin.zsh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# ------------------------------------------------------------------------------
2+
# FILE: ahccli.plugin.zsh
3+
# DESCRIPTION: oh-my-zsh ahccli plugin file.
4+
# AUTHOR: Jitendra Adhikari ([email protected])
5+
# VERSION: 0.0.1
6+
# LICENSE: MIT
7+
# ------------------------------------------------------------------------------
8+
# Specifically tuned to support autocompletion for apps build with adhocore/cli!
9+
# Check https://github.com/adhocore/php-cli#autocompletion
10+
# ------------------------------------------------------------------------------
11+
12+
# AhcCli command completion
13+
_ahccli_command_list () {
14+
command $1 --help 2>/dev/null | sed "1,/Commands/d" | gawk 'match($0, / ([a-z]+) [a-z]* /, c) { print c[1] }'
15+
}
16+
17+
# AhcCli option completion
18+
_ahccli_option_list () {
19+
command $1 $2 --help 2>/dev/null | sed '1,/Options/d' | gawk 'match($0, / .*(--[a-z-]+)(\.\.\.)?. /, o) { print o[1] }'
20+
}
21+
22+
# AhcCli compdef handler
23+
_ahccli () {
24+
local curcontext="$curcontext" state line cmd subcmd
25+
typeset -A opt_args
26+
_arguments '1: :->cmd' '*: :->opts'
27+
28+
cmd=`echo $curcontext | gawk 'match($0, /\:([_a-z-]+)\:$/, c) { print c[1] }'`
29+
subcmd=`echo $line | awk '{print $1}'`
30+
31+
case $state in
32+
cmd) compadd $(_ahccli_command_list $cmd) ;;
33+
opts) compadd $(_ahccli_option_list $cmd $subcmd) ;;
34+
esac
35+
}
36+
37+
#
38+
# Register commands for autocompletion below:
39+
#
40+
# format: compdef _ahccli <cmd>
41+
# example: compdef _ahccli phint
42+
#

0 commit comments

Comments
 (0)