]>
Commit | Line | Data |
---|---|---|
c794f6d3 CR |
1 | # bash programmable completion for bitcoin-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 $bitcoin-cli for RPC | |
58966e96 | 7 | _zcash_rpc() { |
c794f6d3 CR |
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 | $bitcoin_cli "${rpcargs[@]}" "$@" | |
18 | } | |
19 | ||
20 | # Add wallet accounts to COMPREPLY | |
58966e96 | 21 | _zcash_accounts() { |
c794f6d3 | 22 | local accounts |
a01daac7 JG |
23 | # Accounts are deprecated in Zcash |
24 | #accounts=$(_zcash_rpc listaccounts | awk -F '"' '{ print $2 }') | |
25 | accounts="\\\"\\\"" | |
c794f6d3 CR |
26 | COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) ) |
27 | } | |
28 | ||
58966e96 | 29 | _zcash_cli() { |
c794f6d3 CR |
30 | local cur prev words=() cword |
31 | local bitcoin_cli | |
32 | ||
33 | # save and use original argument to invoke bitcoin-cli for -help, help and RPC | |
34 | # as bitcoin-cli might not be in $PATH | |
35 | bitcoin_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) | |
58966e96 | 65 | _zcash_accounts |
c794f6d3 CR |
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 | ;; | |
73546e1b | 85 | fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction|z_importkey) |
c794f6d3 CR |
86 | COMPREPLY=( $( compgen -W "true false" -- "$cur" ) ) |
87 | return 0 | |
88 | ;; | |
89 | move|setaccount) | |
58966e96 | 90 | _zcash_accounts |
c794f6d3 CR |
91 | return 0 |
92 | ;; | |
93 | esac | |
94 | fi | |
95 | ||
96 | case "$prev" in | |
73546e1b | 97 | backupwallet|dumpwallet|importwallet|z_exportwallet|z_importwallet) |
c794f6d3 CR |
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) | |
58966e96 | 106 | _zcash_accounts |
c794f6d3 CR |
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=$($bitcoin_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 | |
58966e96 | 135 | commands=$(_zcash_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }') |
c794f6d3 CR |
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 | } && | |
58966e96 | 148 | complete -F _zcash_cli zcash-cli |
c794f6d3 CR |
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 |