-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_common.ps1
97 lines (73 loc) · 3.85 KB
/
_common.ps1
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
param([switch]$VerboseSwitch = $false)
Write-Verbose "[_common.ps1] Entered common" -Verbose:$VerboseSwitch
switch ($env:IsDesktop)
{
('true')
{
$env:IsWindows = 'True'; $env:IsUnix = 'False'
}
default
{
$env:IsWindows = "$IsWindows"; $env:IsUnix = "$($IsLinux -or $IsMacOS)"
}
}
Write-Verbose "`$env:IsWindows: $($env:IsWindows)" -Verbose:$VerboseSwitch
$utilities = Get-Module Microsoft.PowerShell.Utility -ErrorAction SilentlyContinue
if(-not $utilities){
Install-Module Microsoft.PowerShell.Utility -AllowClobber -Scope CurrentUser -AcceptLicense -Force
}
Import-Module Microsoft.PowerShell.Utility
function Set-SnippetsLocation {
Set-Location "$env:Snippets"
}
function Initialize-Snippets {
param([switch]$VerboseSwitch = $false)
#$Verbose=$true -or $VerboseSwitch
$Verbose=$VerboseSwitch
# Write-Verbose "[$script] [$env:SnippetsInitialized] -not `$env:SnippetsInitialized: $(-not $env:SnippetsInitialized)" -Verbose:$VerboseSwitch
$script = $MyInvocation.MyCommand
Write-Verbose $MyInvocation -Verbose:$VerboseSwitch
$alias = set-alias -Verbose:$VerboseSwitch -Scope Global -Description "Snippets: [snippets] Go to Snippets folder [$env:Snippets]" -Name snipps -Value Set-SnippetsLocation
Push-Location
try {
if($env:SnippetsInitialized) {
Write-Verbose "[$script] Snippets already initialized." -Verbose:$VerboseSwitch
return $env:SnippetsInitialized
}
else {
$fileInfo = New-Object System.IO.FileInfo (Get-Item $PSScriptRoot).FullName
$path = $fileInfo.Directory.FullName;
if($path.EndsWith("PowerShell", [System.StringComparison]::OrdinalIgnoreCase)){
$path = join-path $path -ChildPath Snippets
}
set-location $path
Write-Verbose "[$script] Initializing Snippets in $path" -Verbose:$VerboseSwitch
$versionFilePath = Join-Path (Get-Location) -Child ".version" -Verbose:$VerboseSwitch
if(-not (Test-Path $versionFilePath)){
if(Test-Path $PWD/set-version.ps1 -Verbose:$VerboseSwitch) {
. $PWD/set-version.ps1 -Verbose:$VerboseSwitch
$versionFile = Get-Item $PWD/.version -ErrorAction Stop
}
}
$versionFile = Get-Item $versionFilePath -ErrorAction SilentlyContinue -Verbose:$VerboseSwitch
Write-Verbose "[$script] $versionFilePath == [${versionFile.FullName}]: $($versionFilePath -eq $versionFile.FullName)" -Verbose:$VerboseSwitch
$env:SnippetsVersion = get-content -Path $versionFilePath -Verbose:$VerboseSwitch -ErrorAction Stop
Write-Verbose "[$script] `$env:SnippetsVersion: [$($env:SnippetsVersion)]" -Verbose:$VerboseSwitch
$env:IsDesktop = "$($PSVersionTable.PSEdition -ieq 'desktop')"
Write-Verbose "[$script] `$env:IsDesktop: [$($env:IsDesktop)]" -Verbose:$VerboseSwitch
Write-Verbose "[$script] Snippets Version: $env:SnippetsVersion" -Verbose:$VerboseSwitch
Write-Verbose "[$script] `$env:IsDesktop: $env:IsDesktop" -Verbose:$VerboseSwitch
Write-Verbose "[$script] `$env:IsWindows: $env:IsWindows" -Verbose:$VerboseSwitch
Write-Verbose "[$script] `$env:IsUnix: $env:IsUnix" -Verbose:$VerboseSwitch
$env:SnippetsInitialized="$true"
if($env:IsUnix -eq "$true") { return "Powershell ready for Unix-like System."}
elseif($env:IsDesktop -eq "$true") { return "Windows Powershell is ready."}
else { return "Powershell Core is ready." }
}
}
finally {
Write-Verbose "[$script] [$env:Snippetscode Initialized] -not `$env:SnippetsInitialized: $(-not $env:SnippetsInitialized)" -Verbose:$VerboseSwitch
Pop-Location -Verbose:$VerboseSwitch
$Verbose = $VerboseSwitch
}
}