Skip to contentSkip to conversation

Add BASH completion for various tools

PATCH New Wido den Hollander 1 participant 4 messages Jun 28, 2011

lore
Share & tools
lore
#0 lore raw

cover Add BASH completion for various tools

Hi,

BASH completion is very useful when working with the common Ceph tools on a regular basis.

It also makes it easier for new users to quickly find out some "hidden" commands the "ceph" tool has.

I made a start with the BASH completion for the most used tools, ceph, rados, radosgw_admin and rbd.

They are not complete yet, they'll have to take shape over time.

I've been playing with complementing pool names to the -p argument of the rados and rbd tool, but this causes "rados lspools" to be ran in the background. I'm not sure yet what kind of performance impact this could have when you have a large amount of pools.

Let me know what you guys think of it.

Wido

#1 lore raw

PATCH 1/3 bash_completion: Add bash completion for ceph, rados, radosgw_admin and rbd

---
 src/bash_completion/ceph          |   60 +++++++++++++++++++++++++++++++++++++
 src/bash_completion/rados         |   40 ++++++++++++++++++++++++
 src/bash_completion/radosgw_admin |   57 +++++++++++++++++++++++++++++++++++
 src/bash_completion/rbd           |   44 +++++++++++++++++++++++++++
 4 files changed, 201 insertions(+), 0 deletions(-)
 create mode 100644 src/bash_completion/ceph
 create mode 100644 src/bash_completion/rados
 create mode 100644 src/bash_completion/radosgw_admin
 create mode 100644 src/bash_completion/rbd
src/bash_completion/ceph new file +60 -0
new file mode 100644
index 0000000..f7ec55b
@@ -0,0 +1,60 @@
+#
+# Ceph - scalable distributed file system
+#
+# Copyright (C) 2011 Wido den Hollander <[email protected]>
+#
+# This is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software
+# Foundation.  See file COPYING.
+#
+
+_ceph()
+{
+        local cur prev
+
+        COMPREPLY=()
+        cur="${COMP_WORDS[COMP_CWORD]}"
+        prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+        if [[ ${cur} == -* ]] ; then
+            COMPREPLY=( $(compgen -W "--conf -c --name --id -m --version -s --status -w --watch -o --out-file -i --in-file" -- ${cur}) )
+            return 0
+        fi
+
+        case "${prev}" in
+            -o | --out-file | -i | --in-file | --conf | -c)
+                COMPREPLY=( $(compgen -f ${cur}) )
+                return 0
+                ;;
+            -m)
+                COMPREPLY=( $(compgen -A hostname ${cur}) )
+                return 0
+                ;;
+            auth)
+                COMPREPLY=( $(compgen -W "list add del" -- ${cur}) )
+                return 0
+                ;;
+            pg)
+                COMPREPLY=( $(compgen -W "stat dump getmap map send_pg_creates scrub repair" -- ${cur}) )
+                return 0
+                ;;
+            osd)
+                COMPREPLY=( $(compgen -W "tell stat injectargs pool dump getmaxosd tree getmap getcrushmap lspools" -- ${cur}) )
+                return 0
+                ;;
+            mon)
+                COMPREPLY=( $(compgen -W "tell stat injectargs getmap" -- ${cur}) )
+                return 0
+                ;;
+            mds)
+                COMPREPLY=( $(compgen -W "tell stat injectargs stat getmap dump compat" -- ${cur}) )
+                return 0
+                ;;
+            *)
+                COMPREPLY=( $(compgen -W "osd mon mds pg auth" -- ${cur}) )
+                return 0
+            ;;
+        esac
+}
+complete -F _ceph ceph
src/bash_completion/rados new file +40 -0
new file mode 100644
index 0000000..aa277c3
@@ -0,0 +1,40 @@
+#
+# Ceph - scalable distributed file system
+#
+# Copyright (C) 2011 Wido den Hollander <[email protected]>
+#
+# This is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software
+# Foundation.  See file COPYING.
+#
+
+_rados()
+{
+        local cur prev
+
+        COMPREPLY=()
+        cur="${COMP_WORDS[COMP_CWORD]}"
+        prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+        if [[ ${cur} == -* ]] ; then
+            COMPREPLY=( $(compgen -W "-c --conf -m -d -f -p --pool -b --snap -i -o --create" -- ${cur}) )
+            return 0
+        fi
+
+        case "${prev}" in
+            --conf | -c | -o | -i)
+                COMPREPLY=( $(compgen -f ${cur}) )
+                return 0
+                ;;
+            -m)
+                COMPREPLY=( $(compgen -A hostname ${cur}) )
+                return 0
+                ;;
+            *)
+                COMPREPLY=( $(compgen -W "lspools mkpool rmpool df ls chown get put create rm listxattr getxattr setxattr rmxattr stat mapext lssnap mksnap rmsnap rollback bench" -- ${cur}) )
+                return 0
+            ;;
+        esac
+}
+complete -F _rados rados
src/bash_completion/radosgw_admin new file +57 -0

57 lines not on this page · raw message

src/bash_completion/rbd new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 2/3 bash_completion: Add the bash_completion files to the Debian packages

In reply to Wido den Hollander
---
 debian/ceph-client-tools.install |    2 ++
 debian/ceph.install              |    1 +
 debian/radosgw.install           |    1 +
 3 files changed, 4 insertions(+), 0 deletions(-)
debian/ceph-client-tools.install +2 -0
index 205eb7c..d9b3edd 100644
@@ -6,3 +6,5 @@ usr/share/man/man8/csyn.8
 usr/share/man/man8/rados.8
 usr/share/man/man8/rbd.8
 usr/share/man/man8/mount.ceph.8
+etc/bash_completion.d/rados
+etc/bash_completion.d/rbd
debian/ceph.install +1 -0
index b1160db..53de14f 100644
@@ -30,3 +30,4 @@ usr/share/man/man8/cephfs.8
 usr/share/man/man8/cauthtool.8
 usr/share/man/man8/cclsinfo.8
 usr/share/man/man8/cdebugpack.8
+etc/bash_completion.d/ceph
debian/radosgw.install +1 -0
index 0a69f45..d968edd 100644
@@ -2,3 +2,4 @@ usr/bin/radosgw
 usr/bin/radosgw_admin
 usr/share/man/man8/radosgw.8
 usr/share/man/man8/radosgw_admin.8
+etc/bash_completion.d/radosgw_admin
Signature · 1 line
1.7.0.4
#3 lore raw

PATCH 3/3 bash_completion: Add to the Makefile

In reply to Wido den Hollander
---
 src/Makefile.am |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
src/Makefile.am +11 -1
index cffd09b..38bbf0e 100644
@@ -558,6 +558,12 @@ sample.fetch_config: fetch_config
 shell_commondir = $(libdir)/ceph
 shell_common_SCRIPTS = ceph_common.sh
 
+bash_completiondir = /etc/bash_completion.d
+bash_completion_DATA = $(srcdir)/bash_completion/ceph \
+		$(srcdir)/bash_completion/rados \
+		$(srcdir)/bash_completion/rbd \
+		$(srcdir)/bash_completion/radosgw_admin
+
 libceph_includedir = $(includedir)/ceph
 libceph_include_DATA = $(srcdir)/include/ceph/libceph.h
 
@@ -1149,7 +1155,11 @@ noinst_HEADERS = \
 	tools/gui_resources.h\
 	test/osd/RadosModel.h\
 	global/pidfile.h\
-	common/sync_filesystem.h
+	common/sync_filesystem.h\
+	bash_completion/ceph\
+	bash_completion/rados\
+	bash_completion/rbd\
+	bash_completion/radosgw_admin
 
 all_sources = $(cmon_SOURCES) $(ceph_SOURCES) $(cephfs_SOURCES) $(librados_config_SOURCES) $(cauthtool_SOURCES) $(monmaptool_SOURCES) \
 	$(crushtool_SOURCES) $(osdmaptool_SOURCES) $(cconf_SOURCES) $(mount_ceph_SOURCES) $(cmds_SOURCES) \
Signature · 1 line
1.7.0.4