2015-03-18 17:26:21 +04:00
|
|
|
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
## Fonctions pour l'autocomplétion bash, si le package bash-completion n'est pas
|
|
|
|
## installé. ATTENTION! Ces fonctions ont été pour la plupart récupérées de
|
|
|
|
## l'implémentation sous Debian Wheezy, ce qui signifie qu'elles sont conçues
|
|
|
|
## pour fonctionner avec bash 4.1
|
|
|
|
##@cooked nocomments
|
|
|
|
##@require base
|
|
|
|
uprovide bash_completion
|
|
|
|
|
2015-03-23 05:08:27 +04:00
|
|
|
function __bash_completion_enabled() {
|
2015-03-18 17:54:45 +04:00
|
|
|
[ -n "$__NUTOOLS_BASH_COMPLETION" ] && return 0
|
2015-03-18 17:26:21 +04:00
|
|
|
grep -qE '^[ \t]*(\.|source)[ \t]*/usr/share/bash-completion/bash_completion' /etc/bash.bashrc && return 0
|
|
|
|
grep -qE '^[ \t]*(\.|source)[ \t]*/usr/share/bash-completion/bash_completion' ~/.bashrc && return 0
|
|
|
|
return 1
|
|
|
|
}
|
2015-03-23 05:08:27 +04:00
|
|
|
function __bash_completion_module_enabled() {
|
2015-03-23 05:20:27 +04:00
|
|
|
if [ -f "/usr/share/bash-completion/completions/$1" ]; then
|
|
|
|
local var="__NUTOOLS_BASH_COMPLETION_${1//-/_}"
|
|
|
|
if [ -z "${!var}" ]; then
|
|
|
|
# nous ne supportons pas le chargement à la demande: charger le
|
|
|
|
# module de suite
|
|
|
|
source "/usr/share/bash-completion/completions/$1"
|
|
|
|
eval "$var=1"
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
fi
|
2015-03-18 17:54:45 +04:00
|
|
|
[ -n "$BASH_COMPLETION_COMPAT_DIR" -a -f "$BASH_COMPLETION_COMPAT_DIR/$1" ] && return 0
|
|
|
|
return 1
|
2015-03-18 17:26:21 +04:00
|
|
|
}
|
|
|
|
|
2015-03-23 05:08:27 +04:00
|
|
|
if ! __bash_completion_enabled; then
|
|
|
|
__NUTOOLS_BASH_COMPLETION=1
|
2015-03-18 17:26:21 +04:00
|
|
|
fi
|
2015-03-23 05:08:27 +04:00
|
|
|
[ -n "$BASH_COMPLETION" ] || BASH_COMPLETION=1
|