TortoiseGit.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# TortoiseGit

function private:Get-TortoiseGitPath {
    if ((Test-Path "C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe") -eq $true) {
        # TortoiseGit 1.8.0 renamed TortoiseProc to TortoiseGitProc.
        return "C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe"
    }

    return "C:\Program Files\TortoiseGit\bin\TortoiseProc.exe"
}

$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";
        "fetch" = "sync";
        "sync" = "sync";
    }
}

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
            $Global:TortoiseGitSettings.TortoiseGitCommands.Values.GetEnumerator() | Sort-Object | Get-Unique
            return
        }

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

        $cmd = $args[0]

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

        & $Global:TortoiseGitSettings.TortoiseGitPath $newArgs
    }
}