-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPsGitScript.psm1
44 lines (35 loc) · 1.05 KB
/
PsGitScript.psm1
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
function Invoke-Regex {
param
(
[Parameter(Mandatory = $true, Position = 0)]
[string]
$Regex,
[Parameter(Mandatory = $False, Position = 1)]
[int]
$GroupIndex = 0,
[Parameter(Mandatory = $false, Position = 2, ValueFromPipeline = $true)]
[string]
$Text = ""
)
Process {
if ($Text -match $Regex) {
return $Matches[$GroupIndex]
}
}
}
function Invoke-PsGitScriptInit {
try {
Get-Command "git.exe" | Out-Null
}
Catch { throw "git installation cannot be found." }
$scripts = Get-Command "git-*.ps1"
foreach ($item in $scripts) {
$path = $item.Source
$command = $path.Replace('\', '/')
$alias = "! pwsh -NoProfile -ExecutionPolicy bypass -WorkingDirectory `$PWD -c $command"
$name = Split-Path $path -Leaf | Invoke-Regex -Regex "^git-(.*).ps1$" -Group 1
& git config --global "alias.$name" "$alias"
}
}
Invoke-PsGitScriptInit
Export-ModuleMember -Function Invoke-PsGitScriptInit