~ubuntu-branches/debian/stretch/bitcoin/stretch

« back to all changes in this revision

Viewing changes to contrib/bitcoin-cli.bash-completion

  • Committer: Package Import Robot
  • Author(s): Anthony Towns
  • Date: 2016-10-21 17:13:13 UTC
  • mfrom: (1.3.2)
  • Revision ID: package-import@ubuntu.com-20161021171313-7eu2ltpbk0xag3q1
Tags: 0.13.0-0.1
* Non-maintainer upload.
* New upstream release.
* Allow compilation with gcc/g++ 6. (Closes: Bug#835963)
* Additional fixes for openssl 1.1 compatibility. (See Bug#828248)
* Check if -latomic is needed (it is on mips*).
* Remove reproducible build patch, since leveldb build system is
  no longer used in 0.13. (See Bug#791834)
* Update description since the blockchain is much more than "several GB"
  now. (Closes: Bug#835809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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