1 # bash programmable completion for bitcoind(1) and bitcoin-cli(1)
2 # Copyright (c) 2012,2014 Christian von Roques <roques@mti.ag>
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 # call $bitcoind for RPC
10 # determine already specified args necessary for RPC
12 for i in ${COMP_LINE}; do
14 -conf=*|-proxy*|-rpc*)
15 rpcargs=( "${rpcargs[@]}" "$i" )
19 $bitcoind "${rpcargs[@]}" "$@"
22 # Add bitcoin accounts to COMPREPLY
25 accounts=$(_bitcoin_rpc listaccounts | awk '/".*"/ { a=$1; gsub(/"/, "", a); print a}')
26 COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
30 local cur prev words=() cword
33 # save and use original argument to invoke bitcoind
34 # bitcoind might not be in $PATH
38 _get_comp_words_by_ref -n = cur prev words cword
40 if ((cword > 4)); then
41 case ${words[cword-4]} in
43 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
47 COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
53 if ((cword > 3)); then
54 case ${words[cword-3]} in
59 getbalance|gettxout|importaddress|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
60 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
66 if ((cword > 2)); then
67 case ${words[cword-2]} in
69 COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
72 getblock|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
73 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
84 backupwallet|dumpwallet|importwallet)
88 getmempool|lockunspent|setgenerate)
89 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
92 getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
99 -conf=*|-pid=*|-loadblock=*|-wallet=*)
109 -*=*) # prevent nonsense completions
113 local helpopts commands
115 # only parse --help if senseful
116 if [[ -z "$cur" || "$cur" =~ ^- ]]; then
117 helpopts=$($bitcoind --help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
120 # only parse help if senseful
121 if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
122 commands=$(_bitcoin_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
125 COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
127 # Prevent space if an argument is desired
128 if [[ $COMPREPLY == *= ]]; then
136 complete -F _bitcoind bitcoind bitcoin-cli
142 # sh-indent-comment: t
143 # indent-tabs-mode: nil
145 # ex: ts=4 sw=4 et filetype=sh