]> Git Repo - VerusCoin.git/blob - contrib/zcash-cli.bash-completion
Auto merge of #2786 - str4d:2074-build, 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|z_importkey)
86                 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
87                 return 0
88                 ;;
89             move|setaccount)
90                 _zcash_accounts
91                 return 0
92                 ;;
93         esac
94     fi
95
96     case "$prev" in
97         backupwallet|dumpwallet|importwallet|z_exportwallet|z_importwallet)
98             _filedir
99             return 0
100             ;;
101         getaddednodeinfo|getrawmempool|lockunspent|setgenerate)
102             COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
103             return 0
104             ;;
105         getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
106             _zcash_accounts
107             return 0
108             ;;
109     esac
110
111     case "$cur" in
112         -conf=*)
113             cur="${cur#*=}"
114             _filedir
115             return 0
116             ;;
117         -datadir=*)
118             cur="${cur#*=}"
119             _filedir -d
120             return 0
121             ;;
122         -*=*)   # prevent nonsense completions
123             return 0
124             ;;
125         *)
126             local helpopts commands
127
128             # only parse -help if senseful
129             if [[ -z "$cur" || "$cur" =~ ^- ]]; then
130                 helpopts=$($zcash_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
131             fi
132
133             # only parse help if senseful
134             if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
135                 commands=$(_zcash_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
136             fi
137
138             COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
139
140             # Prevent space if an argument is desired
141             if [[ $COMPREPLY == *= ]]; then
142                 compopt -o nospace
143             fi
144             return 0
145             ;;
146     esac
147 } &&
148 complete -F _zcash_cli zcash-cli
149
150 # Local variables:
151 # mode: shell-script
152 # sh-basic-offset: 4
153 # sh-indent-comment: t
154 # indent-tabs-mode: nil
155 # End:
156 # ex: ts=4 sw=4 et filetype=sh
This page took 0.03252 seconds and 4 git commands to generate.