forked from adhocore/php-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ahccli.plugin.zsh
42 lines (36 loc) · 1.43 KB
/
ahccli.plugin.zsh
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
# ------------------------------------------------------------------------------
# FILE: ahccli.plugin.zsh
# DESCRIPTION: oh-my-zsh ahccli plugin file.
# AUTHOR: Jitendra Adhikari (jiten.adhikary@gmail.com)
# VERSION: 0.0.1
# LICENSE: MIT
# ------------------------------------------------------------------------------
# Specifically tuned to support autocompletion for apps build with adhocore/cli!
# Check https://github.com/adhocore/php-cli#autocompletion
# ------------------------------------------------------------------------------
# AhcCli command completion
_ahccli_command_list () {
command $1 --help 2>/dev/null | sed "1,/Commands/d" | gawk 'match($0, / ([a-z]+) [a-z]* /, c) { print c[1] }'
}
# AhcCli option completion
_ahccli_option_list () {
command $1 $2 --help 2>/dev/null | sed '1,/Options/d' | gawk 'match($0, / .*(--[a-z-]+)(\.\.\.)?. /, o) { print o[1] }'
}
# AhcCli compdef handler
_ahccli () {
local curcontext="$curcontext" state line cmd subcmd
typeset -A opt_args
_arguments '1: :->cmd' '*: :->opts'
cmd=`echo $curcontext | gawk 'match($0, /\:([_a-z-]+)\:$/, c) { print c[1] }'`
subcmd=`echo $line | awk '{print $1}'`
case $state in
cmd) compadd $(_ahccli_command_list $cmd) ;;
opts) compadd $(_ahccli_option_list $cmd $subcmd) ;;
esac
}
#
# Register commands for autocompletion below:
#
# format: compdef _ahccli <cmd>
# example: compdef _ahccli phint
#