]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Add a bash_completion script
authorDavid Howells <dhowells@redhat.com>
Fri, 5 May 2023 09:28:15 +0000 (10:28 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 5 May 2023 10:53:26 +0000 (11:53 +0100)
Add a script that can be source by a shell to do bash completion.

Signed-off-by: David Howells <dhowells@redhat.com>
bash_complete [new file with mode: 0644]

diff --git a/bash_complete b/bash_complete
new file mode 100644 (file)
index 0000000..dd01383
--- /dev/null
@@ -0,0 +1,24 @@
+# -*- sh -*-
+# bash completion script for AFS tools
+#
+# To use these routines:
+#
+#    1. Copy this file to somewhere (e.g. ~/.kafs-completion.bash).
+#
+#    2. Add the following line to your .bashrc:
+#         . ~/.kafs-completion.bash
+
+_afs () {
+    COMPREPLY=($(kafs --complete $COMP_CWORD "${COMP_WORDS[@]}"))
+
+    case "${COMPREPLY[0]}" in
+       @HOSTNAME@)
+       COMPREPLY=($(compgen -A hostname -- "${COMP_WORDS[$COMP_CWORD]}"))
+       ;;
+       @VOLNAME@|@PARTID@|@FILE@|@OTHER@)
+       COMPREPLY=($(compgen -A file -- "${COMP_WORDS[$COMP_CWORD]}"))
+       ;;
+    esac
+}
+
+complete -o bashdefault -o default -F _afs afs bos pts vos