I have set up the following alias in my .gitconfig file:
[alias]
ss = stash show
Unfortunately bash completion does not work correctly on this alias. When I type git ss <TAB>, I get:
❯ git ss <TAB>
apply clear drop pop show
branch create list push
Which is obviously the completion for git stash instead of git stash show.
With the original command I get the list of available stashes:
❯ git stash show <TAB>
stash@{0} stash@{1}
Is there a way to get the completion on the alias behave like on the original command?
I am on Ubuntu 20.04 and using the distro's default git completions.
I posted this question on the Git mailing list and got a reply to work around this issue:
It is possible to make completion work for your particular alias by using our completion script's extension mechanism that allows users to specify completion functions to their own git commands. If you type
git foo <TAB>and there is a_git_foo()function in your shell's environment, then the completion script will invoke that function to perform completion; this works not only for commands but for aliases as well. So for your alias you only need to "borrow" all the "show"-subcommand-specific case arms from_git_stash()and place them in a_git_ss()function, e.g. like this:Add it to your
~/.bashrc, or to a separate file that you source from your.bashrc; If you use bash-completion, then you don't even have to touch you.bashrc: save that function to a filegit-ss(dash, not underscore!) in one of the directories scanned by bash-completion ($BASH_COMPLETION_USER_DIR,~/.local/share/bash-completion/completionsor itsXDG_DATA_HOME-equivalent) and it will be auto-loaded as needed.