posh-git icon indicating copy to clipboard operation
posh-git copied to clipboard

Is it possible to extend tab complete to work for complex git aliases?

Open braydie opened this issue 6 years ago • 4 comments

I have a complex git alias that I'd like to have tab completion on to fill branch names. The command is as follows:

mstage = "!git checkout stage && git pull && git reset --hard && git merge $1 --no-commit"

$1 should be a branch name. I'm able to get this to work using git-complete.bash on bit bash on Windows

Is it possible to extend posh-git to handle tab completion for an alias like the above?

braydie avatar Jul 10 '17 11:07 braydie

I'm able to get this to work using git-complete.bash on bit bash on Windows

Meaning it already works out-of-the-box? Or you had to extend it in some way?

Is it possible to extend posh-git to handle tab completion for an alias like the above?

We could certainly add an extension point, or maybe even teach posh-git to handle basic compound aliases like yours (split on && and look for $1?

dahlbyk avatar Jul 10 '17 14:07 dahlbyk

Hey @dahlbyk - sorry I meant to say that I got autocomplete working on git bash following these steps. I believe that is a bash only thing, and wouldn't impact PowerShell (I'm guessing though).

I have a workaround at the moment using https://github.com/dahlbyk/posh-git/issues/257 -- I've added my aliases in to GitTabExpansion.ps1 which replaces my alias for git checkout for tab completion purposes

braydie avatar Jul 10 '17 19:07 braydie

sorry I meant to say that I got autocomplete working on git bash following these steps. I believe that is a bash only thing, and wouldn't impact PowerShell (I'm guessing though).

Correct. posh-git is essentially an incomplete port of that completion (plus other stuff). As far as I can tell, its alias expansion is handled here. It looks like for your alias it's going to offer completion options for git checkout even though the value will actually be used with merge, but there's a way to use the null command : to specify what command's completion should be shown.

I'm certainly open to posh-git being smarter about parsing these Git aliases.

dahlbyk avatar Jul 10 '17 21:07 dahlbyk

It would be easier to only pick up aliases right? For example I simply alias git.exe to g. This is IMO already an improvement.

FranklinYu avatar Nov 19 '18 19:11 FranklinYu