From: Stéphane Graber Date: Tue, 21 Jan 2014 04:49:19 +0000 (-0500) Subject: Add bash auto completion X-Git-Tag: lxc-1.0.0.beta3~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0306de4f280adc0cd5faa3cd365c584d61c9e383;p=thirdparty%2Flxc.git Add bash auto completion 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 Acked-by: Serge E. Hallyn --- diff --git a/config/Makefile.am b/config/Makefile.am index f9ce6fb86..951596571 100644 --- a/config/Makefile.am +++ b/config/Makefile.am @@ -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 index 000000000..b1768c9e1 --- /dev/null +++ b/config/bash/Makefile.am @@ -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 index 000000000..c1c9041df --- /dev/null +++ b/config/bash/lxc.in @@ -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 +} diff --git a/configure.ac b/configure.ac index e2b7e79db..fd3803816 100644 --- a/configure.ac +++ b/configure.ac @@ -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