[Bash-completion-devel] Bug#669618: bash-completion should autocomplete bash alias as well
Michael Schuerig
michael at schuerig.de
Sat Jul 19 11:48:17 UTC 2014
I just stumbled on the same problem and after some experimentation, I'm
sourcing a modified completion loader at the end of my .bashrc (specifically
after the original completion code is loaded).
_custom_completion_loader()
{
local cmd="${1##*/}"
local cmdt=$(type -t "$1")
local compfile=./completions
#[[ $BASH_SOURCE == */* ]] && compfile="${BASH_SOURCE%/*}/completions"
compfile="/usr/share/bash-completion/completions"
if [[ $cmdt = 'alias' ]]; then
cmd=$( alias "$cmd" | sed "s/^alias [^=]*='\([^ ']*\)[ '].*$/\1/" )
[[ $(type -t "_${cmd}") = 'function' ]] && complete -F "_${cmd}" "$1" &&
return 124
fi
compfile+="/${cmd}"
# Avoid trying to source dirs; https://bugzilla.redhat.com/903540
[[ -f "$compfile" ]] && . "$compfile" &>/dev/null && return 124
# Need to define *something*, otherwise there will be no completion at
all.
complete -F _minimal "$cmd" && return 124
}
complete -D -F _custom_completion_loader
Beware of wrapped lines. This code is fresh from my keyboard and not at all
well-tested!
Michael
More information about the Bash-completion-devel
mailing list