When inside a Git repository, is it possible to add tab completion for branches to Powershell? For example:
PS> git checkout maTAB
would result in
PS> git checkout master
When inside a Git repository, is it possible to add tab completion for branches to Powershell? For example:
PS> git checkout maTAB
would result in
PS> git checkout master
I wrote this little PS "gem", if posh-git is too much.
Just put it in your PowerShell profile to be able to type co (with a space) and hit Tab to trigger completion and cycle through the list of branches:
function co
{
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[ArgumentCompleter({
param($pCmd, $pParam, $pWord, $pAst, $pFakes)
$branchList = (git branch --format='%(refname:short)')
if ([string]::IsNullOrWhiteSpace($pWord)) {
return $branchList;
}
$branchList | Select-String "$pWord"
})]
[string] $branch
)
git checkout $branch;
}
UPDATE: refactored to return a list of branches when tab-completion invoked after space and no partial string can be matched. Will return "master" if this is only one branch
As a bonus, did you know you can call TortoiseGit from shell?
function dif
{
TortoiseGitProc.exe /command:repostatus
}