Port bash completion from ZEC 4d6498b900

This commit is contained in:
Jonathan "Duke" Leto
2018-03-24 08:32:25 -07:00
parent 076452eeaa
commit 87020d117a
3 changed files with 42 additions and 37 deletions

View File

@@ -1,10 +1,10 @@
# bash programmable completion for bitcoin-cli(1) # bash programmable completion for komodo-cli(1)
# Copyright (c) 2012-2016 The Bitcoin Core developers # Copyright (c) 2012-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
# call $bitcoin-cli for RPC # call $komodo-cli for RPC
_zcash_rpc() { _komodo_rpc() {
# determine already specified args necessary for RPC # determine already specified args necessary for RPC
local rpcargs=() local rpcargs=()
for i in ${COMP_LINE}; do for i in ${COMP_LINE}; do
@@ -14,25 +14,25 @@ _zcash_rpc() {
;; ;;
esac esac
done done
$bitcoin_cli "${rpcargs[@]}" "$@" $komodo_cli "${rpcargs[@]}" "$@"
} }
# Add wallet accounts to COMPREPLY # Add wallet accounts to COMPREPLY
_zcash_accounts() { _komodo_accounts() {
local accounts local accounts
# Accounts are deprecated in Zcash # Accounts are deprecated in komodo
#accounts=$(_zcash_rpc listaccounts | awk -F '"' '{ print $2 }') #accounts=$(_komodo_rpc listaccounts | awk -F '"' '{ print $2 }')
accounts="\\\"\\\"" accounts="\\\"\\\""
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) ) COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
} }
_zcash_cli() { _komodo_cli() {
local cur prev words=() cword local cur prev words=() cword
local bitcoin_cli local komodo_cli
# save and use original argument to invoke bitcoin-cli for -help, help and RPC # save and use original argument to invoke komodo-cli for -help, help and RPC
# as bitcoin-cli might not be in $PATH # as komodo-cli might not be in $PATH
bitcoin_cli="$1" komodo_cli="$1"
COMPREPLY=() COMPREPLY=()
_get_comp_words_by_ref -n = cur prev words cword _get_comp_words_by_ref -n = cur prev words cword
@@ -62,7 +62,7 @@ _zcash_cli() {
if ((cword > 3)); then if ((cword > 3)); then
case ${words[cword-3]} in case ${words[cword-3]} in
addmultisigaddress) addmultisigaddress)
_zcash_accounts _komodo_accounts
return 0 return 0
;; ;;
getbalance|gettxout|importaddress|importpubkey|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock) getbalance|gettxout|importaddress|importpubkey|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
@@ -82,12 +82,17 @@ _zcash_cli() {
COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) ) COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) )
return 0 return 0
;; ;;
fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction|z_importkey) fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) ) COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
return 0 return 0
;; ;;
# KMD does not have viewing keys, yet
# z_importkey|z_importviewingkey)
# COMPREPLY=( $( compgen -W "yes no whenkeyisnew" -- "$cur" ) )
# return 0
# ;;
move|setaccount) move|setaccount)
_zcash_accounts _komodo_accounts
return 0 return 0
;; ;;
esac esac
@@ -103,7 +108,7 @@ _zcash_cli() {
return 0 return 0
;; ;;
getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany) getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
_zcash_accounts _komodo_accounts
return 0 return 0
;; ;;
esac esac
@@ -127,12 +132,12 @@ _zcash_cli() {
# only parse -help if senseful # only parse -help if senseful
if [[ -z "$cur" || "$cur" =~ ^- ]]; then if [[ -z "$cur" || "$cur" =~ ^- ]]; then
helpopts=$($bitcoin_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' ) helpopts=$($komodo_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
fi fi
# only parse help if senseful # only parse help if senseful
if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
commands=$(_zcash_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }') commands=$(_komodo_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
fi fi
COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
@@ -145,7 +150,7 @@ _zcash_cli() {
;; ;;
esac esac
} && } &&
complete -F _zcash_cli zcash-cli complete -F _komodo_cli komodo-cli
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@@ -1,15 +1,15 @@
# bash programmable completion for bitcoin-tx(1) # bash programmable completion for komodo-tx(1)
# Copyright (c) 2016 The Bitcoin Core developers # Copyright (c) 2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
_bitcoin_tx() { _komodo_tx() {
local cur prev words=() cword local cur prev words=() cword
local bitcoin_tx local komodo_tx
# save and use original argument to invoke bitcoin-tx for -help # save and use original argument to invoke komodo-tx for -help
# it might not be in $PATH # it might not be in $PATH
bitcoin_tx="$1" komodo_tx="$1"
COMPREPLY=() COMPREPLY=()
_get_comp_words_by_ref -n =: cur prev words cword _get_comp_words_by_ref -n =: cur prev words cword
@@ -27,15 +27,15 @@ _bitcoin_tx() {
if [[ "$cword" == 1 || ( "$prev" != "-create" && "$prev" == -* ) ]]; then if [[ "$cword" == 1 || ( "$prev" != "-create" && "$prev" == -* ) ]]; then
# only options (or an uncompletable hex-string) allowed # only options (or an uncompletable hex-string) allowed
# parse bitcoin-tx -help for options # parse komodo-tx -help for options
local helpopts local helpopts
helpopts=$($bitcoin_tx -help | sed -e '/^ -/ p' -e d ) helpopts=$($komodo_tx -help | sed -e '/^ -/ p' -e d )
COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) )
else else
# only commands are allowed # only commands are allowed
# parse -help for commands # parse -help for commands
local helpcmds local helpcmds
helpcmds=$($bitcoin_tx -help | sed -e '1,/Commands:/d' -e 's/=.*/=/' -e '/^ [a-z]/ p' -e d ) helpcmds=$($komodo_tx -help | sed -e '1,/Commands:/d' -e 's/=.*/=/' -e '/^ [a-z]/ p' -e d )
COMPREPLY=( $( compgen -W "$helpcmds" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$helpcmds" -- "$cur" ) )
fi fi
@@ -46,7 +46,7 @@ _bitcoin_tx() {
return 0 return 0
} && } &&
complete -F _bitcoin_tx zcash-tx complete -F _komodo_tx komodo-tx
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@@ -1,16 +1,16 @@
# bash programmable completion for zcashd(1) # bash programmable completion for komodod(1)
# Copyright (c) 2012-2017 The Bitcoin Core developers # Copyright (c) 2012-2017 The Bitcoin Core developers
# Copyright (c) 2016-2017 The Zcash developers # Copyright (c) 2016-2017 The komodo developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
_zcashd() { _komodod() {
local cur prev words=() cword local cur prev words=() cword
local bitcoind local komodod
# save and use original argument to invoke zcashd for -help # save and use original argument to invoke komodod for -help
# it might not be in $PATH # it might not be in $PATH
bitcoind="$1" komodod="$1"
COMPREPLY=() COMPREPLY=()
_get_comp_words_by_ref -n = cur prev words cword _get_comp_words_by_ref -n = cur prev words cword
@@ -21,7 +21,7 @@ _zcashd() {
_filedir _filedir
return 0 return 0
;; ;;
-datadir=*) -datadir=*|-exportdir=*)
cur="${cur#*=}" cur="${cur#*=}"
_filedir -d _filedir -d
return 0 return 0
@@ -34,7 +34,7 @@ _zcashd() {
# only parse -help if senseful # only parse -help if senseful
if [[ -z "$cur" || "$cur" =~ ^- ]]; then if [[ -z "$cur" || "$cur" =~ ^- ]]; then
local helpopts local helpopts
helpopts=$($bitcoind -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' ) helpopts=$($komodod -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) )
fi fi
@@ -46,7 +46,7 @@ _zcashd() {
;; ;;
esac esac
} && } &&
complete -F _zcashd zcashd complete -F _komodod komodod
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script