Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCP Segment never disabled state #2810

Closed
1 task done
GavinOsborn opened this issue Sep 20, 2022 · 4 comments
Closed
1 task done

GCP Segment never disabled state #2810

GavinOsborn opened this issue Sep 20, 2022 · 4 comments
Assignees
Labels
🐛 bug Something isn't working

Comments

@GavinOsborn
Copy link
Sponsor Contributor

Code of Conduct

  • I agree to follow this project's Code of Conduct

What happened?

Most contextual segments (kubectl, az, aws, dotnet, etc) do not render anything if they have no active context - from what I can tell from the source code (I don't really understand Go) this is toggled through the Enabled() function of each segment.

The GCP segment behaves differently when no active context - or even when the tool isn't installed at all. The GCP segment always renders something. When testing on my workstation the default template will render the error NO ACTIVE CONFIG FOUND.

Given the behavior of the other segments I presume this is not the desired behavior?

Theme

{
    "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
    "blocks": [
        {
            "alignment": "left",
            "newline": false,
            "segments": [
                {
                    "background": "#000000",
                    "foreground": "#ffffff",
                    "type": "gcp",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b4"
                },
                {
                    "background": "#000000",
                    "foreground": "#ffffff",
                    "type": "aws",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b4"
                },
                {
                    "background": "#000000",
                    "foreground": "#ffffff",
                    "type": "az",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b4"
                }
            ],
            "type": "prompt"
        }
    ],
    "version": 2
}

What OS are you seeing the problem on?

Windows

Which shell are you using?

bash, powershell

Log output

�[1mVersion:�[0m 9.0.0

�[1mSegments:�[0m

ConsoleTitle(false) -   0 ms - 
gcp(true)  -   0 ms - �[38;2;0;0;0;49m�[7m�[0m�[48;2;0;0;0m�[38;2;255;255;255m NO ACTIVE CONFIG FOUND �[0m
aws(false) -   0 ms - 
az(false)  -   0 ms - 

�[1mRun duration:�[0m 39.318ms

�[1mCache path:�[0m C:\Users\OsbornG\AppData\Local\oh-my-posh

�[1mConfig path:�[0m C:/Users/OsbornG/code/gav/oh-my-posh-themes/gcp-repro.omp.json

�[1mLogs:�[0m

2022/09/20 11:28:30 debug: Getenv
C:\Users\OsbornG\AppData\Local
2022/09/20 11:28:30 Getenv duration: 0s, args: LOCALAPPDATA
2022/09/20 11:28:30 CachePath duration: 0s, args: 
2022/09/20 11:28:30 debug: Getenv
C:/Users/OsbornG/code/gav/oh-my-posh-themes/gcp-repro.omp.json
2022/09/20 11:28:30 Getenv duration: 0s, args: POSH_THEME
2022/09/20 11:28:30 Shell duration: 15.9947ms, args: 
2022/09/20 11:28:30 resolveConfigPath duration: 15.9947ms, args: 
2022/09/20 11:28:30 Init duration: 37.3403ms, args: 
2022/09/20 11:28:30 Flags duration: 0s, args: 
2022/09/20 11:28:30 config.loadConfig duration: 0s, args: 
2022/09/20 11:28:30 Flags duration: 0s, args: 
2022/09/20 11:28:30 debug: Getenv

2022/09/20 11:28:30 Getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/09/20 11:28:30 WindowsRegistryKeyValue duration: 0s, args: HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 debug: WindowsRegistryKeyValue
ColorizationColor(DWORD): 0xC40078D7
2022/09/20 11:28:30 Root duration: 978.2µs, args: 
2022/09/20 11:28:30 Shell duration: 0s, args: 
2022/09/20 11:28:30 ErrorCode duration: 0s, args: 
2022/09/20 11:28:30 IsWsl duration: 0s, args: 
2022/09/20 11:28:30 debug: Pwd
C:\Users\OsbornG
2022/09/20 11:28:30 Pwd duration: 0s, args: 
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 debug: User
OsbornG
2022/09/20 11:28:30 User duration: 0s, args: 
2022/09/20 11:28:30 debug: Host
MEL-PF3NJR4W
2022/09/20 11:28:30 Host duration: 0s, args: 
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 TemplateCache duration: 978.2µs, args: 
2022/09/20 11:28:30 Flags duration: 0s, args: 
2022/09/20 11:28:30 debug: Pwd
C:\Users\OsbornG
2022/09/20 11:28:30 Pwd duration: 0s, args: 
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 debug: Getenv

2022/09/20 11:28:30 Getenv duration: 0s, args: CLOUDSDK_CONFIG
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 error: FileContent
open C:\Users\OsbornG\.config\gcloud\active_config: The system cannot find the path specified.
2022/09/20 11:28:30 FileContent duration: 999.5µs, args: C:\Users\OsbornG\.config\gcloud\active_config
2022/09/20 11:28:30 TemplateCache duration: 0s, args: 
2022/09/20 11:28:30 TemplateCache duration: 0s, args: 
2022/09/20 11:28:30 Shell duration: 0s, args: 
2022/09/20 11:28:30 debug: Pwd
C:\Users\OsbornG
2022/09/20 11:28:30 Pwd duration: 0s, args: 
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 debug: Getenv

2022/09/20 11:28:30 Getenv duration: 0s, args: AWS_VAULT
2022/09/20 11:28:30 debug: Getenv

2022/09/20 11:28:30 Getenv duration: 0s, args: AWS_PROFILE
2022/09/20 11:28:30 debug: Getenv

2022/09/20 11:28:30 Getenv duration: 0s, args: AWS_REGION
2022/09/20 11:28:30 debug: Getenv

2022/09/20 11:28:30 Getenv duration: 0s, args: AWS_DEFAULT_REGION
2022/09/20 11:28:30 debug: Getenv

2022/09/20 11:28:30 Getenv duration: 0s, args: AWS_CONFIG_FILE
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 error: FileContent
open C:\Users\OsbornG/.aws/config: The system cannot find the file specified.
2022/09/20 11:28:30 FileContent duration: 0s, args: C:\Users\OsbornG/.aws/config
2022/09/20 11:28:30 debug: Pwd
C:\Users\OsbornG
2022/09/20 11:28:30 Pwd duration: 0s, args: 
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 GOOS duration: 0s, args: 
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 debug: Getenv

2022/09/20 11:28:30 Getenv duration: 0s, args: AZURE_CONFIG_DIR
2022/09/20 11:28:30 debug: HasFolder
true
2022/09/20 11:28:30 HasFolder duration: 0s, args: C:\Users\OsbornG\.azure
2022/09/20 11:28:30 debug: FileContent
{"installationId": "83f7df66-1c68-11ed-872b-701ab85953a2", "subscriptions": []}
2022/09/20 11:28:30 FileContent duration: 0s, args: C:\Users\OsbornG\.azure\azureProfile.json
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 debug: Home
C:\Users\OsbornG
2022/09/20 11:28:30 debug: HasFolder
true
2022/09/20 11:28:30 HasFolder duration: 0s, args: C:\Users\OsbornG\.azure
2022/09/20 11:28:30 debug: FileContent
{
  "DefaultContextKey": "Default",
  "EnvironmentTable": {},
  "Contexts": {},
  "ExtendedProperties": {}
}
2022/09/20 11:28:30 FileContent duration: 0s, args: C:\Users\OsbornG\.azure\AzureRmContext.json
2022/09/20 11:28:30 debug: Getenv
C:\Users\OsbornG\AppData\Local
2022/09/20 11:28:30 Getenv duration: 0s, args: LOCALAPPDATA
2022/09/20 11:28:30 CachePath duration: 0s, args: 
2022/09/20 11:28:30 Flags duration: 0s, args:
@GavinOsborn GavinOsborn added the 🐛 bug Something isn't working label Sep 20, 2022
@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Sep 20, 2022

@GavinOsborn this isn't a bug but by design. The segment has the following template:

"template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Project }}{{ end }} "

Changing it to this will have the behaviour you're looking for:

"template": "{{ if not .Error }} {{ .Project }} {{ end }}"

One could argue that should be the default template, and I agree.

@GavinOsborn
Copy link
Sponsor Contributor Author

Thanks @JanDeDobbeleer for the rapid turn around as always.

I have everything I need to go on - but in the interest of completeness I would still suggest that you haven't actually aligned segment behavior.

Consider the following theme:

{
    "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
    "blocks": [
        {
            "alignment": "left",
            "newline": false,
            "segments": [
                {
                    "background": "red",
                    "foreground": "green",
                    "type": "aws",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b4",
                    "template": " \uE7AD "
                },
                {
                    "background": "blue",
                    "foreground": "yellow",
                    "type": "gcp",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b4",
                    "template": " \uE7B2 "
                },
                {
                    "background": "white",
                    "foreground": "black",
                    "type": "az",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b4",
                    "template": " \ufd03 "
                }
            ],
            "type": "prompt"
        }
    ],
    "version": 2
}

Were I to deploy this theme onto a workstation where nether of the az, aws or gcp tooling were installed or had no configured context then the az and aws segments would not render the template but the gcp segment would.

I'm not going to reopen the issue - I just leave this here for your consideration.

Thanks again

@JanDeDobbeleer
Copy link
Owner

@GavinOsborn fair point. The error state isn't something that exists elsewhere. I agree it doesn't make sense as if something goes wrong, the debug logs are what's needed.

JanDeDobbeleer added a commit that referenced this issue Sep 23, 2022
aligns the segment with az and aws, relates to #2810

BREAKING CHANGE: this removes the .Error field from the segment template
which means anyone with a custom template in the gcp segment needs to
remove it from their template. The new default template is:

`" {{ .Project }} "`
JanDeDobbeleer added a commit that referenced this issue Sep 23, 2022
aligns the segment with az and aws, relates to #2810

BREAKING CHANGE: this removes the .Error field from the segment template
which means anyone with a custom template in the gcp segment needs to
remove it from their template. The new default template is:

`" {{ .Project }} "`
Copy link

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants