- Package:
- bash-completion
- Source:
- bash-completion
- Submitter:
- afuentes
- Date:
- 2014-09-27 08:09:05 UTC
- Severity:
- wishlist
i think is wanted and feasible to make bash-completion to autocomplete something like alias aptinstall='apt-get install' just in the same way it would autocomplete in bash shell after typing those words either buildin alias autocompletion (most awesome) or some stanza or means to easier to the task of autocomplete alias (less awesome but still useful). Thanks!
A related problem is that aliasing an existing command stops bash-completion working. For example, I had: alias make=colormake And that stops bash-completion from working for either make or colormake. The code that gets bash-completion working for aliases, e.g.: http://superuser.com/questions/436314/how-can-i-get-bash-to-perform-tab-completion-for-my-aliases does not work for this case (where the name of a command with bash completions is aliased to some other command). This is a pity, as it means that for make I'm forced to choose between coloring and bash-completion.
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
This feature will be very useful! michael your script not work for me :-/
Some of the time it hasn't been working for me, either. Right now (on a current sid) it appears to work. I'm not really sure why. In your case, I'm sorry to say, you'll have to do some debugging yourself.