forked from TSYS-Merchant/posh-svn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SvnTabExpansion.ps1
95 lines (86 loc) · 3.64 KB
/
SvnTabExpansion.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
87
88
89
90
91
92
93
94
95
function SvnTabExpansion($lastBlock) {
switch -regex ($lastBlock) {
#handles svn help <cmd>
#handles svn <cmd>
'svn (help )?(\S*)$' {
svnCommands($matches[2]);
}
'tsvn (\S*)$' {
tortoiseSvnCommands($matches[1]);
}
}
}
function svnCommands($filter) {
$cmdList = @()
$output = & $svn help
foreach($line in $output) {
if($line -match '^ (\S+)(.*)') {
$cmd = $matches[1]
if($filter -and $cmd.StartsWith($filter)) {
$cmdList += $cmd.Trim();
}
elseif(-not $filter) {
$cmdList += $cmd.Trim();
}
}
}
$cmdList | Sort-Object
}
function tortoiseSvnCommands($filter) {
if($filter) {
return $tsvnCommands.keys | Where-Object { $tsvnCommands[$_].cmd.StartsWith($filter) } | Sort-object
}
else {
return $tsvnCommands.keys | Sort-Object
}
}
$tsvnCommands = @{
"about" = @{ cmd = "about"; useCurrentDirectory = $false };
"log" = @{ cmd = "log"; useCurrentDirectory = $true };
"checkout" = @{ cmd = "checkout"; useCurrentDirectory = $false };
"import" = @{ cmd = "import"; useCurrentDirectory = $false };
"update" = @{ cmd = "update"; useCurrentDirectory = $true };
"commit" = @{ cmd = "commit"; useCurrentDirectory = $true };
"add" = @{ cmd = "add"; useCurrentDirectory = $false };
"revert" = @{ cmd = "revert"; useCurrentDirectory = $false };
"cleanup" = @{ cmd = "cleanup"; useCurrentDirectory = $false };
"resolve" = @{ cmd = "resolve"; useCurrentDirectory = $false };
"repocreate" = @{ cmd = "repocreate"; useCurrentDirectory = $false };
"switch" = @{ cmd = "switch"; useCurrentDirectory = $true };
"export" = @{ cmd = "export"; useCurrentDirectory = $false };
"merge" = @{ cmd = "merge"; useCurrentDirectory = $false };
"mergeall" = @{ cmd = "mergeall"; useCurrentDirectory = $false };
"copy" = @{ cmd = "copy"; useCurrentDirectory = $false };
"settings" = @{ cmd = "settings"; useCurrentDirectory = $false };
"remove" = @{ cmd = "remove"; useCurrentDirectory = $false };
"rename" = @{ cmd = "rename"; useCurrentDirectory = $false };
"diff" = @{ cmd = "diff"; useCurrentDirectory = $false };
"showcompare" = @{ cmd = "showcompare"; useCurrentDirectory = $false };
"conflicteditor" = @{ cmd = "conflicteditor"; useCurrentDirectory = $false };
"relocate" = @{ cmd = "relocate"; useCurrentDirectory = $false };
"help" = @{ cmd = "help"; useCurrentDirectory = $false };
"repostatus" = @{ cmd = "repostatus"; useCurrentDirectory = $false };
"repobrowser" = @{ cmd = "repobrowser"; useCurrentDirectory = $false };
"ignore" = @{ cmd = "ignore"; useCurrentDirectory = $false };
"blame" = @{ cmd = "blame"; useCurrentDirectory = $false };
"cat" = @{ cmd = "cat"; useCurrentDirectory = $false };
"createpatch" = @{ cmd = "createpatch"; useCurrentDirectory = $false };
"revisiongraph" = @{ cmd = "revisiongraph"; useCurrentDirectory = $false };
"lock" = @{ cmd = "lock"; useCurrentDirectory = $false };
"unlock" = @{ cmd = "unlock"; useCurrentDirectory = $false };
"rebuildiconcache" = @{ cmd = "rebuildiconcache"; useCurrentDirectory = $false };
"properties" = @{ cmd = "properties"; useCurrentDirectory = $false };
}
if (Test-Path Function:\TabExpansion) {
Rename-Item Function:\TabExpansion TabExpansionBackup
}
function TabExpansion($line, $lastWord) {
$lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
switch -regex ($lastBlock) {
# Execute git tab completion for all svn-related commands
"^$(Get-AliasPattern svn) (.*)" { SvnTabExpansion $lastBlock }
"^$(Get-AliasPattern tsvn) (.*)" { SvnTabExpansion $lastBlock }
# Fall back on existing tab expansion
default { if (Test-Path Function:\TabExpansionBackup) { TabExpansionBackup $line $lastWord } }
}
}