From cda2c1e9cbbdee2a44a803fee6492f22f3334ef5 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Fri, 22 Jul 2011 11:39:28 +0200 Subject: [PATCH] #14: Add Pear completion --- _pear | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 _pear diff --git a/_pear b/_pear new file mode 100644 index 0000000..a7eecaf --- /dev/null +++ b/_pear @@ -0,0 +1,84 @@ +#compdef pear +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for Pear (http://pear.php.net). +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * aki77 (https://github.com/aki77) +# +# ------------------------------------------------------------------------------ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------ + + +_pear () { + local curcontext="$curcontext" state line expl ret=1 + + _arguments \ + '1: :->subcmds' \ + '*:: :->args' && ret=0 + + case $state in + subcmds) + _pear_commands + ;; + args) + local cmd args + + cmd=$words[1] + args=() + + case $cmd in + channel-alias|channel-delete|channel-info|channel-update) + args+=( + ':channel:_pear_discovered_channels' + ) + ;; + uninstall|upgrade|run-scripts) + args+=( + ':package:_pear_installed_packages' + ) + ;; + esac + + _arguments "$args[@]" && ret=0 + return + ;; + esac + return ret +} + +_pear_commands () { + local commands + + commands=( + ${${(f)${"$(_call_program commands $service 2>&1)"#*Commands:}%Usage:*}/[[:blank:]]*[[:blank:]][[:blank:]]/:} + ) + _describe -t commands 'Pear commands' commands +} + +_pear_installed_packages () { + local packages + + packages=( + ${${(f)"$(pear list)"#*STATE}%%[[:blank:]]*} + ) + _wanted package expl 'package' compadd -a packages +} + +_pear_discovered_channels () { + local channels + + channels=( + ${${${(f)"$(_call_program commands pear list-channels)"#*SUMMARY}%__uri*}%%[[:blank:]]*} + ) + _wanted channel expl 'channel' compadd -a channels +} + +_pear "$@"