]>
Commit | Line | Data |
---|---|---|
87020d11 | 1 | # bash programmable completion for komodo-cli(1) |
c794f6d3 CR |
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 | ||
87020d11 JDL |
6 | # call $komodo-cli for RPC |
7 | _komodo_rpc() { | |
c794f6d3 CR |
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 | |
87020d11 | 17 | $komodo_cli "${rpcargs[@]}" "$@" |
c794f6d3 CR |
18 | } |
19 | ||
20 | # Add wallet accounts to COMPREPLY | |
87020d11 | 21 | _komodo_accounts() { |
c794f6d3 | 22 | local accounts |
87020d11 JDL |
23 | # Accounts are deprecated in komodo |
24 | #accounts=$(_komodo_rpc listaccounts | awk -F '"' '{ print $2 }') | |
a01daac7 | 25 | accounts="\\\"\\\"" |
c794f6d3 CR |
26 | COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) ) |
27 | } | |
28 | ||
87020d11 | 29 | _komodo_cli() { |
c794f6d3 | 30 | local cur prev words=() cword |
87020d11 | 31 | local komodo_cli |
c794f6d3 | 32 | |
87020d11 JDL |
33 | # save and use original argument to invoke komodo-cli for -help, help and RPC |
34 | # as komodo-cli might not be in $PATH | |
35 | komodo_cli="$1" | |
c794f6d3 CR |
36 | |
37 | COMPREPLY=() | |
38 | _get_comp_words_by_ref -n = cur prev words cword | |
39 | ||
40 | if ((cword > 5)); then | |
41 | case ${words[cword-5]} in | |
42 | sendtoaddress) | |
43 | COMPREPLY=( $( compgen -W "true false" -- "$cur" ) ) | |
44 | return 0 | |
45 | ;; | |
46 | esac | |
47 | fi | |
48 | ||
49 | if ((cword > 4)); then | |
50 | case ${words[cword-4]} in | |
51 | importaddress|listtransactions|setban) | |
52 | COMPREPLY=( $( compgen -W "true false" -- "$cur" ) ) | |
53 | return 0 | |
54 | ;; | |
55 | signrawtransaction) | |
56 | COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) ) | |
57 | return 0 | |
58 | ;; | |
59 | esac | |
60 | fi | |
61 | ||
62 | if ((cword > 3)); then | |
63 | case ${words[cword-3]} in | |
64 | addmultisigaddress) | |
87020d11 | 65 | _komodo_accounts |
c794f6d3 CR |
66 | return 0 |
67 | ;; | |
68 | getbalance|gettxout|importaddress|importpubkey|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock) | |
69 | COMPREPLY=( $( compgen -W "true false" -- "$cur" ) ) | |
70 | return 0 | |
71 | ;; | |
72 | esac | |
73 | fi | |
74 | ||
75 | if ((cword > 2)); then | |
76 | case ${words[cword-2]} in | |
77 | addnode) | |
78 | COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) ) | |
79 | return 0 | |
80 | ;; | |
81 | setban) | |
82 | COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) ) | |
83 | return 0 | |
84 | ;; | |
87020d11 | 85 | fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction) |
c794f6d3 CR |
86 | COMPREPLY=( $( compgen -W "true false" -- "$cur" ) ) |
87 | return 0 | |
88 | ;; | |
f08e247d JDL |
89 | z_importkey|z_importviewingkey) |
90 | COMPREPLY=( $( compgen -W "yes no whenkeyisnew" -- "$cur" ) ) | |
91 | return 0 | |
92 | ;; | |
c794f6d3 | 93 | move|setaccount) |
87020d11 | 94 | _komodo_accounts |
c794f6d3 CR |
95 | return 0 |
96 | ;; | |
97 | esac | |
98 | fi | |
99 | ||
100 | case "$prev" in | |
73546e1b | 101 | backupwallet|dumpwallet|importwallet|z_exportwallet|z_importwallet) |
c794f6d3 CR |
102 | _filedir |
103 | return 0 | |
104 | ;; | |
105 | getaddednodeinfo|getrawmempool|lockunspent|setgenerate) | |
106 | COMPREPLY=( $( compgen -W "true false" -- "$cur" ) ) | |
107 | return 0 | |
108 | ;; | |
109 | getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany) | |
87020d11 | 110 | _komodo_accounts |
c794f6d3 CR |
111 | return 0 |
112 | ;; | |
113 | esac | |
114 | ||
115 | case "$cur" in | |
116 | -conf=*) | |
117 | cur="${cur#*=}" | |
118 | _filedir | |
119 | return 0 | |
120 | ;; | |
121 | -datadir=*) | |
122 | cur="${cur#*=}" | |
123 | _filedir -d | |
124 | return 0 | |
125 | ;; | |
126 | -*=*) # prevent nonsense completions | |
127 | return 0 | |
128 | ;; | |
129 | *) | |
130 | local helpopts commands | |
131 | ||
132 | # only parse -help if senseful | |
133 | if [[ -z "$cur" || "$cur" =~ ^- ]]; then | |
87020d11 | 134 | helpopts=$($komodo_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' ) |
c794f6d3 CR |
135 | fi |
136 | ||
137 | # only parse help if senseful | |
138 | if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then | |
87020d11 | 139 | commands=$(_komodo_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }') |
c794f6d3 CR |
140 | fi |
141 | ||
142 | COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) ) | |
143 | ||
144 | # Prevent space if an argument is desired | |
145 | if [[ $COMPREPLY == *= ]]; then | |
146 | compopt -o nospace | |
147 | fi | |
148 | return 0 | |
149 | ;; | |
150 | esac | |
151 | } && | |
87020d11 | 152 | complete -F _komodo_cli komodo-cli |
c794f6d3 CR |
153 | |
154 | # Local variables: | |
155 | # mode: shell-script | |
156 | # sh-basic-offset: 4 | |
157 | # sh-indent-comment: t | |
158 | # indent-tabs-mode: nil | |
159 | # End: | |
160 | # ex: ts=4 sw=4 et filetype=sh |