-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linux-ReadmeTest.ps9
103 lines (88 loc) · 3.56 KB
/
Linux-ReadmeTest.ps9
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
96
97
98
99
100
101
102
103
# $env:VerboseStartup = 'true'
$profileScript = Split-Path $PROFILE -Leaf
$exclusions=@()
# EXCLUSIONS-START
$exclusions += '*Windows*','repos*','choco*'
# EXCLUSIONS-END
if((-not $env:Snippets) -or (-not (Test-Path $env:Snippets))) {
$env:Snippets = "$env:HOME/.config/powershell"
}
if ($env:VerboseStartup -eq 'true') {
[switch]$MasterVerbose = $true
}
else {
[switch]$MasterVerbose = $false
}
try {
Push-Location -Verbose:$MasterVerbose
Import-Module Microsoft.PowerShell.Utility #-Verbose:$MasterVerbose
if((Split-Path $env:Snippets -Leaf) -ieq 'powershell') {
$env:Snippets = Join-Path $env:Snippets -Child Snippets -Verbose:$MasterVerbose
}
if (-not (Test-Path $env:Snippets -Verbose:$MasterVerbose)) {
git clone "https://github.com/sharpninja/Snippets.git"
if($LASTEXITCODE -ne 0) { throw "git clone `"https://github.com/sharpninja/Snippets.git`" failed with: $LASTEXITCODE" }
} else {
Write-Verbose "[$profileScript] Found $env:Snippets" -Verbose:$MasterVerbose
}
if (Test-Path $env:Snippets -Verbose:$MasterVerbose) {
Push-Location -Verbose:$MasterVerbose
Set-Location $env:Snippets -Verbose:$MasterVerbose
$exclusions += '_common.ps1'
Write-Verbose -Verbose:$MasterVerbose -Message "[$profileScript] Exclusions: $exclusions"
$snippets = Get-ChildItem *.ps1 -Verbose:$MasterVerbose -Exclude $exclusions
Pop-Location -Verbose:$MasterVerbose
$resultList = [ordered]@{ }
$snippets.FullName | ForEach-Object -Verbose:$MasterVerbose -Process {
try {
$snippet = $_
$snippetName = Split-Path $snippet -Leaf
if($snippetName){
Write-Verbose "[$profileScript]->[$snippetName] Calling with: -Verbose:`$$MasterVerbose" -Verbose:$MasterVerbose
$result = $null
$result = . $snippet -Verbose:$MasterVerbose
}
}
catch {
$err=$_.ErrorRecord?.ToString() ?? $_.ToString()
$result="[Error:] ${err}"
}
finally {
if($null -ne $snippetName){
$resultList.Add($snippetName,$result)
} elseif ($null -ne $_) {
$resultList.Add($_,$result)
} elseif ($null -ne $err) {
$resultList.Add($err.ToString(),$result)
} else {
$counter += 1
$resultList.Add("${counter}: `$null",$result)
}
}
}
if ($resultList.Length -gt 0) {
# "[$profileScript] Snippet Results`n---`n$([System.String]::Join("`n", $resultList))`n---`n"
$resultList `
| Sort-Object -Property key `
| Format-Table @{Label="Snippet"; Expression={$_.Name}}, @{Label="Result"; Expression={$_.Value}}
}
else {
"[$profileScript] No snippets where executed."
}
}
else {
Write-Verbose "[$profileScript] No directory found at [$env:Snippets]" -Verbose:$MasterVerbose
}
}
catch {
Write-Error "[$profileScript] $_"
}
finally {
Pop-Location
Write-Verbose "Leaving $Profile" -Verbose:$MasterVerbose
}
Get-Alias -Verbose:$MasterVerbose `
| Where-Object -Property Description -imatch 'snippet' -Verbose:$MasterVerbose `
| Sort-Object -Property Description, Name -Verbose:$MasterVerbose `
| Format-Table Name, Description -AutoSize -Verbose:$MasterVerbose
Write-Verbose 'PowerShell Ready.' -Verbose:$MasterVerbose