diff options
Diffstat (limited to 'pcr/bash-dynamic-completion')
-rw-r--r-- | pcr/bash-dynamic-completion/PKGBUILD | 17 | ||||
-rw-r--r-- | pcr/bash-dynamic-completion/dynamic_completion.install | 8 | ||||
-rw-r--r-- | pcr/bash-dynamic-completion/dynamic_completion.sh | 60 |
3 files changed, 85 insertions, 0 deletions
diff --git a/pcr/bash-dynamic-completion/PKGBUILD b/pcr/bash-dynamic-completion/PKGBUILD new file mode 100644 index 000000000..e2878f04c --- /dev/null +++ b/pcr/bash-dynamic-completion/PKGBUILD @@ -0,0 +1,17 @@ +pkgname='bash-dynamic-completion' +pkgver=1 +pkgrel=1 +pkgdesc="A simple script that automatically load any of those completion functions when it is requested for the first time" +arch=( 'i686' 'x86_64' ) +url="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467231" +license=( 'GPL' ) +depends=( 'bash' 'bash-completion' 'cron' ) +source=( 'dynamic_completion.sh' ) +md5sums=( 'b3659f84162ebda9e0444273b2d0bd8a' ) +install=dynamic_completion.install + +build() { + mkdir ${pkgdir}/etc + mkdir ${pkgdir}/etc/cron.monthly + cp ${srcdir}/dynamic_completion.sh ${pkgdir}/etc/cron.monthly/ +} diff --git a/pcr/bash-dynamic-completion/dynamic_completion.install b/pcr/bash-dynamic-completion/dynamic_completion.install new file mode 100644 index 000000000..bd2fb0c5b --- /dev/null +++ b/pcr/bash-dynamic-completion/dynamic_completion.install @@ -0,0 +1,8 @@ +post_install() { + chmod 744 /etc/cron.monthly/dynamic_completion.sh + echo "Executing /etc/cron.monthly/dynamic_completion.sh" + /etc/cron.monthly/dynamic_completion.sh + + echo "Please insert this line into /etc/bash.bashrc instead of calling /etc/bash_completion" + . /etc/bash_dyncompletion +} diff --git a/pcr/bash-dynamic-completion/dynamic_completion.sh b/pcr/bash-dynamic-completion/dynamic_completion.sh new file mode 100644 index 000000000..bde058af4 --- /dev/null +++ b/pcr/bash-dynamic-completion/dynamic_completion.sh @@ -0,0 +1,60 @@ +#! /bin/sh + +# This script automatically moves the completion +# functions from /etc/bash_completion and /etc/bash_completion.d +# to a separate directory and creates a drop-in replacement for +# /etc/bash_completion - which will load any of those completion +# functions when it is requested for the first time. By this, we +# greatly reduce the loading time (the replacement script is ~30kb) +# and also the memory footprint (as we rarely need every completion +# function in every bash session). +# +# The generator script is intended to be run once the base script +# /etc/bash_completion is installed and then, every time something +# is added to /etc/bash_completion.d. I'd like to propose it for +# the bash package -- maybe as an optional part of installation. +# +# Taken from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467231 +# Author: Andrei Paskevich +# andrei@capet.iut-fbleau.fr + +BASH_COMPLETION=/etc/bash_completion +BASH_DYNCOMPLETION=/etc/bash_dyncompletion +BASH_DYNCOMPLETION_DIR=/etc/bash_dyncompletion.d + +echo "Read static completions from $BASH_COMPLETION" +. "$BASH_COMPLETION" || exit 1 + +echo "Create dynamic completion file $BASH_DYNCOMPLETION" +touch "$BASH_DYNCOMPLETION" || exit 1 + +echo "Create dynamic completion directory $BASH_DYNCOMPLETION_DIR" +mkdir -p "$BASH_DYNCOMPLETION_DIR" || exit 1 + +echo -n "Populate dynamic completion directory:" +FUNCS=$(declare -f | grep '^[a-zA-Z_][a-zA-Z0-9_]* () $' | cut -f 1 -d ' ') +for FN in $FUNCS ; do + echo -n " $FN" + declare -f $FN > "$BASH_DYNCOMPLETION_DIR/$FN" + eval "$FN () { . '$BASH_DYNCOMPLETION_DIR/$FN' ; $FN \"\$@\" ; }" +done +echo + +echo "Write dynamic completion file $BASH_DYNCOMPLETION" +exec > "$BASH_DYNCOMPLETION" +cat <<EOF +# $(basename $BASH_DYNCOMPLETION) - load-by-need bash completions +# actual completion functions are stored in $BASH_DYNCOMPLETION_DIR +# this file and directory are generated from $BASH_COMPLETION + +shopt -s extglob progcomp +EOF + +declare -p BASH_COMPLETION 2>/dev/null +declare -p bash205 2>/dev/null +declare -p bash205b 2>/dev/null +declare -p bash3 2>/dev/null +declare -f +complete -p + +exit 0 |