Skip to content

Commit 26316ff

Browse files
committed
Merge #8289: bash-completion: Adapt for 0.12 and 0.13
1ba3db6 bash-completion: Adapt for 0.12 and 0.13 (Christian von Roques)
2 parents 67caef6 + 1ba3db6 commit 26316ff

File tree

5 files changed

+224
-100
lines changed

5 files changed

+224
-100
lines changed

contrib/bitcoin-cli.bash-completion

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# bash programmable completion for bitcoin-cli(1)
2+
# Copyright (c) 2012-2016 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
# call $bitcoin-cli for RPC
7+
_bitcoin_rpc() {
8+
# determine already specified args necessary for RPC
9+
local rpcargs=()
10+
for i in ${COMP_LINE}; do
11+
case "$i" in
12+
-conf=*|-datadir=*|-regtest|-rpc*|-testnet)
13+
rpcargs=( "${rpcargs[@]}" "$i" )
14+
;;
15+
esac
16+
done
17+
$bitcoin_cli "${rpcargs[@]}" "$@"
18+
}
19+
20+
# Add wallet accounts to COMPREPLY
21+
_bitcoin_accounts() {
22+
local accounts
23+
accounts=$(_bitcoin_rpc listaccounts | awk -F '"' '{ print $2 }')
24+
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
25+
}
26+
27+
_bitcoin_cli() {
28+
local cur prev words=() cword
29+
local bitcoin_cli
30+
31+
# save and use original argument to invoke bitcoin-cli for -help, help and RPC
32+
# as bitcoin-cli might not be in $PATH
33+
bitcoin_cli="$1"
34+
35+
COMPREPLY=()
36+
_get_comp_words_by_ref -n = cur prev words cword
37+
38+
if ((cword > 5)); then
39+
case ${words[cword-5]} in
40+
sendtoaddress)
41+
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
42+
return 0
43+
;;
44+
esac
45+
fi
46+
47+
if ((cword > 4)); then
48+
case ${words[cword-4]} in
49+
importaddress|listtransactions|setban)
50+
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
51+
return 0
52+
;;
53+
signrawtransaction)
54+
COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
55+
return 0
56+
;;
57+
esac
58+
fi
59+
60+
if ((cword > 3)); then
61+
case ${words[cword-3]} in
62+
addmultisigaddress)
63+
_bitcoin_accounts
64+
return 0
65+
;;
66+
getbalance|gettxout|importaddress|importpubkey|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
67+
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
68+
return 0
69+
;;
70+
esac
71+
fi
72+
73+
if ((cword > 2)); then
74+
case ${words[cword-2]} in
75+
addnode)
76+
COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
77+
return 0
78+
;;
79+
setban)
80+
COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) )
81+
return 0
82+
;;
83+
fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
84+
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
85+
return 0
86+
;;
87+
move|setaccount)
88+
_bitcoin_accounts
89+
return 0
90+
;;
91+
esac
92+
fi
93+
94+
case "$prev" in
95+
backupwallet|dumpwallet|importwallet)
96+
_filedir
97+
return 0
98+
;;
99+
getaddednodeinfo|getrawmempool|lockunspent|setgenerate)
100+
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
101+
return 0
102+
;;
103+
getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
104+
_bitcoin_accounts
105+
return 0
106+
;;
107+
esac
108+
109+
case "$cur" in
110+
-conf=*)
111+
cur="${cur#*=}"
112+
_filedir
113+
return 0
114+
;;
115+
-datadir=*)
116+
cur="${cur#*=}"
117+
_filedir -d
118+
return 0
119+
;;
120+
-*=*) # prevent nonsense completions
121+
return 0
122+
;;
123+
*)
124+
local helpopts commands
125+
126+
# only parse -help if senseful
127+
if [[ -z "$cur" || "$cur" =~ ^- ]]; then
128+
helpopts=$($bitcoin_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
129+
fi
130+
131+
# only parse help if senseful
132+
if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
133+
commands=$(_bitcoin_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
134+
fi
135+
136+
COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
137+
138+
# Prevent space if an argument is desired
139+
if [[ $COMPREPLY == *= ]]; then
140+
compopt -o nospace
141+
fi
142+
return 0
143+
;;
144+
esac
145+
} &&
146+
complete -F _bitcoin_cli bitcoin-cli
147+
148+
# Local variables:
149+
# mode: shell-script
150+
# sh-basic-offset: 4
151+
# sh-indent-comment: t
152+
# indent-tabs-mode: nil
153+
# End:
154+
# ex: ts=4 sw=4 et filetype=sh

contrib/bitcoin-tx.bash-completion

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# bash programmable completion for bitcoin-tx(1)
2+
# Copyright (c) 2016 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
_bitcoin_tx() {
7+
local cur prev words=() cword
8+
local bitcoin_tx
9+
10+
# save and use original argument to invoke bitcoin-tx for -help
11+
# it might not be in $PATH
12+
bitcoin_tx="$1"
13+
14+
COMPREPLY=()
15+
_get_comp_words_by_ref -n =: cur prev words cword
16+
17+
case "$cur" in
18+
load=*:*)
19+
cur="${cur#load=*:}"
20+
_filedir
21+
return 0
22+
;;
23+
*=*) # prevent attempts to complete other arguments
24+
return 0
25+
;;
26+
esac
27+
28+
if [[ "$cword" == 1 || ( "$prev" != "-create" && "$prev" == -* ) ]]; then
29+
# only options (or an uncompletable hex-string) allowed
30+
# parse bitcoin-tx -help for options
31+
local helpopts
32+
helpopts=$($bitcoin_tx -help | sed -e '/^ -/ p' -e d )
33+
COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) )
34+
else
35+
# only commands are allowed
36+
# parse -help for commands
37+
local helpcmds
38+
helpcmds=$($bitcoin_tx -help | sed -e '1,/Commands:/d' -e 's/=.*/=/' -e '/^ [a-z]/ p' -e d )
39+
COMPREPLY=( $( compgen -W "$helpcmds" -- "$cur" ) )
40+
fi
41+
42+
# Prevent space if an argument is desired
43+
if [[ $COMPREPLY == *= ]]; then
44+
compopt -o nospace
45+
fi
46+
47+
return 0
48+
} &&
49+
complete -F _bitcoin_tx bitcoin-tx
50+
51+
# Local variables:
52+
# mode: shell-script
53+
# sh-basic-offset: 4
54+
# sh-indent-comment: t
55+
# indent-tabs-mode: nil
56+
# End:
57+
# ex: ts=4 sw=4 et filetype=sh

contrib/bitcoind.bash-completion

Lines changed: 11 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,21 @@
1-
# bash programmable completion for bitcoind(1) and bitcoin-cli(1)
2-
# Copyright (c) 2012,2014 Christian von Roques <[email protected]>
1+
# bash programmable completion for bitcoind(1) and bitcoin-qt(1)
2+
# Copyright (c) 2012-2016 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6-
have bitcoind && {
7-
8-
# call $bitcoind for RPC
9-
_bitcoin_rpc() {
10-
# determine already specified args necessary for RPC
11-
local rpcargs=()
12-
for i in ${COMP_LINE}; do
13-
case "$i" in
14-
-conf=*|-proxy*|-rpc*)
15-
rpcargs=( "${rpcargs[@]}" "$i" )
16-
;;
17-
esac
18-
done
19-
$bitcoind "${rpcargs[@]}" "$@"
20-
}
21-
22-
# Add bitcoin accounts to COMPREPLY
23-
_bitcoin_accounts() {
24-
local accounts
25-
accounts=$(_bitcoin_rpc listaccounts | awk '/".*"/ { a=$1; gsub(/"/, "", a); print a}')
26-
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
27-
}
28-
296
_bitcoind() {
307
local cur prev words=() cword
318
local bitcoind
329

33-
# save and use original argument to invoke bitcoind
34-
# bitcoind might not be in $PATH
10+
# save and use original argument to invoke bitcoind for -help
11+
# it might not be in $PATH
3512
bitcoind="$1"
3613

3714
COMPREPLY=()
3815
_get_comp_words_by_ref -n = cur prev words cword
3916

40-
if ((cword > 4)); then
41-
case ${words[cword-4]} in
42-
listtransactions)
43-
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
44-
return 0
45-
;;
46-
signrawtransaction)
47-
COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
48-
return 0
49-
;;
50-
esac
51-
fi
52-
53-
if ((cword > 3)); then
54-
case ${words[cword-3]} in
55-
addmultisigaddress)
56-
_bitcoin_accounts
57-
return 0
58-
;;
59-
getbalance|gettxout|importaddress|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
60-
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
61-
return 0
62-
;;
63-
esac
64-
fi
65-
66-
if ((cword > 2)); then
67-
case ${words[cword-2]} in
68-
addnode)
69-
COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
70-
return 0
71-
;;
72-
getblock|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
73-
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
74-
return 0
75-
;;
76-
move|setaccount)
77-
_bitcoin_accounts
78-
return 0
79-
;;
80-
esac
81-
fi
82-
83-
case "$prev" in
84-
backupwallet|dumpwallet|importwallet)
85-
_filedir
86-
return 0
87-
;;
88-
getmempool|lockunspent|setgenerate)
89-
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
90-
return 0
91-
;;
92-
getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
93-
_bitcoin_accounts
94-
return 0
95-
;;
96-
esac
97-
9817
case "$cur" in
99-
-conf=*|-pid=*|-loadblock=*|-wallet=*)
18+
-conf=*|-pid=*|-loadblock=*|-rootcertificates=*|-rpccookiefile=*|-wallet=*)
10019
cur="${cur#*=}"
10120
_filedir
10221
return 0
@@ -110,31 +29,23 @@ _bitcoind() {
11029
return 0
11130
;;
11231
*)
113-
local helpopts commands
11432

115-
# only parse --help if senseful
33+
# only parse -help if senseful
11634
if [[ -z "$cur" || "$cur" =~ ^- ]]; then
117-
helpopts=$($bitcoind --help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
35+
local helpopts
36+
helpopts=$($bitcoind -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
37+
COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) )
11838
fi
11939

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; }')
123-
fi
124-
125-
COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
126-
12740
# Prevent space if an argument is desired
12841
if [[ $COMPREPLY == *= ]]; then
12942
compopt -o nospace
13043
fi
13144
return 0
13245
;;
13346
esac
134-
}
135-
136-
complete -F _bitcoind bitcoind bitcoin-cli
137-
}
47+
} &&
48+
complete -F _bitcoind bitcoind bitcoin-qt
13849

13950
# Local variables:
14051
# mode: shell-script
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
contrib/bitcoin-tx.bash-completion bitcoin-tx
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
contrib/bitcoind.bash-completion bitcoind
2+
contrib/bitcoin-cli.bash-completion bitcoin-cli

0 commit comments

Comments
 (0)