Auto merge of #3901 - rex4539:electric-coin-company, r=str4d
[VerusCoin.git] / contrib / zcash-cli.bash-completion
1 # bash programmable completion for zcash-cli(1)
2 # Copyright (c) 2012-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6 # call $zcash-cli for RPC
7 _zcash_rpc() {
8     # determine already specified args necessary for RPC
9     local rpcargs=()
10     for i in ${COMP_LINE}; do
11         case "$i" in
12             -conf=*|-datadir=*|-regtest|-rpc*|-testnet)
13                 rpcargs=( "${rpcargs[@]}" "$i" )
14                 ;;
15         esac
16     done
17     $zcash_cli "${rpcargs[@]}" "$@"
18 }
19
20 # Add wallet accounts to COMPREPLY
21 _zcash_accounts() {
22     local accounts
23     # Accounts are deprecated in Zcash
24     #accounts=$(_zcash_rpc listaccounts | awk -F '"' '{ print $2 }')
25     accounts="\\\"\\\""
26     COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
27 }
28
29 _zcash_cli() {
30     local cur prev words=() cword
31     local zcash_cli
32
33     # save and use original argument to invoke zcash-cli for -help, help and RPC
34     # as zcash-cli might not be in $PATH
35     zcash_cli="$1"
36
37     COMPREPLY=()
38     _get_comp_words_by_ref -n = cur prev words cword
39
40     if ((cword > 5)); then
41         case ${words[cword-5]} in
42             sendtoaddress)
43                 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
44                 return 0
45                 ;;
46         esac
47     fi
48
49     if ((cword > 4)); then
50         case ${words[cword-4]} in
51             importaddress|listtransactions|setban)
52                 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
53                 return 0
54                 ;;
55             signrawtransaction)
56                 COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
57                 return 0
58                 ;;
59         esac
60     fi
61
62     if ((cword > 3)); then
63         case ${words[cword-3]} in
64             addmultisigaddress)
65                 _zcash_accounts
66                 return 0
67                 ;;
68             getbalance|gettxout|importaddress|importpubkey|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
69                 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
70                 return 0
71                 ;;
72         esac
73     fi
74
75     if ((cword > 2)); then
76         case ${words[cword-2]} in
77             addnode)
78                 COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
79                 return 0
80                 ;;
81             setban)
82                 COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) )
83                 return 0
84                 ;;
85             fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
86                 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
87                 return 0
88                 ;;
89             z_importkey|z_importviewingkey)
90                 COMPREPLY=( $( compgen -W "yes no whenkeyisnew" -- "$cur" ) )
91                 return 0
92                 ;;
93             move|setaccount)
94                 _zcash_accounts
95                 return 0
96                 ;;
97         esac
98     fi
99
100     case "$prev" in
101         backupwallet|dumpwallet|importwallet|z_exportwallet|z_importwallet)
102             _filedir
103             return 0
104             ;;
105         getaddednodeinfo|getrawmempool|lockunspent|setgenerate)
106             COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
107             return 0
108             ;;
109         getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
110             _zcash_accounts
111             return 0
112             ;;
113     esac
114
115     case "$cur" in
116         -conf=*)
117             cur="${cur#*=}"
118             _filedir
119             return 0
120             ;;
121         -datadir=*)
122             cur="${cur#*=}"
123             _filedir -d
124             return 0
125             ;;
126         -*=*)   # prevent nonsense completions
127             return 0
128             ;;
129         *)
130             local helpopts commands
131
132             # only parse -help if senseful
133             if [[ -z "$cur" || "$cur" =~ ^- ]]; then
134                 helpopts=$($zcash_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
135             fi
136
137             # only parse help if senseful
138             if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
139                 commands=$(_zcash_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
140             fi
141
142             COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
143
144             # Prevent space if an argument is desired
145             if [[ $COMPREPLY == *= ]]; then
146                 compopt -o nospace
147             fi
148             return 0
149             ;;
150     esac
151 } &&
152 complete -F _zcash_cli zcash-cli
153
154 # Local variables:
155 # mode: shell-script
156 # sh-basic-offset: 4
157 # sh-indent-comment: t
158 # indent-tabs-mode: nil
159 # End:
160 # ex: ts=4 sw=4 et filetype=sh
This page took 0.031936 seconds and 4 git commands to generate.