i use alias which adds some parameters to some program.
for example:
alias git.home='git --git-dir=$HOME/.git.home/'
complete -o bashdefault -o default -o nospace -F _git git.home \
2>/dev/null || complete -o default -o nospace -F _git git.home
it works with bash-completion v.1:2.0-1
("debian 7 wheezy"):
tab completes parameters and options for alias git.home
as well as for "original" git
.
but with bash-completion v.1:2.1-4
("debian 8 jessie") after typing git.home
and pressing tab i get this error:
bash: completion: function `_git' not found
how to re-use existing completion (for example for git
) with recent versions of package bash-completion
?
update
found partial solution: do source /usr/share/bash-completion/completions/git
before complete ...
but i get another error – git.home log
+ space + tab results in:
fatal: Not a git repository (or any of the parent directories): .git
HEAD
Best Answer
Add the following lines to your
~/.bashrc
:Explanation:
bash-completion
uses a dynamic loading of completions since 1.90. So, thegit
compspec unavailable before your typinggit
,Space,Tab.Try:
_completion_loader git
imitatesgit
,Space,Tab (i.e. loads a compspec forgit
)complete -p git | perl -pe 's/(\s)git$/$1git.home/'
builds a compspec forgit.home
(replacesgit
togit.home
in agit
's compspec)eval
execute the resulting compspec.Type
git.home
,Space,p
Tab. You should see:But
git.home log
,Space,Tab produces:This message is a result of the git completion bug. There is a fix in the upstream: completion: silence "fatal: Not a git repository" error
Looks like another question:)doesn't work as expected. You set
GIT_DIR
for current session. Try with your solution: