=Fix profile listing mechanism

This commit is contained in:
Gilad Plex 2022-01-29 16:35:26 -05:00
parent 685077b250
commit cdabbc7858
3 changed files with 24 additions and 15 deletions

View File

@ -386,7 +386,9 @@ function _Init {
[switch]$NoReloadScripts
)
. LoadProfileCodeFunctions
$local:LoadMissing = ". LoadProfileCodeFunctions"
if( Test-Path function:ProfileCode_cleanup ) { $LoadMissing = "#" }
. Invoke-Expression $LoadMissing
if ( -not $NoGitAction ) {
if ( -not [bool]$(Get-Command git -ErrorAction SilentlyContinue) ) {
@ -437,22 +439,20 @@ function _Init {
if( $_profile ) {
$_profiles += ,$_profile
} else {
$_profiles = $PROFILE | fl * -Force | Out-String -Stream | ForEach-Object {
$local:p = $($_ -split ' : [/A-Z\\]');
if ( $p[0] -match 'User' ) {
$p[0].Trim()
}
}
$_profiles = $PROFILE | Get-Member -Type NoteProperty |
Select-Object -ExpandProperty Name
$_profile = $profile.CurrentUserAllHosts;
if ( $sudo -or $(Test-IsAdmin) ) { $_profile = $profile.AllUsersAllHosts }
}
Write-Verbose $( $_profiles | Out-String )
Write-Verbose $( $_profile | Out-String )
if ( $RemoveOnly -and $ConfirmPreference -eq 'High' -and (-not $PSBoundParameters -or -not $PSBoundParameters.ContainsKey('Confirm')) ) {
$script:ConfirmPreference = 'Low'
}
$_profiles | Foreach-Object {
$local:p = $profile."$_"
$local:p = Invoke-Expression "`$profile.$_"
if( -not $p ) { $p = $_ }
$local:profileContent = $randomSeed;
$local:exists = Test-Path $p
@ -579,7 +579,9 @@ if( $WriteInitScript ) {
_Init @PSBoundParameters
}
. ProfileCode_cleanup
if( Test-Path function:ProfileCode_cleanup ) {
. ProfileCode_cleanup
}
if( $NoReloadScripts ) { return }

View File

@ -2,12 +2,14 @@
[switch]$AsDictionary
)
filter ConvertTo-Hash { param([string]$Property="Name") begin { $hash = @{} } process{ $hash[$_."$Property"] = $_ } end {return $hash} }
filter ConvertTo-Hash { param([string]$Property='Name') begin { $hash = @{} } process{ $hash[$_."$Property"] = $_ } end {return $hash} }
$local:rVal = $PROFILE | fl * -Force | Out-String -Stream | Where-Object { $_ -match '( : /)|(:\\)' } |
Select-Object @{
N="Profile";E={($_ -split ": ")[0].Trim()}
},@{N="Path";E={($_ -split ": ")[-1].Trim()}
} | Select-Object *,@{N="Exists";E={Test-Path $_.Path}}
$local:rVal = $PROFILE | Get-Member -Type NoteProperty |
Select-Object -ExpandProperty Name |
Select-Object @{
N='Profile';E={$_}
},@{N='Path';E={$PROFILE."$_"}
} |
Select-Object *,@{N="Exists";E={Test-Path $_.Path}}
if( $AsDictionary ) { return $rVal | ConvertTo-Hash -Property "Profile" }
return $rVal

View File

@ -10,6 +10,11 @@
"/zsys": "/etc/zsys.conf",
"shrc": "~/.shrc",
"sz-aliases-sh": "~/.sz.aliases.sh",
"szload": [
"@shell-loading-snippets/zsh",
"@shell-loading-snippets/bash",
"@shell-loading-snippets/sh"
],
"sz-shrc": [
"~/.sz.shrc.sh",
"#shrc",