aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-05-25 09:07:16 -0700
committerGavin Andresen <gavinandresen@gmail.com>2012-05-25 09:07:16 -0700
commit325e5c3ef0459bbf5f1629cbbdb8cda0659f98b2 (patch)
tree6bceaf98434c4f46a82cfd210576fa1b66b794de
parent787f5e9949a0e2de32121008271b0e3f103a64c6 (diff)
parentdbd9c486bb02c567668c8f3952f37c1917d8bcca (diff)
downloadbitcoin-325e5c3ef0459bbf5f1629cbbdb8cda0659f98b2.tar.xz
Merge pull request #1366 from roques/completion
Bash completion for bitcoind(1)
-rw-r--r--contrib/bitcoind.bash-completion115
-rw-r--r--contrib/debian/bitcoind.bash-completion1
-rw-r--r--contrib/debian/control1
-rwxr-xr-xcontrib/debian/rules2
4 files changed, 118 insertions, 1 deletions
diff --git a/contrib/bitcoind.bash-completion b/contrib/bitcoind.bash-completion
new file mode 100644
index 0000000000..dd6c1ce819
--- /dev/null
+++ b/contrib/bitcoind.bash-completion
@@ -0,0 +1,115 @@
+# bash programmable completion for bitcoind(1)
+# Copyright (c) 2012 Christian von Roques <roques@mti.ag>
+# Distributed under the MIT/X11 software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+have bitcoind && {
+
+# call $bitcoind for RPC
+_bitcoin_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
+ $bitcoind "${rpcargs[@]}" "$@"
+}
+
+# Add bitcoin accounts to COMPREPLY
+_bitcoin_accounts() {
+ local accounts
+ accounts=$(_bitcoin_rpc listaccounts | awk '/".*"/ { a=$1; gsub(/"/, "", a); print a}')
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
+}
+
+_bitcoind() {
+ local cur prev words=() cword
+ local bitcoind
+
+ # save and use original argument to invoke bitcoind
+ # bitcoind might not be in $PATH
+ bitcoind="$1"
+
+ COMPREPLY=()
+ _get_comp_words_by_ref -n = cur prev words cword
+
+ if ((cword > 2)); then
+ case ${words[cword-2]} in
+ listreceivedbyaccount|listreceivedbyaddress)
+ COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
+ return 0
+ ;;
+ move|setaccount)
+ _bitcoin_accounts
+ return 0
+ ;;
+ esac
+ fi
+
+ case "$prev" in
+ backupwallet)
+ _filedir
+ return 0
+ ;;
+ setgenerate)
+ COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
+ return 0
+ ;;
+ getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
+ _bitcoin_accounts
+ return 0
+ ;;
+ esac
+
+ case "$cur" in
+ -conf=*|-pid=*|-rpcsslcertificatechainfile=*|-rpcsslprivatekeyfile=*)
+ 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=$($bitcoind --help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
+ fi
+
+ # only parse help if senseful
+ if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
+ commands=$(_bitcoin_rpc help 2>/dev/null | awk '{ 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 _bitcoind bitcoind
+}
+
+# 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
diff --git a/contrib/debian/bitcoind.bash-completion b/contrib/debian/bitcoind.bash-completion
new file mode 100644
index 0000000000..0f84707b66
--- /dev/null
+++ b/contrib/debian/bitcoind.bash-completion
@@ -0,0 +1 @@
+contrib/bitcoind.bash-completion bitcoind
diff --git a/contrib/debian/control b/contrib/debian/control
index 745fd71ea8..de067d8fc4 100644
--- a/contrib/debian/control
+++ b/contrib/debian/control
@@ -5,6 +5,7 @@ Maintainer: Jonas Smedegaard <dr@jones.dk>
Uploaders: Micah Anderson <micah@debian.org>
Build-Depends: debhelper,
devscripts,
+ bash-completion,
libboost-system-dev (>> 1.35) | libboost-system1.35-dev,
libdb4.8++-dev,
libssl-dev,
diff --git a/contrib/debian/rules b/contrib/debian/rules
index 49c7766d13..98bb2bba1c 100755
--- a/contrib/debian/rules
+++ b/contrib/debian/rules
@@ -9,7 +9,7 @@ DEB_INSTALL_EXAMPLES_bitcoind += debian/examples/*
DEB_INSTALL_MANPAGES_bitcoind += debian/manpages/*
%:
- dh $@
+ dh --with bash-completion $@
override_dh_auto_build:
cd src; $(MAKE) -f makefile.unix bitcoind