2014-03-04 17:24:59 +01:00
|
|
|
# bash programmable completion for bitcoind(1) and bitcoin-cli(1)
|
|
|
|
# Copyright (c) 2012,2014 Christian von Roques <roques@mti.ag>
|
2012-05-23 20:26:45 +02:00
|
|
|
# Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
have bitcoind && {
|
|
|
|
|
|
|
|
# call $bitcoind for RPC
|
|
|
|
_bitcoin_rpc() {
|
|
|
|
# determine already specified args necessary for RPC
|
|
|
|
local rpcargs=()
|
|
|
|
for i in ${COMP_LINE}; do
|
|
|
|
case "$i" in
|
|
|
|
-conf=*|-proxy*|-rpc*)
|
|
|
|
rpcargs=( "${rpcargs[@]}" "$i" )
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
$bitcoind "${rpcargs[@]}" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add bitcoin accounts to COMPREPLY
|
|
|
|
_bitcoin_accounts() {
|
|
|
|
local accounts
|
|
|
|
accounts=$(_bitcoin_rpc listaccounts | awk '/".*"/ { a=$1; gsub(/"/, "", a); print a}')
|
|
|
|
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
|
|
|
|
}
|
|
|
|
|
|
|
|
_bitcoind() {
|
|
|
|
local cur prev words=() cword
|
|
|
|
local bitcoind
|
|
|
|
|
|
|
|
# save and use original argument to invoke bitcoind
|
|
|
|
# bitcoind might not be in $PATH
|
|
|
|
bitcoind="$1"
|
|
|
|
|
|
|
|
COMPREPLY=()
|
|
|
|
_get_comp_words_by_ref -n = cur prev words cword
|
|
|
|
|
2014-03-04 17:24:59 +01:00
|
|
|
if ((cword > 4)); then
|
|
|
|
case ${words[cword-4]} in
|
|
|
|
signrawtransaction)
|
|
|
|
COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ((cword > 3)); then
|
|
|
|
case ${words[cword-3]} in
|
|
|
|
addmultisigaddress)
|
|
|
|
_bitcoin_accounts
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
gettxout|importprivkey)
|
|
|
|
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2012-05-23 20:26:45 +02:00
|
|
|
if ((cword > 2)); then
|
|
|
|
case ${words[cword-2]} in
|
2014-03-04 17:24:59 +01:00
|
|
|
addnode)
|
|
|
|
COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
getblock|getrawtransaction|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
|
2012-05-23 20:26:45 +02:00
|
|
|
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
move|setaccount)
|
|
|
|
_bitcoin_accounts
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$prev" in
|
2014-03-04 17:24:59 +01:00
|
|
|
backupwallet|dumpwallet|importwallet)
|
2012-05-23 20:26:45 +02:00
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
2014-03-04 17:24:59 +01:00
|
|
|
getmempool|lockunspent|setgenerate)
|
2012-05-23 20:26:45 +02:00
|
|
|
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
|
|
|
|
_bitcoin_accounts
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "$cur" in
|
2014-03-04 17:24:59 +01:00
|
|
|
-conf=*|-pid=*|-loadblock=*|-wallet=*|-rpcsslcertificatechainfile=*|-rpcsslprivatekeyfile=*)
|
2012-05-23 20:26:45 +02:00
|
|
|
cur="${cur#*=}"
|
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-datadir=*)
|
|
|
|
cur="${cur#*=}"
|
|
|
|
_filedir -d
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-*=*) # prevent nonsense completions
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
local helpopts commands
|
|
|
|
|
|
|
|
# only parse --help if senseful
|
|
|
|
if [[ -z "$cur" || "$cur" =~ ^- ]]; then
|
|
|
|
helpopts=$($bitcoind --help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
|
|
|
|
fi
|
|
|
|
|
|
|
|
# only parse help if senseful
|
|
|
|
if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
|
|
|
|
commands=$(_bitcoin_rpc help 2>/dev/null | awk '{ print $1; }')
|
|
|
|
fi
|
|
|
|
|
|
|
|
COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
|
|
|
|
|
|
|
|
# Prevent space if an argument is desired
|
|
|
|
if [[ $COMPREPLY == *= ]]; then
|
|
|
|
compopt -o nospace
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2014-03-04 17:24:59 +01:00
|
|
|
complete -F _bitcoind bitcoind bitcoin-cli
|
2012-05-23 20:26:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
|
|
|
# sh-basic-offset: 4
|
|
|
|
# sh-indent-comment: t
|
|
|
|
# indent-tabs-mode: nil
|
|
|
|
# End:
|
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|