diff --git a/src/segments/az.go b/src/segments/az.go index b093eb97..93d46ce1 100644 --- a/src/segments/az.go +++ b/src/segments/az.go @@ -15,8 +15,6 @@ type Az struct { AzureSubscription Origin string - - configDir string } const ( @@ -103,11 +101,6 @@ func (a *Az) Init(props properties.Properties, env environment.Environment) { func (a *Az) Enabled() bool { source := a.props.GetString(Source, firstMatch) - var err error - a.configDir, err = a.ConfigDir() - if err != nil { - return false - } switch source { case firstMatch: return a.getCLISubscription() || a.getModuleSubscription() @@ -127,7 +120,11 @@ func (a *Az) FileContentWithoutBom(file string) string { func (a *Az) getCLISubscription() bool { var content string - profile := filepath.Join(a.configDir, "azureProfile.json") + configDir, err := a.ConfigDir(true) + if err != nil { + return false + } + profile := filepath.Join(configDir, "azureProfile.json") if content = a.FileContentWithoutBom(profile); len(content) == 0 { return false } @@ -147,8 +144,12 @@ func (a *Az) getCLISubscription() bool { func (a *Az) getModuleSubscription() bool { var content string + configDir, err := a.ConfigDir(false) + if err != nil { + return false + } profiles := []string{ - filepath.Join(a.configDir, "AzureRmContext.json"), + filepath.Join(configDir, "AzureRmContext.json"), } for _, profile := range profiles { if content = a.FileContentWithoutBom(profile); len(content) != 0 { @@ -180,12 +181,14 @@ func (a *Az) getModuleSubscription() bool { return true } -func (a *Az) ConfigDir() (string, error) { +func (a *Az) ConfigDir(cli bool) (string, error) { configDirs := []string{ - a.env.Getenv("AZURE_CONFIG_DIR"), filepath.Join(a.env.Home(), ".azure"), filepath.Join(a.env.Home(), ".Azure"), } + if cli { + configDirs = append([]string{a.env.Getenv("AZURE_CONFIG_DIR")}, configDirs...) + } for _, dir := range configDirs { if len(dir) != 0 && a.env.HasFolder(dir) { return dir, nil diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1 index 68daa0f5..cd186221 100644 --- a/src/shell/scripts/omp.ps1 +++ b/src/shell/scripts/omp.ps1 @@ -235,7 +235,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { } else { $themes | ForEach-Object -Process { Write-Host "Theme: $(Get-FileHyperlink -uri $_.FullName -Name ($_.BaseName -replace '\.omp$', ''))`n" - @(Start-Utf8Process $script:OMPExecutable @("print", "primary", "--config=$($_.FullName)", "--pwd=$PWD", "--shell=pwsh")) + @(Start-Utf8Process $script:OMPExecutable @("print", "primary", "--config=$($_.FullName)", "--pwd=$PWD", "--shell=::SHELL::")) Write-Host "`n" } }