neobytes/contrib/neobytesd.bash-completion

146 lines
4.2 KiB
Plaintext
Raw Normal View History

2024-02-05 23:00:22 +01:00
# bash programmable completion for neobytesd(1) and neobytes-cli(1)
# Copyright (c) 2012,2014 Christian von Roques <roques@mti.ag>
2014-12-13 05:09:33 +01:00
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
2024-02-05 23:00:22 +01:00
have neobytesd && {
2024-02-05 23:00:22 +01:00
# call $neobytesd for RPC
_neobytes_rpc() {
# determine already specified args necessary for RPC
local rpcargs=()
for i in ${COMP_LINE}; do
case "$i" in
-conf=*|-proxy*|-rpc*)
rpcargs=( "${rpcargs[@]}" "$i" )
;;
esac
done
2024-02-05 23:00:22 +01:00
$neobytesd "${rpcargs[@]}" "$@"
}
2024-02-05 23:00:22 +01:00
# Add neobytes accounts to COMPREPLY
_neobytes_accounts() {
local accounts
2024-02-05 23:00:22 +01:00
accounts=$(_neobytes_rpc listaccounts | awk '/".*"/ { a=$1; gsub(/"/, "", a); print a}')
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
}
2024-02-05 23:00:22 +01:00
_neobytesd() {
local cur prev words=() cword
2024-02-05 23:00:22 +01:00
local neobytesd
2024-02-05 23:00:22 +01:00
# save and use original argument to invoke neobytesd
# neobytesd might not be in $PATH
neobytesd="$1"
COMPREPLY=()
_get_comp_words_by_ref -n = cur prev words cword
if ((cword > 4)); then
case ${words[cword-4]} in
listtransactions)
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
return 0
;;
signrawtransaction)
COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
return 0
;;
esac
fi
if ((cword > 3)); then
case ${words[cword-3]} in
addmultisigaddress)
2024-02-05 23:00:22 +01:00
_neobytes_accounts
return 0
;;
getbalance|gettxout|importaddress|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
return 0
;;
esac
fi
if ((cword > 2)); then
case ${words[cword-2]} in
addnode)
COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
return 0
;;
getblock|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
return 0
;;
move|setaccount)
2024-02-05 23:00:22 +01:00
_neobytes_accounts
return 0
;;
esac
fi
case "$prev" in
backupwallet|dumpwallet|importwallet)
_filedir
return 0
;;
getmempool|lockunspent|setgenerate)
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
return 0
;;
getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
2024-02-05 23:00:22 +01:00
_neobytes_accounts
return 0
;;
esac
case "$cur" in
2015-01-23 07:53:50 +01:00
-conf=*|-pid=*|-loadblock=*|-wallet=*)
cur="${cur#*=}"
_filedir
return 0
;;
-datadir=*)
cur="${cur#*=}"
_filedir -d
return 0
;;
-*=*) # prevent nonsense completions
return 0
;;
*)
local helpopts commands
# only parse --help if senseful
if [[ -z "$cur" || "$cur" =~ ^- ]]; then
2024-02-05 23:00:22 +01:00
helpopts=$($neobytesd --help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
fi
# only parse help if senseful
if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
2024-02-05 23:00:22 +01:00
commands=$(_neobytes_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
fi
COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
# Prevent space if an argument is desired
if [[ $COMPREPLY == *= ]]; then
compopt -o nospace
fi
return 0
;;
esac
}
2024-02-05 23:00:22 +01:00
complete -F _neobytesd neobytesd neobytes-cli
}
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh