]> git.proxmox.com Git - mirror_lxc.git/commitdiff
Add bash auto completion
authorStéphane Graber <stgraber@ubuntu.com>
Tue, 21 Jan 2014 04:49:19 +0000 (23:49 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 22 Jan 2014 17:23:08 +0000 (12:23 -0500)
This adds a basic bash auto-completion profile.

It supports 3 things at this time:
 - Auto-complete of container name (-n or -o)
 - Auto-complete of template name (-t)
 - Auto-complete of state names (-s)

It's configured in a way to be as little disruptive as possible, any
argument that's not explicitly handled by the profile will fallack to
bash's default completion.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
config/Makefile.am
config/bash/Makefile.am [new file with mode: 0644]
config/bash/lxc.in [new file with mode: 0644]
configure.ac

index f9ce6fb86c51ce2454cf990fafcd000a59d60bf9..9515965715a56f1da8c92f6c817cc84b878ceb76 100644 (file)
@@ -1 +1 @@
-SUBDIRS = apparmor etc init templates
+SUBDIRS = apparmor bash etc init templates
diff --git a/config/bash/Makefile.am b/config/bash/Makefile.am
new file mode 100644 (file)
index 0000000..b1768c9
--- /dev/null
@@ -0,0 +1,14 @@
+EXTRA_DIST = lxc
+
+if ENABLE_BASH
+install-bash:
+       $(MKDIR_P) $(DESTDIR)$(sysconfdir)/bash_completion.d/
+       $(INSTALL_DATA) lxc $(DESTDIR)$(sysconfdir)/bash_completion.d/
+
+uninstall-bash:
+       rm -f $(DESTDIR)$(sysconfdir)/bash_completion.d/lxc
+       rmdir $(DESTDIR)$(sysconfdir)/bash_completion.d/ || :
+
+install-data-local: install-bash
+uninstall-local: uninstall-bash
+endif
diff --git a/config/bash/lxc.in b/config/bash/lxc.in
new file mode 100644 (file)
index 0000000..c1c9041
--- /dev/null
@@ -0,0 +1,105 @@
+#!bash
+
+have lxc-start && {
+    _lxc_names() {
+        COMPREPLY=( $( compgen -W "$( lxc-ls )" "$cur" ) )
+    }
+
+    _lxc_states() {
+        COMPREPLY=( $( compgen -W "STOPPED STARTING RUNNING STOPPING ABORTING FREEZING FROZEN THAWED" "$cur" ) )
+    }
+
+    _lxc_templates() {
+        COMPREPLY=( $( compgen -W "$(ls @LXCTEMPLATEDIR@/ | sed -e 's|^lxc-||' )" "$cur" ) )
+    }
+
+    _lxc-generic-n() {
+        local cur prev
+
+        COMPREPLY=()
+        _get_comp_words_by_ref cur prev
+
+        case $prev in
+            -n)
+                _lxc_names "$cur"
+                return 0
+            ;;
+        esac
+
+        return 1
+    }
+
+    _lxc-generic-ns() {
+        local cur prev
+
+        COMPREPLY=()
+        _get_comp_words_by_ref cur prev
+
+        case $prev in
+            -n)
+                _lxc_names "$cur"
+                return 0
+            ;;
+
+            -s)
+                _lxc_states "$cur"
+                return 0
+            ;;
+        esac
+
+        return 1
+    }
+
+    _lxc-generic-t() {
+        local cur prev
+
+        COMPREPLY=()
+        _get_comp_words_by_ref cur prev
+
+        case $prev in
+            -t)
+                _lxc_templates "$cur"
+                return 0
+            ;;
+        esac
+
+        return 1
+    }
+
+    _lxc-generic-o() {
+        local cur prev
+
+        COMPREPLY=()
+        _get_comp_words_by_ref cur prev
+
+        case $prev in
+            -o)
+                _lxc_names "$cur"
+                return 0
+            ;;
+        esac
+
+        return 1
+    }
+
+    complete -o default -F _lxc-generic-n lxc-attach
+    complete -o default -F _lxc-generic-n lxc-cgroup
+    complete -o default -F _lxc-generic-n lxc-console
+    complete -o default -F _lxc-generic-n lxc-destroy
+    complete -o default -F _lxc-generic-n lxc-device
+    complete -o default -F _lxc-generic-n lxc-execute
+    complete -o default -F _lxc-generic-n lxc-freeze
+    complete -o default -F _lxc-generic-n lxc-info
+    complete -o default -F _lxc-generic-n lxc-monitor
+    complete -o default -F _lxc-generic-n lxc-snapshot
+    complete -o default -F _lxc-generic-n lxc-start
+    complete -o default -F _lxc-generic-n lxc-stop
+    complete -o default -F _lxc-generic-n lxc-unfreeze
+
+    complete -o default -F _lxc-generic-ns lxc-wait
+
+    complete -o default -F _lxc-generic-t lxc-create
+
+    complete -o default -F _lxc-generic-o lxc-clone
+    complete -o default -F _lxc-generic-o lxc-start-ephemeral
+}
index e2b7e79db84e9b54440142139d700cca911c17ab..fd3803816a7d74b61b86716c747c2cb907f08e86 100644 (file)
@@ -385,6 +385,12 @@ AM_COND_IF([ENABLE_LUA],
                [LUA_INSTALL_LMOD=$datadir/lua/$LUA_VERSION])
        ])
 
+# Optional bash integration
+AC_ARG_ENABLE([bash],
+       [AC_HELP_STRING([--enable-bash], [build bash integration [default=yes]])],
+       [], [enable_bash=yes])
+AM_CONDITIONAL([ENABLE_BASH], [test "x$enable_bash" = "xyes"])
+
 # Optional test binaries
 AC_ARG_ENABLE([tests],
        [AC_HELP_STRING([--enable-tests], [build test/example binaries [default=no]])],
@@ -548,6 +554,8 @@ AC_CONFIG_FILES([
 
        config/Makefile
        config/apparmor/Makefile
+       config/bash/Makefile
+       config/bash/lxc
        config/init/Makefile
        config/init/sysvinit/Makefile
        config/init/systemd/Makefile
@@ -705,6 +713,7 @@ Environment:
  - init script type(s): $init_script
  - rpath: $enable_rpath
  - GnuTLS: $enable_gnutls
+ - Bash integration: $enable_bash
 
 Security features:
  - Apparmor: $enable_apparmor