@@ -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- }
9456class 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 (
0 commit comments