You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

starwels-cli.bash-completion 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # bash programmable completion for starwels-cli(1)
  2. # Copyright (c) 2012-2016 The Starwels developers
  3. # Distributed under the MIT software license, see the accompanying
  4. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. # call $starwels-cli for RPC
  6. _starwels_rpc() {
  7. # determine already specified args necessary for RPC
  8. local rpcargs=()
  9. for i in ${COMP_LINE}; do
  10. case "$i" in
  11. -conf=*|-datadir=*|-regtest|-rpc*|-ai)
  12. rpcargs=( "${rpcargs[@]}" "$i" )
  13. ;;
  14. esac
  15. done
  16. $starwels_cli "${rpcargs[@]}" "$@"
  17. }
  18. # Add wallet accounts to COMPREPLY
  19. _starwels_accounts() {
  20. local accounts
  21. accounts=$(_starwels_rpc listaccounts | awk -F '"' '{ print $2 }')
  22. COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
  23. }
  24. _starwels_cli() {
  25. local cur prev words=() cword
  26. local starwels_cli
  27. # save and use original argument to invoke starwels-cli for -help, help and RPC
  28. # as starwels-cli might not be in $PATH
  29. starwels_cli="$1"
  30. COMPREPLY=()
  31. _get_comp_words_by_ref -n = cur prev words cword
  32. if ((cword > 5)); then
  33. case ${words[cword-5]} in
  34. sendtoaddress)
  35. COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
  36. return 0
  37. ;;
  38. esac
  39. fi
  40. if ((cword > 4)); then
  41. case ${words[cword-4]} in
  42. importaddress|listtransactions|setban)
  43. COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
  44. return 0
  45. ;;
  46. signrawtransaction)
  47. COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
  48. return 0
  49. ;;
  50. esac
  51. fi
  52. if ((cword > 3)); then
  53. case ${words[cword-3]} in
  54. addmultisigaddress)
  55. _starwels_accounts
  56. return 0
  57. ;;
  58. getbalance|gettxout|importaddress|importpubkey|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
  59. COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
  60. return 0
  61. ;;
  62. esac
  63. fi
  64. if ((cword > 2)); then
  65. case ${words[cword-2]} in
  66. addnode)
  67. COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
  68. return 0
  69. ;;
  70. setban)
  71. COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) )
  72. return 0
  73. ;;
  74. fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
  75. COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
  76. return 0
  77. ;;
  78. move|setaccount)
  79. _starwels_accounts
  80. return 0
  81. ;;
  82. esac
  83. fi
  84. case "$prev" in
  85. backupwallet|dumpwallet|importwallet)
  86. _filedir
  87. return 0
  88. ;;
  89. getaddednodeinfo|getrawmempool|lockunspent|setgenerate)
  90. COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
  91. return 0
  92. ;;
  93. getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
  94. _starwels_accounts
  95. return 0
  96. ;;
  97. esac
  98. case "$cur" in
  99. -conf=*)
  100. cur="${cur#*=}"
  101. _filedir
  102. return 0
  103. ;;
  104. -datadir=*)
  105. cur="${cur#*=}"
  106. _filedir -d
  107. return 0
  108. ;;
  109. -*=*) # prevent nonsense completions
  110. return 0
  111. ;;
  112. *)
  113. local helpopts commands
  114. # only parse -help if senseful
  115. if [[ -z "$cur" || "$cur" =~ ^- ]]; then
  116. helpopts=$($starwels_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
  117. fi
  118. # only parse help if senseful
  119. if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
  120. commands=$(_starwels_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
  121. fi
  122. COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
  123. # Prevent space if an argument is desired
  124. if [[ $COMPREPLY == *= ]]; then
  125. compopt -o nospace
  126. fi
  127. return 0
  128. ;;
  129. esac
  130. } &&
  131. complete -F _starwels_cli starwels-cli
  132. # Local variables:
  133. # mode: shell-script
  134. # sh-basic-offset: 4
  135. # sh-indent-comment: t
  136. # indent-tabs-mode: nil
  137. # End:
  138. # ex: ts=4 sw=4 et filetype=sh