mirror_lxc/config/bash/lxc.in
Lucas Werkmeister e0bc106769
Use POSIX-compliant function names in bash completion
When running in posix mode (for example, because it was invoked as `sh`,
or with the --posix option), bash rejects the function names previously
used because they contain hyphens, which are not legal POSIX names, and
exits immediately.

This is a particularly serious problem on a system in which the
following three conditions hold:

1. The `sh` executable is provided by bash, e. g. via a symlink
2. Gnome Display Manager is used to launch X sessions
3. Bash completion is loaded in the (system or user) profile file
   instead of in the bashrc file

In that case, GDM's Xsession script (run with `sh`, i. e., bash in posix
mode) sources the profile files, thus causing the shell to load the bash
completion files. Upon encountering the non-POSIX-compliant function
names, bash would then exit, immediately ending the X session.

Fixes #521.

Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
2015-05-14 22:39:06 +02:00

104 lines
2.4 KiB
Plaintext

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
}