-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindows-ReadmeTest.ps9
147 lines (121 loc) · 4.82 KB
/
Windows-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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# $env:VerboseStartup = 'true'
$profileScript = Split-Path $PROFILE -Leaf
$exclusions = @()
# EXCLUSIONS-START
$exclusions += '*Linux*'
$exclusions += '*ConvertFrom-WingetStdout.ps1'
# EXCLUSIONS-END
if ((-not $env:Snippets) -or (-not (Test-Path $env:Snippets))) {
if (Test-Path "$env:ONEDRIVE/Documents/Powershell") {
$env:Snippets = "$env:ONEDRIVE/Documents/Powershell"
}
else {
$env:Snippets = "$env:UserProfile/Documents/Powershell"
}
}
if ($env:VerboseStartup -eq 'true') {
[switch]$MasterVerbose = $true
}
else {
[switch]$MasterVerbose = $false
}
try {
Push-Location -Verbose:$MasterVerbose
if(-not($env:GitRoot)){
$env:GitRoot = "https://github.com/PS-Services"
}
Write-Verbose "[$profileScript] `$GitRoot: $GitRoot" -Verbose:$MasterVerbose
Import-Module Microsoft.PowerShell.Utility #-Verbose:$MasterVerbose
if ((Split-Path $env:Snippets -Leaf) -ieq 'powershell') {
Set-Location $env:Snippets
$env:Snippets = Join-Path $env:Snippets -Child Snippets -Verbose:$MasterVerbose
}
if (-not (Test-Path $env:Snippets -Verbose:$MasterVerbose)) {
git clone "$GitRoot/Snippets.git"
if ($LASTEXITCODE -ne 0) {
throw "git clone `"$GitRoot/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 | Sort-Object Name
$thirdPartyPath = $env:Snippets + '/3rdParty'
if (Test-Path $thirdPartyPath) {
$thirdParty = Get-ChildItem *.ps1 -Path $thirdPartyPath -Recurse -Verbose:$MasterVerbose -Exclude $exclusions
$snippets += $thirdParty
}
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 = "$_"
$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
}
function Invoke-Audio {
param([string]$target)
$audioConverter = "C:\GitHub\AudioConverter\src\AudioConverter\bin\Debug\AudioConverter.exe";
& $audioConverter $target --root 'c:\Users\kingd\Music'
}
Set-Alias -Name 'audio' -Value 'Invoke-Audio' -PassThru
Set-Alias -Name pwg -Value "$env:Snippets\3rdParty\parse-winget\ConvertFrom-WingetStdout.ps1" -PassThru
function Set-LocationDownloads {
Set-Location (Join-Path $env:USERPROFILE -Child downloads)
}
set-alias -Name down -Value Set-LocationDownloads -Description 'Set Location to Downloads folder.'
}
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