Improve COutPoint less operator
[bitcoinplatinum.git] / contrib / bitcoind.bash-completion
blob1338d2f2b5c3b5dc48a36f93c5afbac330b9a065
1 # bash programmable completion for bitcoind(1) and bitcoin-cli(1)
2 # Copyright (c) 2012,2014 Christian von Roques <roques@mti.ag>
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 have bitcoind && {
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[@]}" "$@"
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" ) )
29 _bitcoind() {
30     local cur prev words=() cword
31     local bitcoind
33     # save and use original argument to invoke bitcoind
34     # bitcoind might not be in $PATH
35     bitcoind="$1"
37     COMPREPLY=()
38     _get_comp_words_by_ref -n = cur prev words cword
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
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
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
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
98     case "$cur" in
99         -conf=*|-pid=*|-loadblock=*|-wallet=*)
100             cur="${cur#*=}"
101             _filedir
102             return 0
103             ;;
104         -datadir=*)
105             cur="${cur#*=}"
106             _filedir -d
107             return 0
108             ;;
109         -*=*)   # prevent nonsense completions
110             return 0
111             ;;
112         *)
113             local helpopts commands
115             # only parse --help if senseful
116             if [[ -z "$cur" || "$cur" =~ ^- ]]; then
117                 helpopts=$($bitcoind --help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
118             fi
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
125             COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
127             # Prevent space if an argument is desired
128             if [[ $COMPREPLY == *= ]]; then
129                 compopt -o nospace
130             fi
131             return 0
132             ;;
133     esac
136 complete -F _bitcoind bitcoind bitcoin-cli
139 # Local variables:
140 # mode: shell-script
141 # sh-basic-offset: 4
142 # sh-indent-comment: t
143 # indent-tabs-mode: nil
144 # End:
145 # ex: ts=4 sw=4 et filetype=sh