Closed ppittle closed 3 years ago
2 things we can do:
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.The first option will unblock you, the second one makes the most sense in the long run ;-)
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?
@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.
@ppittle can you check the latest version offers what you're looking for?
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?
@glucas yes, and the config file. How did you add the segment? Because I still have a bug in the docs 😅
How did you add the segment? Because I still have a bug in the docs 😅
Ha, I just copied the example from the doc!
That should be correct, did you update?
@JanDeDobbeleer that's fantastic!
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}}"
}
}
Feel free to close this when your request is resolved.
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.
@glucas ok, but did you update oh-my-posh? Otherwise it won't work.
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.
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.
@glucas not necessarily, that's an additional feature :-) But very doable indeed. I'll add it.
@glucas added with the newly available display_default
property.
@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?
@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 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.
@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:
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.
@glucas you can set the property display_default
to false
to get that result.
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.
Prerequisites
CONTRIBUTING
guideDescription
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
:But the command segment doesn't print anything:
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
Steps to Reproduce
$localVar
totest
Expected behavior: Prompt reads local variable and displays
test
Actual behavior:
Test
is not printed inside the Prompt