Skip to content

Instantly share code, notes, and snippets.

@yuuan
Created July 9, 2020 06:42
Show Gist options
  • Save yuuan/b132ec0f708e1edb412e10fd84e63321 to your computer and use it in GitHub Desktop.
Save yuuan/b132ec0f708e1edb412e10fd84e63321 to your computer and use it in GitHub Desktop.
Zsh で composer コマンドを補完
#compdef composer
function __composer_get_command_list() {
if which composer &> /dev/null && which perl &> /dev/null; then
composer list --raw | perl -pe 's/:/\\:/g;s/([a-z\\:-]+)(?:\s+(.*))?/$1:$2/ig;'
fi
}
function __composer_commands() {
local -a cmds
cmds=( ${(@f)"$(__composer_get_command_list)"} )
_describe -t commands "commands" cmds
}
function _composer() {
local context curcontext=$curcontext state line
declare -A opt_args
local ret=1
_arguments -C \
'(-h --help)'{-h,--help}'[Display help message]' \
'1: :__composer_commands' \
'*:: :->args' \
&& ret=0
case $state in
(args)
__options \
'*:files:_files' \
&& ret=0
;;
esac
return ret
}
_composer "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment