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(1) wrapper2# Copyright (c) 2026-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# wrapper to delegate completion to the real function7_bitcoin_wrap() {8local delegate="$1" shift_count="$2"9local func="_${delegate//-/_}"10local words cword dir file12# load completion script if function not yet defined13if ! declare -F $func >/dev/null; then14dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"15file="$(grep -l -E "complete[[:space:]]+-F[[:space:]]+${func}" "$dir"/* 2>/dev/null | head -n1)"16[ -z "$file" ] && file="$(grep -l -E "^[[:space:]]*${func}[[:space:]]*\(\)" "$dir"/* 2>/dev/null | head -n1)"17[ -n "$file" ] && source "$file" || return 018fi20_get_comp_words_by_ref -n = words cword22COMP_WORDS=( "$delegate" "${words[@]:$shift_count}" )23COMP_CWORD=$(( cword - (shift_count - 1) ))24COMP_LINE="${COMP_WORDS[@]}"25COMP_POINT=${#COMP_LINE}26$func "$delegate"27}29_bitcoin() {30local cur prev words cword31local bitcoin subcmd offset33# save and use original argument to invoke bitcoin for help34# it might not be in $PATH35bitcoin="$1"37COMPREPLY=()38_get_comp_words_by_ref -n = cur prev words cword40case "${words[1]}" in41-m|-M|--multiprocess|--monolithic)42subcmd="${words[2]}"43offset=344;;45*)46subcmd="${words[1]}"47offset=248;;49esac51case "$subcmd" in52gui|node)53_bitcoin_wrap bitcoind "$offset"54return 055;;56rpc)57_bitcoin_wrap bitcoin-cli "$offset"58return 059;;60tx)61_bitcoin_wrap bitcoin-tx "$offset"62return 063;;64esac66case "$cur" in67-*=*) # prevent nonsense completions68return 069;;70*)71local options commands73# only parse help if sensible74if [[ -z "$cur" || "$cur" =~ ^- ]]; then75options=$($bitcoin help 2>&1 | awk '{ for(i=1;i<=NF;i++) if ($i~/^--/) { sub(/=.*/, "=",$i); print $i } }' )76fi77if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then78commands=$($bitcoin help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')79fi81COMPREPLY=( $( compgen -W "$options $commands" -- "$cur" ) )83# Prevent space if an argument is desired84if [[ $COMPREPLY == *= ]]; then85compopt -o nospace86fi87return 088;;89esac91} &&92complete -F _bitcoin bitcoin94# Local variables:95# mode: shell-script96# sh-basic-offset: 497# sh-indent-comment: t98# indent-tabs-mode: nil99# End:100# 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.