[Bash-completion-devel] bash-completion loading enhancements

Raph gibboris at gmail.com
Thu Mar 10 13:48:19 UTC 2011


On Wed, Mar 09, 2011 at 11:14:30PM +0100, dpc at ucore.info wrote:
> If anybody is interested -- I think I've hacked some nice solution for
> this. Seems to be working for me.
> 
> http://ucore.info/en/2011/03/faster-bash-completion-loading/
> https://github.com/dpc/bash_completion

Hi,

your commit (92d83fe2d6f6bd949446) is huge, thus difficult to
understand.


The solution I would like is: "export the bash comp stuff to the subshell"
(see the script attached)

But it's not practical until the problem described there [0]
is given the proper patch.

I also need to find out how setting part of environment readonly would
reduce the bash memory footprint. it may be interesting
(eg: export A="plop"; readonly A; bash;)

... and anyway, bash-completion-lib is not that far [1]

regards



[0]
http://groups.google.com/group/gnu.bash.bug/browse_thread/thread/caf0420b467a13d6/7230f5067cbf0d4f

[1]
http://code.google.com/p/bash-completion-lib/
-------------- next part --------------
#!/bin/bash

# NOTES:

# - subshells will need to be run with -O extglob
# but "internal" subshells calls (like in "man bash") won't do the above => warnings

# - see that thread:
# http://groups.google.com/group/gnu.bash.bug/browse_thread/thread/caf0420b467a13d6/7230f5067cbf0d4f

if [[ -z "$BASHCOMP_LOADED" ]]; then
    . /etc/bash_completion

    # exports all completions ( functions name prefixed by '_' )
    export -f $(typeset -F|sed -nE '/ _/s/^[^_]+//p')
    export BASHCOMP_LOADED=true

else
    eval $(grep '^complete ' /usr/share/bash-completion/base)

    # way 1 (mess-up with trailing backslashes)
    # exec 3< <(grep --no-filename --exclude="*/base" '^complete ' /usr/share/bash-completion/*)
    # way 2 (note: it is not posix)
    exec 3< <(sed -n ':join /\\$/{N; s/\\\n//; b join; };/^complete /p' $(find /usr/share/bash-completion -not -name "base" -and -not -name ".*" -type f))
    while read -u 3 f; do
    	# $f="complete -F _YYY XXX ..."
	# we want the _YYY part
    	a=_${f##*_}
    	b=${a%% *}
	typeset -F +f $b && eval "$f"
    done
    exec 3>&-

fi


More information about the Bash-completion-devel mailing list