-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathIrregular.psm1
53 lines (43 loc) · 1.76 KB
/
Irregular.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
50
51
52
$CommandsPath = Join-Path $PSScriptRoot Commands
:ToIncludeFiles foreach ($file in (Get-ChildItem -Path "$CommandsPath" -Filter "*-*.ps1" -Recurse)) {
if ($file.Extension -ne '.ps1') { continue } # Skip if the extension is not .ps1
foreach ($exclusion in '\.[^\.]+\.ps1$') {
if (-not $exclusion) { continue }
if ($file.Name -match $exclusion) {
continue ToIncludeFiles # Skip excluded files
}
}
. $file.FullName
}
$MyModule = $MyInvocation.MyCommand.ScriptBlock.Module
$ExecutionContext.SessionState.PSVariable.Set($myModule.Name, $MyModule)
$MyModule.pstypenames.insert(0, $myModule.Name)
$newDriveCommonParameters =
@{PSProvider='FileSystem';Scope='Global';ErrorAction='Ignore'}
New-PSDrive -Name $myModule.name @newDriveCommonParameters -Root ($myModule | Split-Path)
if ($home) {
$MyMyModule= "My$($myModule.name)"
New-PSDrive -Name $MyMyModule @newDriveCommonParameters -Root (Join-Path $home $MyMyModule)
}
Import-RegEx
foreach ($k in $script:_RegexLibrary.Keys) {
Set-Alias -Name "?<$k>" -Value Use-RegEx
}
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
if ($script:_RegexTempModules -and $script:_RegexTempModules.Count) {
@($script:_RegexTempModules) | Remove-Module
}
}
$MyInvocation.MyCommand.ScriptBlock.Module |
Add-Member NoteProperty Splicers @{
'\?\<(?<Name>\w+)\>' = {
$out = "[Regex]::new(@'" + [Environment]::NewLine + (
Get-RegEx -Name $input.name |
Select-Object -ExpandProperty Pattern) + "'@, 'IgnoreCase,IgnorePatternWhitespace')"
$out
}
}
Set-Alias ?<> New-RegEx
Set-Alias Write-RegEx New-RegEx
Set-Alias ?<.> Use-Regex
Export-ModuleMember -Function *-* -Alias * -Variable $MyModule.Name