Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

bitcoind.bash-completion 4.0KB

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