Package: bash
Version: 3.1dfsg-9
Severity: wishlist

The default /etc/bash_completion in Debian/sid takes 216kb, and 
a couple of scripts in /etc/bash_completion.d add another 100kb.
To load this, my system needs half a second, a perceivable and
quite annoying delay on every shell start. 

I wrote a simple script, that 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.

The generator script is attached, any comments are welcome.

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)

Kernel: Linux 2.6.24-1-686 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages bash depends on:
ii  base-files                4.0.2          Debian base system miscellaneous f
ii  debianutils               2.28.3         Miscellaneous utilities specific t
ii  libc6                     2.7-8          GNU C Library: Shared libraries
ii  libncurses5               5.6+20080203-1 Shared libraries for terminal hand

Versions of packages bash recommends:
pn  bash-completion               <none>     (no description available)

-- no debconf information
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 \"[EMAIL PROTECTED]" ; 
}"
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

Reply via email to