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.
6 # call $bitcoin-cli for RPC
8 # determine already specified args necessary for RPC
10 for i in ${COMP_LINE}; do
12 -conf=*|-datadir=*|-regtest|-rpc*|-testnet)
13 rpcargs=( "${rpcargs[@]}" "$i" )
17 $bitcoin_cli "${rpcargs[@]}" "$@"
20 # Add wallet accounts to COMPREPLY
23 accounts=$(_bitcoin_rpc listaccounts | awk -F '"' '{ print $2 }')
24 COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
28 local cur prev words=() cword
31 # save and use original argument to invoke bitcoin-cli for -help, help and RPC
32 # as bitcoin-cli might not be in $PATH
36 _get_comp_words_by_ref -n = cur prev words cword
38 if ((cword > 5)); then
39 case ${words[cword-5]} in
41 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
47 if ((cword > 4)); then
48 case ${words[cword-4]} in
49 importaddress|listtransactions|setban)
50 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
54 COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
60 if ((cword > 3)); then
61 case ${words[cword-3]} in
66 getbalance|gettxout|importaddress|importpubkey|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
67 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
73 if ((cword > 2)); then
74 case ${words[cword-2]} in
76 COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
80 COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) )
83 fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
84 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
95 backupwallet|dumpwallet|importwallet)
99 getaddednodeinfo|getrawmempool|lockunspent|setgenerate)
100 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
103 getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
120 -*=*) # prevent nonsense completions
124 local helpopts commands
126 # only parse -help if senseful
127 if [[ -z "$cur" || "$cur" =~ ^- ]]; then
128 helpopts=$($bitcoin_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
131 # only parse help if senseful
132 if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
133 commands=$(_bitcoin_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
136 COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
138 # Prevent space if an argument is desired
139 if [[ $COMPREPLY == *= ]]; then
146 complete -F _bitcoin_cli bitcoin-cli
151 # sh-indent-comment: t
152 # indent-tabs-mode: nil
154 # ex: ts=4 sw=4 et filetype=sh