bitcoind.bash raw

   1  # bash programmable completion for bitcoind(1) and bitcoin-qt(1)
   2  # Copyright (c) 2012-present The Bitcoin Core developers
   3  # Distributed under the MIT software license, see the accompanying
   4  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
   5  
   6  _bitcoind() {
   7      local cur prev words=() cword
   8      local bitcoind
   9  
  10      # save and use original argument to invoke bitcoind for -help
  11      # it might not be in $PATH
  12      bitcoind="$1"
  13  
  14      COMPREPLY=()
  15      _get_comp_words_by_ref -n = cur prev words cword
  16  
  17      case "$cur" in
  18          -conf=*|-pid=*|-loadblock=*|-rpccookiefile=*|-wallet=*)
  19              cur="${cur#*=}"
  20              _filedir
  21              return 0
  22              ;;
  23          -datadir=*)
  24              cur="${cur#*=}"
  25              _filedir -d
  26              return 0
  27              ;;
  28          -*=*)	# prevent nonsense completions
  29              return 0
  30              ;;
  31          *)
  32  
  33              # only parse -help if sensible
  34              if [[ -z "$cur" || "$cur" =~ ^- ]]; then
  35                  local helpopts
  36                  helpopts=$($bitcoind -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
  37                  COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) )
  38              fi
  39  
  40              # Prevent space if an argument is desired
  41              if [[ $COMPREPLY == *= ]]; then
  42                  compopt -o nospace
  43              fi
  44              return 0
  45              ;;
  46      esac
  47  } &&
  48  complete -F _bitcoind bitcoind bitcoin-qt
  49  
  50  # Local variables:
  51  # mode: shell-script
  52  # sh-basic-offset: 4
  53  # sh-indent-comment: t
  54  # indent-tabs-mode: nil
  55  # End:
  56  # ex: ts=4 sw=4 et filetype=sh
  57