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

feat: AWS segment #380

Closed
2 tasks done
ppittle opened this issue Feb 5, 2021 · 21 comments
Closed
2 tasks done

feat: AWS segment #380

ppittle opened this issue Feb 5, 2021 · 21 comments
Labels
🤔 info needed Further information is requested

Comments

@ppittle
Copy link

ppittle commented Feb 5, 2021

Prerequisites

  • I have read and understand the CONTRIBUTING guide
  • I looked for duplicate issues before submitting this one

Description

Is it possible to have a local powershell variable display in a segment? (And be performant while doing so?)

I tried with the following segment which I want to write out $localVar:

 "segments": [  {
     "type": "command",
     "style": "plain",
     "powerline_symbol": "",
     "invert_powerline": false,
     "foreground": "#D4E157",
     "background": "#546E7A",
     "leading_diamond": "",
     "trailing_diamond": "",
     "properties": {
         "command": "echo $localVar"
      }
}]

But the command segment doesn't print anything:

image

Context:

For context, I'm basically trying to port the custom Prompt in this old aws blog on powershell for aws and port it to work inside oh-my-posh.

Environment

  • Oh my Posh version: 3.80.1
  • Theme:
  • Operating System: Windows
  • Shell: PowerShell Core
  • Terminal: Windows Terminal

Steps to Reproduce

  1. Set a powershell variable $localVar to test
  2. Create a theme with a command segmant like above.
  3. Run oh-my-posh

Expected behavior: Prompt reads local variable and displays test

Actual behavior: Test is not printed inside the Prompt

@JanDeDobbeleer
Copy link
Owner

2 things we can do:

  • there's a function called Set-PoshContext you can use to update environment variables for example. If you define a new env var and add the value of $localVar to it and use that in the envvar segment. The details are also indicated in those docs.
  • we build an AWS segment for this use-case

The first option will unblock you, the second one makes the most sense in the long run ;-)

@ppittle
Copy link
Author

ppittle commented Feb 6, 2021

I might be experimenting with an AWS segment :)

Curious if a custom segment would allow me access to local PowerShell variables though? Inside the segment running env.runShellCommand or env.runCommand doesn't seam to be able to access the value.

Would the custom segment still need to use the Set-PoshContext trick in the Prompt?

@JanDeDobbeleer
Copy link
Owner

@ppittle you can't access Powershell variables as that runs in a different process. You can call environment variables (AWS cli sets these) and display those or call that AWS cli directly.

@JanDeDobbeleer JanDeDobbeleer changed the title Question: Display powershell variable in segment feat: AWS segment Feb 7, 2021
@JanDeDobbeleer JanDeDobbeleer added the 🚀 feat New feature label Feb 7, 2021
JanDeDobbeleer added a commit that referenced this issue Feb 7, 2021
JanDeDobbeleer added a commit that referenced this issue Feb 7, 2021
@JanDeDobbeleer
Copy link
Owner

@ppittle can you check the latest version offers what you're looking for?

@JanDeDobbeleer JanDeDobbeleer added 🤔 info needed Further information is requested and removed 🚀 feat New feature labels Feb 11, 2021
@glucas
Copy link

glucas commented Feb 12, 2021

Trying this out on Win10 / pwsh 7.1.1 and not seeing anything shown for the AWS template. Just to clarify, this template will look for the $env:AWS_PROFILE and similar variables, right?

@JanDeDobbeleer
Copy link
Owner

@glucas yes, and the config file. How did you add the segment? Because I still have a bug in the docs 😅

@glucas
Copy link

glucas commented Feb 12, 2021

How did you add the segment? Because I still have a bug in the docs 😅

Ha, I just copied the example from the doc!

@JanDeDobbeleer
Copy link
Owner

That should be correct, did you update?

@ppittle
Copy link
Author

ppittle commented Feb 13, 2021

@JanDeDobbeleer that's fantastic!

image

I tweaked out the template to replace the @ with an orange amazon logo and dropped the prefix character:

{
    "type": "aws",
    "style": "powerline",
    "powerline_symbol": "",
    "invert_powerline": false,
    "foreground": "#100e23",
    "background": "#ffffff",
    "leading_diamond": "",
    "trailing_diamond": "",
    "properties": {                        
		"template": "{{.Profile}}{{if .Region}}<#F8991D>\uf52c</>{{.Region}}{{end}}"
    }
}

@JanDeDobbeleer
Copy link
Owner

Feel free to close this when your request is resolved.

@glucas
Copy link

glucas commented Feb 13, 2021

That should be correct, did you update?

Interesting, I get nothing. I grabbed the segment from the doc and added it to my theme. I'm setting $env:AWS_PROFILE and $env:AWS_REGION in my pwsh shell. I'll experiment further.

I can aws configure list and see profile and region are picked up from my shell. Created a theme with just path and aws segments, and only get the path. Strange.

@JanDeDobbeleer
Copy link
Owner

@glucas ok, but did you update oh-my-posh? Otherwise it won't work.

@glucas
Copy link

glucas commented Feb 15, 2021

Yes, this is my fault. I've been updating oh-my-posh3 via scoop to newer versions, but now realize I separately have the powershell module installed and that is on an older version. Once again, apologies for the noise!

Works great now - this is very useful, thanks for the great package.

@glucas
Copy link

glucas commented Feb 15, 2021

One possible enhancement for the AWS segment would be to only show when the profile is not 'default'. I think I can achieve something similar with if conditions in the template, however.

@JanDeDobbeleer
Copy link
Owner

@glucas not necessarily, that's an additional feature :-) But very doable indeed. I'll add it.

JanDeDobbeleer added a commit that referenced this issue Feb 18, 2021
JanDeDobbeleer added a commit that referenced this issue Feb 18, 2021
@JanDeDobbeleer
Copy link
Owner

@glucas added with the newly available display_default property.

@alefranz
Copy link

@glucas yes, and the config file. How did you add the segment? Because I still have a bug in the docs 😅

Hi Jan,
I'm trying to configure this, but it only seems to read the value from the env variables (AWS_PROFILE, AWS_REGION) but it doesn't seem to be loading the config file ~/.aws/config.

For example with AWS_PROFILE, the active profile should be the one called "default" from the config file, but it is not displayed.
When AWS_REGION is not set, the region selected should be the one of the active profile (either "default" or the one specified in the AWS_PROFILE variable).

Could you clarify how the config is loaded?

I think it would also be nice to get a status if the authentication is valid or expired, and extra infromations like the account connected and so on, essentially to get something like the output of aws sts get-caller-identity CLI command. Should I create a ticket for this feature request?

@JanDeDobbeleer
Copy link
Owner

@alefranz allow me to explain in the morning 😉 (you can read it here). About using the aws command, that's discouraged as it's really slow (tried it).

@alefranz
Copy link

@alefranz allow me to explain in the morning 😉 (you can read it here). About using the aws command, that's discouraged as it's really slow (tried it).

Appreciate the quick reply, but take your time 😂 not urgent at all!
I had a look at the code, but that logic is somehow not working for me on pwsh on Windows.
I'll get the repo and try to see if I can debug it.

@glucas
Copy link

glucas commented Feb 24, 2021

@alefranz For what it's worth, I am running pwsh and when I enable the AWS segment it in fact shows me the default profile name and region, with no AWS variables set:
image

In my case I'd prefer to only see this for non-default values but that should be a separate feature request, I'll file it.

@JanDeDobbeleer
Copy link
Owner

@glucas you can set the property display_default to false to get that result.

JanDeDobbeleer added a commit that referenced this issue Mar 8, 2021
JanDeDobbeleer added a commit that referenced this issue Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 info needed Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants