[Lunar-commits] <moonbase> rabbitmq-server: Adding rabbitmqctl bash completion

Stefan Wold ratler at lunar-linux.org
Mon Sep 20 09:30:31 CEST 2010


commit c84998979dff8d8a97c67eef560c25af89c14ec8
Author: Stefan Wold <ratler at lunar-linux.org>
Date:   Mon Sep 20 09:30:31 2010 +0200

    rabbitmq-server: Adding rabbitmqctl bash completion
---
 .../profile.d/rabbitmq-server-completion.rc        |   41 ++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/net/rabbitmq-server/profile.d/rabbitmq-server-completion.rc b/net/rabbitmq-server/profile.d/rabbitmq-server-completion.rc
new file mode 100644
index 0000000..12daa52
--- /dev/null
+++ b/net/rabbitmq-server/profile.d/rabbitmq-server-completion.rc
@@ -0,0 +1,41 @@
+#
+# RabbitMQ Server Completion
+#
+# Author: Stefan Wold <ratler at lunar-linux.org>
+#
+
+# Turn on extended globbing
+shopt -s extglob
+
+__rabbitmqctl_list_all_commands () {
+  while read line; do
+    echo $line
+  done < <(rabbitmqctl | awk '/^[[:space:]]+[a-z]+/{ print $1}')
+  
+}
+
+__rabbitmqctl_all_commands=
+__rabbitmqctl_compute_all_commands () {
+  : ${__rabbitmqctl_all_commands:=$(__rabbitmqctl_list_all_commands)}
+}
+
+
+# rabbitmqctl(1) completion
+_rabbitmqctl () {
+  local current previous
+
+  __rabbitmqctl_compute_all_commands
+
+  COMPREPLY=()
+  current=${COMP_WORDS[COMP_CWORD]}
+  previous=${COMP_WORDS[COMP_CWORD-1]}
+
+  if [ $COMP_CWORD -eq 1 ] || [ "${previous:0:1}" = "-" ]; then
+    COMPREPLY=($(compgen -W "${__rabbitmqctl_all_commands}" $current))
+  else
+    COMPREPLY=($(compgen -f $current))
+  fi
+  return 0
+}
+
+complete -F _rabbitmqctl rabbitmqctl


More information about the Lunar-commits mailing list