1 # bash programmable completion for bitcoind(1)
3 # Distributed under the MIT/X11 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 > 2)); then
41 case ${words[cword-2]} in
42 listreceivedbyaccount|listreceivedbyaddress)
43 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
59 COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
62 getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
69 -conf=*|-pid=*|-rpcsslcertificatechainfile=*|-rpcsslprivatekeyfile=*)
79 -*=*) # prevent nonsense completions
83 local helpopts commands
85 # only parse --help if senseful
86 if [[ -z "$cur" || "$cur" =~ ^- ]]; then
87 helpopts=$($bitcoind --help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
90 # only parse help if senseful
91 if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
92 commands=$(_bitcoin_rpc help 2>/dev/null | awk '{ print $1; }')
95 COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
97 # Prevent space if an argument is desired
98 if [[ $COMPREPLY == *= ]]; then
106 complete -F _bitcoind bitcoind
112 # sh-indent-comment: t
113 # indent-tabs-mode: nil
115 # ex: ts=4 sw=4 et filetype=sh