Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds aliasing support for TortoiseGit commands #394

Merged
merged 3 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function GitTabExpansionInternal($lastBlock) {
# Handles tgit <command> (tortoisegit)
if ($lastBlock -match "^$(Get-AliasPattern tgit) (?<cmd>\S*)$") {
# Need return statement to prevent fall-through.
return $tortoiseGitCommands | Where-Object { $_ -like "$($matches['cmd'])*" }
return $Global:TortoiseGitSettings.TortoiseGitCommands.Keys.GetEnumerator() | sort | Where-Object { $_ -like "$($matches['cmd'])*" }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/sort/Sort-Object/

(also in TortoiseGit.ps1)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. PowerShell Core running on Linux or macOS does not have the sort alias defined for Sort-Object. So calling sort would execute the native sort utility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

# Handles gitk
Expand Down
98 changes: 56 additions & 42 deletions src/TortoiseGit.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TortoiseGit
# TortoiseGit

function private:Get-TortoiseGitPath {
if ((Test-Path "C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe") -eq $true) {
Expand All @@ -11,60 +11,74 @@ function private:Get-TortoiseGitPath {

$Global:TortoiseGitSettings = new-object PSObject -Property @{
TortoiseGitPath = (Get-TortoiseGitPath)
TortoiseGitCommands = @{
"about" = "about";
"add" = "add";
"blame" = "blame";
"cat" = "cat";
"cleanup" = "cleanup";
"clean" = "cleanup";
"commit" = "commit";
"conflicteditor" = "conflicteditor";
"createpatch" = "createpatch";
"patch" = "createpatch";
"diff" = "diff";
"export" = "export";
"help" = "help";
"ignore" = "ignore";
"log" = "log";
"merge" = "merge";
"pull" = "pull";
"push" = "push";
"rebase" = "rebase";
"refbrowse" = "refbrowse";
"reflog" = "reflog";
"remove" = "remove";
"rm" = "remove";
"rename" = "rename";
"mv" = "rename";
"repocreate" = "repocreate";
"init" = "repocreate";
"repostatus" = "repostatus";
"status" = "repostatus";
"resolve" = "resolve";
"revert" = "revert";
"settings" = "settings";
"config" = "settings";
"stash" = "stash";
"stashapply" = "stashapply";
"stashsave" = "stashsave";
"subadd" = "subadd";
"subsync" = "subsync";
"subupdate" = "subupdate";
"switch" = "switch";
"checkout" = "switch";
"sync" = "sync";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to alias fetch to sync?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

}
}

function tgit {
if($args) {
# Replace any aliases with actual TortoiseGit commands
if ($Global:TortoiseGitSettings.TortoiseGitCommands.ContainsKey($args[0])) {
$args[0] = $Global:TortoiseGitSettings.TortoiseGitCommands.Get_Item($args[0])
}

if($args[0] -eq "help") {
# Replace the built-in help behaviour with just a list of commands
$tortoiseGitCommands
return
$Global:TortoiseGitSettings.TortoiseGitCommands.Values.GetEnumerator() | sort | Get-Unique
return
}

$newArgs = @()
$newArgs += "/command:" + $args[0]

$cmd = $args[0]

if($args.length -gt 1) {
$args[1..$args.length] | % { $newArgs += $_ }
}

& $Global:TortoiseGitSettings.TortoiseGitPath $newArgs
}
}

$tortoiseGitCommands = @(
"about",
"log",
"commit",
"add",
"revert",
"cleanup" ,
"resolve",
"switch",
"export",
"merge",
"settings",
"remove",
"rename",
"diff",
"conflicteditor",
"help",
"ignore",
"blame",
"cat",
"createpatch",
"pull",
"push",
"rebase",
"stashsave",
"stashapply",
"subadd",
"subupdate",
"subsync",
"reflog",
"refbrowse",
"sync",
"repostatus"
) | sort
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOL @ EOF, please!

(Tip: we have a .editorconfig that will enforce this for supported editors.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)