123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- # bash programmable completion for starwels-cli(1)
- # Copyright (c) 2012-2016 The Starwels developers
- # Distributed under the MIT software license, see the accompanying
- # file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
- # call $starwels-cli for RPC
- _starwels_rpc() {
- # determine already specified args necessary for RPC
- local rpcargs=()
- for i in ${COMP_LINE}; do
- case "$i" in
- -conf=*|-datadir=*|-regtest|-rpc*|-ai)
- rpcargs=( "${rpcargs[@]}" "$i" )
- ;;
- esac
- done
- $starwels_cli "${rpcargs[@]}" "$@"
- }
-
- # Add wallet accounts to COMPREPLY
- _starwels_accounts() {
- local accounts
- accounts=$(_starwels_rpc listaccounts | awk -F '"' '{ print $2 }')
- COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
- }
-
- _starwels_cli() {
- local cur prev words=() cword
- local starwels_cli
-
- # save and use original argument to invoke starwels-cli for -help, help and RPC
- # as starwels-cli might not be in $PATH
- starwels_cli="$1"
-
- COMPREPLY=()
- _get_comp_words_by_ref -n = cur prev words cword
-
- if ((cword > 5)); then
- case ${words[cword-5]} in
- sendtoaddress)
- COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
- return 0
- ;;
- esac
- fi
-
- if ((cword > 4)); then
- case ${words[cword-4]} in
- importaddress|listtransactions|setban)
- 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)
- _starwels_accounts
- return 0
- ;;
- getbalance|gettxout|importaddress|importpubkey|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
- ;;
- setban)
- COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) )
- return 0
- ;;
- fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
- COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
- return 0
- ;;
- move|setaccount)
- _starwels_accounts
- return 0
- ;;
- esac
- fi
-
- case "$prev" in
- backupwallet|dumpwallet|importwallet)
- _filedir
- return 0
- ;;
- getaddednodeinfo|getrawmempool|lockunspent|setgenerate)
- COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
- return 0
- ;;
- getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
- _starwels_accounts
- return 0
- ;;
- esac
-
- case "$cur" in
- -conf=*)
- 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
- helpopts=$($starwels_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
- fi
-
- # only parse help if senseful
- if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
- commands=$(_starwels_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
- } &&
- complete -F _starwels_cli starwels-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
|