Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# bash programmable completion for bitcoin-cli(1)2# Copyright (c) 2012-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.6# call $bitcoin-cli for RPC7_bitcoin_rpc() {8# determine already specified args necessary for RPC9local rpcargs=()10for i in ${COMP_LINE}; do11case "$i" in12-conf=*|-datadir=*|-regtest|-rpc*|-testnet|-testnet4)13rpcargs=( "${rpcargs[@]}" "$i" )14;;15esac16done17$bitcoin_cli "${rpcargs[@]}" "$@"18}20_bitcoin_cli() {21local cur prev words=() cword22local bitcoin_cli24# save and use original argument to invoke bitcoin-cli for -help, help and RPC25# as bitcoin-cli might not be in $PATH26bitcoin_cli="$1"28COMPREPLY=()29_get_comp_words_by_ref -n = cur prev words cword31if ((cword > 5)); then32case ${words[cword-5]} in33sendtoaddress)34COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )35return 036;;37esac38fi40if ((cword > 4)); then41case ${words[cword-4]} in42listtransactions|setban)43COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )44return 045;;46signrawtransactionwithkey|signrawtransactionwithwallet)47COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )48return 049;;50esac51fi53if ((cword > 3)); then54case ${words[cword-3]} in55getbalance|gettxout|listreceivedbyaddress|listsinceblock)56COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )57return 058;;59esac60fi62if ((cword > 2)); then63case ${words[cword-2]} in64addnode)65COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )66return 067;;68setban)69COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) )70return 071;;72fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listreceivedbyaddress|sendrawtransaction)73COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )74return 075;;76esac77fi79case "$prev" in80backupwallet)81_filedir82return 083;;84getaddednodeinfo|getrawmempool|lockunspent)85COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )86return 087;;88getbalance|getnewaddress|listtransactions|sendmany)89return 090;;91esac93case "$cur" in94-conf=*)95cur="${cur#*=}"96_filedir97return 098;;99-datadir=*)100cur="${cur#*=}"101_filedir -d102return 0103;;104-*=*) # prevent nonsense completions105return 0106;;107*)108local helpopts commands110# only parse -help if senseful111if [[ -z "$cur" || "$cur" =~ ^- ]]; then112helpopts=$($bitcoin_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )113fi115# only parse help if senseful116if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then117commands=$(_bitcoin_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')118fi120COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )122# Prevent space if an argument is desired123if [[ $COMPREPLY == *= ]]; then124compopt -o nospace125fi126return 0127;;128esac129} &&130complete -F _bitcoin_cli bitcoin-cli132# Local variables:133# mode: shell-script134# sh-basic-offset: 4135# sh-indent-comment: t136# indent-tabs-mode: nil137# End:138# ex: ts=4 sw=4 et filetype=sh
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.