OSDN Git Service

Newly import UTF-8 code
[ethna/ethna.git] / misc / _ethna
1 #compdef ethna
2
3 # usage:
4 #   1. copy this file to your favorite directory (ex, ~/.zshrc.d/completion)
5 #   2. add below lines to your .zshrc:
6 #      > fpath=(~/.zshrc.d/completion $fpath)
7 #      > autoload -U compinit
8 #      > compinit -u
9 #   3. push [tab] when you typing ethna command's argument.
10 #      % ethna add-[tab]
11 #
12 # note:
13 #   - we tested this function only with Debian/GNU Linux.
14 #   - $Id: _ethna 411 2006-11-17 02:32:32Z ichii386 $
15
16 _ethna() {
17     local curcontext="$curcontext" state line expl ret=1
18
19     _arguments -C \
20         '(-v --version)'{-v,--version}'[show version]' \
21         '1:ethna command:->ethna-cmd' \
22         '*:ethna command args:->ethna-cmd-arg' \
23         && ret=0
24
25     if [[ -n "$state" ]]; then
26         case $state in
27             ethna-cmd)
28                 handles=( $($service | grep '^ \+.* -> .*:$' | awk '{print $1}') )
29                 _wanted ethna-cmd expl 'ethna cmd' compadd -a handles && ret=0
30             ;;
31             ethna-cmd-arg)
32                 usage=$($service | grep -A 1 "^ \+$words[2] ->")
33                 if [[ -n "$usage" ]]; then
34                     _wanted ethna-cmd-arg expl 'ethna cmd arg' compadd -x "$usage" && ret=0
35                 else
36                     _wanted ethna-cmd-arg expl 'ethna cmd arg' compadd -x "unknown command" && ret=0
37                 fi
38             ;;
39         esac    
40     fi
41
42     return ret
43 }