How do I get bash completion to work with aliases?

后端 未结 12 1061
温柔的废话
温柔的废话 2020-11-28 00:35

Case in point:

I\'m a on mac with bash v3.2.17, I\'m using git installed via macports with the bash_completion variant.

When I type git checkout m<

12条回答
  •  庸人自扰
    2020-11-28 01:27

    First, look up the original completion command. Example:

    $ complete | grep git
    
    complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git
    

    Now add these to your startup script (e.g. ~/.bashrc):

    # copy the original statement, but replace the last command (git) with your alias (g)
    complete -o bashdefault -o default -o nospace -F __git_wrap__git_main g
    
    # load dynamically loaded completion functions (may not be required)
    _completion_loader git
    

    The _completion_loader line may not be required. But for some situations, the completion function is only loaded dynamically after you type the command and press TAB the first time. So if you haven't used the original command, and try the alias + TAB, you may get an error like "bash: completion: function '_docker' not found".

提交回复
热议问题