Skip to content

Commit 21487ea

Browse files
authored
!deploy v0.6.0 release (#32)
## 0.6.0 - 2019-11-02 * [Issue #21](#21) - _Thank you [@corbob](https://github.com/corbob)!_ * Fixed: Project folder discovery logic to ensure that project folders with the same name are added to the dictionary without conflict. * [Issue #22](#22) - _Thank you [@corbob](https://github.com/corbob)!_ * Added: `WithInsiders` switch parameter to `Open-Code`, `Edit-PSProfilePrompt`, and `Edit-PSProfileInitScript`. * [Issue #23](#23) * Fixed: `$PSProfile` variable should exist regardless of when you import the module (removed conditional variable setting from PSM1). * [Issue #26](#26) * Fixed: `$PSProfile._globalize()` internal method will now update `$PSDefaultParameterValue` to `$global":PSDefaultParameterValue` on InitScripts / ExternalScripts / etc so `$PSDefaultParameterValue` persists in the main session as intended. * [Issue #27](#27) * Removed: `Set-Prompt` alias to prevent conflict with `oh-my-posh` module. * [Issue #29](#29) * Fixed: Secrets now persist across refreshes and sessions as intended. Details: * Removed `PSProfileVault` class, replaced with pure hashtable. * Updated the Secrets management functions to work directly against the Vault hashtable. * [Issue #31](#31) * Fixed: Same as [Issue #29](#29).
2 parents 4239ac6 + 06e3451 commit 21487ea

11 files changed

+186
-174
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* [PSProfile - ChangeLog](#psprofile---changelog)
2+
* [0.6.0 - 2019-11-02](#060---2019-11-02)
23
* [0.5.0 - 2019-10-08](#050---2019-10-08)
34
* [0.4.1 - 2019-10-08](#041---2019-10-08)
45
* [0.4.0 - 2019-09-22](#040---2019-09-22)
@@ -19,6 +20,25 @@
1920

2021
# PSProfile - ChangeLog
2122

23+
## 0.6.0 - 2019-11-02
24+
25+
* [Issue #21](https://github.com/scrthq/PSProfile/issues/21) - _Thank you [@corbob](https://github.com/corbob)!_
26+
* Fixed: Project folder discovery logic to ensure that project folders with the same name are added to the dictionary without conflict.
27+
* [Issue #22](https://github.com/scrthq/PSProfile/issues/22) - _Thank you [@corbob](https://github.com/corbob)!_
28+
* Added: `WithInsiders` switch parameter to `Open-Code`, `Edit-PSProfilePrompt`, and `Edit-PSProfileInitScript`.
29+
* [Issue #23](https://github.com/scrthq/PSProfile/issues/23)
30+
* Fixed: `$PSProfile` variable should exist regardless of when you import the module (removed conditional variable setting from PSM1).
31+
* [Issue #26](https://github.com/scrthq/PSProfile/issues/26)
32+
* Fixed: `$PSProfile._globalize()` internal method will now update `$PSDefaultParameterValue` to `$global":PSDefaultParameterValue` on InitScripts / ExternalScripts / etc so `$PSDefaultParameterValue` persists in the main session as intended.
33+
* [Issue #27](https://github.com/scrthq/PSProfile/issues/27)
34+
* Removed: `Set-Prompt` alias to prevent conflict with `oh-my-posh` module.
35+
* [Issue #29](https://github.com/scrthq/PSProfile/issues/29)
36+
* Fixed: Secrets now persist across refreshes and sessions as intended. Details:
37+
* Removed `PSProfileVault` class, replaced with pure hashtable.
38+
* Updated the Secrets management functions to work directly against the Vault hashtable.
39+
* [Issue #31](https://github.com/scrthq/PSProfile/issues/31)
40+
* Fixed: Same as [Issue #29](https://github.com/scrthq/PSProfile/issues/29).
41+
2242
## 0.5.0 - 2019-10-08
2343

2444
* Miscellaneous

PSProfile/Classes/PSProfile.Classes.ps1

Lines changed: 84 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -52,45 +52,7 @@ class PSProfileSecret {
5252
$this.SecureString = $secureString
5353
}
5454
}
55-
class PSProfileVault : Hashtable {
56-
[hashtable] $_secrets
5755

58-
PSProfileVault() {
59-
$this._secrets = @{ }
60-
}
61-
[void] SetSecret([string]$name, [string]$userName, [securestring]$password) {
62-
$this._secrets[$name] = [PSCredential]::new(
63-
$userName,
64-
$password
65-
)
66-
}
67-
[void] SetSecret([pscredential]$psCredential) {
68-
$this._secrets[$psCredential.UserName] = $psCredential
69-
}
70-
[void] SetSecret([string]$name, [pscredential]$psCredential) {
71-
$this._secrets[$name] = $psCredential
72-
}
73-
[void] SetSecret([string]$name, [securestring]$secureString) {
74-
$this._secrets[$name] = $secureString
75-
}
76-
[pscredential] GetSecret() {
77-
if ($env:USERNAME) {
78-
return $this._secrets[$env:USERNAME]
79-
}
80-
elseif ($env:USER) {
81-
return $this._secrets[$env:USER]
82-
}
83-
else {
84-
return $null
85-
}
86-
}
87-
[object] GetSecret([string]$name) {
88-
return $this._secrets[$name]
89-
}
90-
[void] RemoveSecret([string]$name) {
91-
$this._secrets.Remove($name)
92-
}
93-
}
9456
class PSProfile {
9557
hidden [System.Collections.Generic.List[PSProfileEvent]] $Log
9658
[hashtable] $_internal
@@ -112,11 +74,11 @@ class PSProfile {
11274
[string[]] $ScriptPaths
11375
[hashtable] $SymbolicLinks
11476
[hashtable] $Variables
115-
[PSProfileVault] $Vault
77+
[hashtable] $Vault
11678

11779
PSProfile() {
11880
$this.Log = [System.Collections.Generic.List[PSProfileEvent]]::new()
119-
$this.Vault = [PSProfileVault]::new()
81+
$this.Vault = @{_secrets = @{}}
12082
$this._internal = @{ }
12183
$this.GitPathMap = @{ }
12284
$this.PSBuildPathMap = @{ }
@@ -150,17 +112,17 @@ class PSProfile {
150112
Default = "AWS: "
151113
}
152114
}
153-
PSReadline = @{
154-
Options = @{}
155-
KeyHandlers = @{}
115+
PSReadline = @{
116+
Options = @{ }
117+
KeyHandlers = @{ }
156118
}
157119
}
158120
$this.RefreshFrequency = (New-TimeSpan -Hours 1).ToString()
159121
$this.LastRefresh = [datetime]::Now.AddHours(-2)
160122
$this.LastSave = [datetime]::Now
161123
$this.ProjectPaths = @()
162124
$this.PluginPaths = @()
163-
$this.InitScripts = @{}
125+
$this.InitScripts = @{ }
164126
$this.ScriptPaths = @()
165127
$this.PathAliases = @{
166128
'~' = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
@@ -245,7 +207,7 @@ if ($env:AWS_PROFILE) {
245207
"`n>> "'
246208
$plugPaths = @((Join-Path $PSScriptRoot "Plugins"))
247209
$curVer = (Import-Metadata (Join-Path $PSScriptRoot "PSProfile.psd1")).ModuleVersion
248-
$this.PluginPaths | Where-Object {-not [string]::IsNullOrEmpty($_) -and ($_ -match "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]$curVer" -or $_ -notmatch "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]\d+\.\d+\.\d+") } | ForEach-Object {
210+
$this.PluginPaths | Where-Object { -not [string]::IsNullOrEmpty($_) -and ($_ -match "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]$curVer" -or $_ -notmatch "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]\d+\.\d+\.\d+") } | ForEach-Object {
249211
$plugPaths += $_
250212
}
251213
$this.PluginPaths = $plugPaths | Select-Object -Unique
@@ -336,6 +298,7 @@ if ($env:AWS_PROFILE) {
336298
$content = $content.Replace($fullValue, "function global:$funcName {")
337299
}
338300
}
301+
$content = $content -replace '\$PSDefaultParameterValues','$global:PSDefaultParameterValues'
339302
return $content
340303
}
341304
hidden [void] _cleanConfig() {
@@ -351,16 +314,16 @@ if ($env:AWS_PROFILE) {
351314
"Verbose"
352315
)
353316
[hashtable[]]$final = @()
354-
$this.$section | Where-Object {$_ -is [hashtable] -and $_.Name} | ForEach-Object {
317+
$this.$section | Where-Object { $_ -is [hashtable] -and $_.Name } | ForEach-Object {
355318
$final += $_
356319
}
357-
$this.$section | Where-Object {$_ -is [string]} | ForEach-Object {
320+
$this.$section | Where-Object { $_ -is [string] } | ForEach-Object {
358321
$this._log(
359322
"[$section] Converting module string to hashtable: $_",
360323
"CleanConfig",
361324
"Verbose"
362325
)
363-
$final += @{Name = $_}
326+
$final += @{Name = $_ }
364327
}
365328
$this.$section = $final
366329
}
@@ -371,7 +334,7 @@ if ($env:AWS_PROFILE) {
371334
"Verbose"
372335
)
373336
[string[]]$final = @()
374-
$this.$section | Where-Object {-not [string]::IsNullOrEmpty($_)} | ForEach-Object {
337+
$this.$section | Where-Object { -not [string]::IsNullOrEmpty($_) } | ForEach-Object {
375338
$final += $_
376339
}
377340
$this.$section = $final
@@ -638,33 +601,33 @@ if ($env:AWS_PROFILE) {
638601
$g = 0
639602
$b = 0
640603
$pInfo.EnumerateDirectories('.git',[System.IO.SearchOption]::AllDirectories) | ForEach-Object {
641-
$PathName = $_.Parent.BaseName
604+
$PathName = $_.Parent.Name
642605
$FullPathName = $_.Parent.FullName
643606
$g++
644607
$this._log(
645608
"Found git project @ $($FullPathName)",
646609
'FindProjects',
647610
'Verbose'
648611
)
649-
$currPath = $_
650-
while($this.GitPathMap.ContainsKey($PathName)){
651-
$currPath = $currPath.Parent
652-
$doublePath = [System.IO.DirectoryInfo]::new($this.GitPathMap[$PathName])
653-
$this.GitPathMap["$($doublePath.Parent)\$($doublePath.BaseName)"] = $doublePath.FullName
654-
$this.GitPathMap.Remove($PathName)
655-
if($this.PSBuildPathMap.ContainsKey($PathName)){
656-
$PSBuildPath = [System.IO.DirectoryInfo]::new($this.PSBuildPathMap[$PathName])
657-
$this.PSBuildPathMap["$($PSBuildPath.Parent)\$($PSBuildPath.BaseName)"] = $doublePath.FullName
658-
$this.PSBuildPathMap.Remove($PathName)
659-
}
660-
$PathName = "$($currPath.Parent.BaseName)\$PathName"
612+
$currPath = $_
613+
while ($this.GitPathMap.ContainsKey($PathName)) {
614+
$currPath = $currPath.Parent
615+
$doublePath = [System.IO.DirectoryInfo]::new($this.GitPathMap[$PathName])
616+
$this.GitPathMap["$($doublePath.Parent.Name)$([System.IO.Path]::DirectorySeparatorChar)$($doublePath.Name)"] = $doublePath.FullName
617+
$this.GitPathMap.Remove($PathName)
618+
if ($this.PSBuildPathMap.ContainsKey($PathName)) {
619+
$PSBuildPath = [System.IO.DirectoryInfo]::new($this.PSBuildPathMap[$PathName])
620+
$this.PSBuildPathMap["$($PSBuildPath.Parent.Name)$([System.IO.Path]::DirectorySeparatorChar)$($PSBuildPath.Name)"] = $doublePath.FullName
621+
$this.PSBuildPathMap.Remove($PathName)
661622
}
623+
$PathName = "$($currPath.Parent.BaseName)$([System.IO.Path]::DirectorySeparatorChar)$PathName"
624+
}
662625
$this.GitPathMap[$PathName] = $FullPathName
663626
$bldPath = [System.IO.Path]::Combine($FullPathName,'build.ps1')
664627
if ([System.IO.File]::Exists($bldPath)) {
665628
$b++
666629
$this._log(
667-
"Found build script @ $($_.FullName)",
630+
"Found build script @ $($bldPath)",
668631
'FindProjects',
669632
'Verbose'
670633
)
@@ -954,74 +917,74 @@ if ($env:AWS_PROFILE) {
954917
)
955918
if ($this.Plugins.Count) {
956919
$this.Plugins.ForEach( {
957-
if ($_.Name -ne 'PSProfile.PowerTools') {
958-
$plugin = $_
959-
$this._log(
960-
"'$($plugin.Name)' Searching for plugin",
961-
'LoadPlugins',
962-
'Verbose'
963-
)
964-
try {
965-
$found = $null
966-
$importParams = @{
967-
ErrorAction = 'Stop'
968-
Global = $true
969-
}
970-
if ($plugin.ArgumentList) {
971-
$importParams['ArgumentList'] = $plugin.ArgumentList
972-
}
973-
[string[]]$pathsToSearch = @($this.PluginPaths)
974-
$env:PSModulePath.Split([System.IO.Path]::PathSeparator) | ForEach-Object {
975-
$pathsToSearch += $_
976-
}
977-
foreach ($plugPath in $pathsToSearch) {
978-
$fullPath = [System.IO.Path]::Combine($plugPath,"$($plugin.Name).ps1")
979-
$this._log(
980-
"'$($plugin.Name)' Checking path: $fullPath",
981-
'LoadPlugins',
982-
'Debug'
983-
)
984-
if (Test-Path $fullPath) {
985-
$sb = [scriptblock]::Create($this._globalize(([System.IO.File]::ReadAllText($fullPath))))
986-
if ($plugin.ArgumentList) {
987-
.$sb($plugin.ArgumentList)
988-
}
989-
else {
990-
.$sb
991-
}
992-
$found = $fullPath
993-
break
920+
if ($_.Name -ne 'PSProfile.PowerTools') {
921+
$plugin = $_
922+
$this._log(
923+
"'$($plugin.Name)' Searching for plugin",
924+
'LoadPlugins',
925+
'Verbose'
926+
)
927+
try {
928+
$found = $null
929+
$importParams = @{
930+
ErrorAction = 'Stop'
931+
Global = $true
994932
}
995-
}
996-
if ($null -ne $found) {
997-
$this._log(
998-
"'$($plugin.Name)' plugin loaded from path: $found",
999-
'LoadPlugins',
1000-
'Verbose'
1001-
)
1002-
}
1003-
else {
1004-
if ($null -ne $plugin.Name -and $null -ne (Get-Module $plugin.Name -ListAvailable -ErrorAction SilentlyContinue)) {
1005-
Import-Module $plugin.Name @importParams
933+
if ($plugin.ArgumentList) {
934+
$importParams['ArgumentList'] = $plugin.ArgumentList
935+
}
936+
[string[]]$pathsToSearch = @($this.PluginPaths)
937+
$env:PSModulePath.Split([System.IO.Path]::PathSeparator) | ForEach-Object {
938+
$pathsToSearch += $_
939+
}
940+
foreach ($plugPath in $pathsToSearch) {
941+
$fullPath = [System.IO.Path]::Combine($plugPath,"$($plugin.Name).ps1")
1006942
$this._log(
1007-
"'$($plugin.Name)' plugin loaded from PSModulePath!",
1008-
'LoadPlugins'
943+
"'$($plugin.Name)' Checking path: $fullPath",
944+
'LoadPlugins',
945+
'Debug'
1009946
)
947+
if (Test-Path $fullPath) {
948+
$sb = [scriptblock]::Create($this._globalize(([System.IO.File]::ReadAllText($fullPath))))
949+
if ($plugin.ArgumentList) {
950+
.$sb($plugin.ArgumentList)
951+
}
952+
else {
953+
.$sb
954+
}
955+
$found = $fullPath
956+
break
957+
}
1010958
}
1011-
else {
959+
if ($null -ne $found) {
1012960
$this._log(
1013-
"'$($plugin.Name)' plugin not found! To remove this plugin from your profile, run 'Remove-PSProfilePlugin $($plugin.Name)'",
961+
"'$($plugin.Name)' plugin loaded from path: $found",
1014962
'LoadPlugins',
1015-
'Warning'
963+
'Verbose'
1016964
)
1017965
}
966+
else {
967+
if ($null -ne $plugin.Name -and $null -ne (Get-Module $plugin.Name -ListAvailable -ErrorAction SilentlyContinue)) {
968+
Import-Module $plugin.Name @importParams
969+
$this._log(
970+
"'$($plugin.Name)' plugin loaded from PSModulePath!",
971+
'LoadPlugins'
972+
)
973+
}
974+
else {
975+
$this._log(
976+
"'$($plugin.Name)' plugin not found! To remove this plugin from your profile, run 'Remove-PSProfilePlugin $($plugin.Name)'",
977+
'LoadPlugins',
978+
'Warning'
979+
)
980+
}
981+
}
982+
}
983+
catch {
984+
throw
1018985
}
1019986
}
1020-
catch {
1021-
throw
1022-
}
1023-
}
1024-
})
987+
})
1025988
}
1026989
else {
1027990
$this._log(

PSProfile/PSProfile.Aliases.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
'Save-Prompt' = 'Add-PSProfilePrompt'
66
'Get-Prompt' = 'Get-PSProfilePrompt'
77
'Edit-Prompt' = 'Edit-PSProfilePrompt'
8-
'Set-Prompt' = 'Switch-PSProfilePrompt'
98
'Switch-Prompt' = 'Switch-PSProfilePrompt'
109
'Remove-Prompt' = 'Remove-PSProfilePrompt'
1110
'Copy-DynamicParameters' = 'Copy-Parameters'

PSProfile/PSProfile.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'PSProfile.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.5.0'
15+
ModuleVersion = '0.6.0'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = @('Desktop','Core')

PSProfile/PSProfile.psm1

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
# If we're in an interactive shell, load the profile.
2-
if ([Environment]::UserInteractive -or ($null -eq [Environment]::UserInteractive -and $null -eq ([Environment]::GetCommandLineArgs() | Where-Object { $_ -like '-NonI*' }))) {
3-
$global:OriginalPrompt =
4-
$global:PSProfile = [PSProfile]::new()
5-
$global:PSProfile.Load()
6-
Export-ModuleMember -Variable PSProfile
7-
$global:PSProfileConfigurationWatcher = [System.IO.FileSystemWatcher]::new($(Split-Path $global:PSProfile.Settings.ConfigurationPath -Parent),'Configuration.psd1')
8-
$job = Register-ObjectEvent -InputObject $global:PSProfileConfigurationWatcher -EventName Changed -Action {
9-
[PSProfile]$conf = Import-Configuration -Name PSProfile -CompanyName 'SCRT HQ' -Verbose:$false
10-
$conf._internal = $global:PSProfile._internal
11-
$global:PSProfile = $conf
1+
$global:PSProfile = [PSProfile]::new()
2+
$global:PSProfile.Load()
3+
Export-ModuleMember -Variable PSProfile
4+
$global:PSProfileConfigurationWatcher = [System.IO.FileSystemWatcher]::new($(Split-Path $global:PSProfile.Settings.ConfigurationPath -Parent),'Configuration.psd1')
5+
$job = Register-ObjectEvent -InputObject $global:PSProfileConfigurationWatcher -EventName Changed -Action {
6+
[PSProfile]$conf = Import-Configuration -Name PSProfile -CompanyName 'SCRT HQ' -Verbose:$false
7+
$conf._internal = $global:PSProfile._internal
8+
$global:PSProfile = $conf
9+
}
10+
$PSProfile_OnRemoveScript = {
11+
try {
12+
$global:PSProfileConfigurationWatcher.Dispose()
1213
}
13-
$PSProfile_OnRemoveScript = {
14-
try {
15-
$global:PSProfileConfigurationWatcher.Dispose()
16-
}
17-
finally {
18-
Remove-Variable PSProfile -Scope Global -Force
19-
Remove-Variable PSProfileConfigurationWatcher -Scope Global -Force
20-
}
14+
finally {
15+
Remove-Variable PSProfile -Scope Global -Force
16+
Remove-Variable PSProfileConfigurationWatcher -Scope Global -Force
2117
}
22-
$ExecutionContext.SessionState.Module.OnRemove += $PSProfile_OnRemoveScript
23-
Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $PSProfile_OnRemoveScript
2418
}
19+
$ExecutionContext.SessionState.Module.OnRemove += $PSProfile_OnRemoveScript
20+
Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $PSProfile_OnRemoveScript

0 commit comments

Comments
 (0)