forked from StartAutomating/PipeScript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPipeScript.psm1
49 lines (39 loc) · 1.7 KB
/
PipeScript.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
45
46
47
48
49
foreach ($file in (Get-ChildItem -Path "$psScriptRoot" -Filter "*-*" -Recurse)) {
if ($file.Extension -ne '.ps1') { continue } # Skip if the extension is not .ps1
if ($file.Name -match '\.[^\.]+\.ps1$') { continue } # Skip if the file is an unrelated file.
. $file.FullName
}
$transpilerNames = Get-Transpiler | Select-Object -ExpandProperty DisplayName
$aliasList +=
@(foreach ($alias in @($transpilerNames)) {
Set-Alias ".>$alias" "Use-PipeScript" -PassThru:$True
})
$aliasList +=
@(foreach ($alias in @($transpilerNames)) {
Set-Alias ".<$alias>" "Use-PipeScript" -PassThru:$True
})
$MyModule = $MyInvocation.MyCommand.ScriptBlock.Module
$aliasList +=
@(
if ($MyModule -isnot [Management.Automation.PSModuleInfo]) {
Write-Error "'$MyModule' must be a [Management.Automation.PSModuleInfo]"
} elseif ($MyModule.ExportedCommands.Count) {
foreach ($cmd in $MyModule.ExportedCommands.Values) {
if ($cmd.CommandType -in 'Alias') {
$cmd
}
}
} else {
foreach ($cmd in $ExecutionContext.SessionState.InvokeCommand.GetCommands('*', 'Function,Cmdlet', $true)) {
if ($cmd.Module -ne $MyModule) { continue }
if ('Alias' -contains 'Alias' -and $cmd.ScriptBlock.Attributes.AliasNames) {
foreach ($aliasName in $cmd.ScriptBlock.Attributes.AliasNames) {
$ExecutionContext.SessionState.InvokeCommand.GetCommand($aliasName, 'Alias')
}
}
if ('Alias' -contains $cmd.CommandType) {
$cmd
}
}
})
Export-ModuleMember -Function * -Alias $aliasList