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

Hide battery segment when no information. #26

Closed
AjayKMehta opened this issue Sep 27, 2020 · 9 comments
Closed

Hide battery segment when no information. #26

AjayKMehta opened this issue Sep 27, 2020 · 9 comments

Comments

@AjayKMehta
Copy link
Contributor

First of all, ❤️ this module! Finally switched over from oh-my-posh 🙂

I like your default theme (jandedobbeleer) but it shows "BATT ERR" on my desktop because no battery info, of course. IMHO it's better to not display the segment if no info but others may disagree.

To cater for both cases, it would be great if you could optionally specify a condition (scriptblock that returns boolean for example) for each segment in the JSON config that determines if the segment gets displayed or not.

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Sep 27, 2020

I could add a switch to the properties which would allow this. For example:

"hide_error": true

Not sure if I want to make a general switch, I do get where you're coming from but it can get confusing.

What's also an option is to remove the segment from the theme altogether. A quick copy-paste, adjust and setting that as the theme will also hide it forever. Although that might take away its portability.

@AjayKMehta
Copy link
Contributor Author

hide_error works.

I get your point about the general switch as it may open a can of worms. I like the idea of being able to dynamically determine visibility of a segment based on condition but embedding PowerShell code in JSON is quite ugly and no point in creating your own DSL for this 😀

@AjayKMehta
Copy link
Contributor Author

@JanDeDobbeleer, one use case for a general switch or config setting for segment visibility is the following:

Say I want to add an 💾 indicator in my prompt to show that (Get-PSReadLineOption).HistorySaveStyle is set to SaveIncrementally or SaveAtExit and remove it if it's not set?

@JanDeDobbeleer
Copy link
Owner

You could achieve that with a custom command segment. That one accepts a shell command (and the shell to run it in, here being powershell) . If the command outputs a value, it will show that value.

@AjayKMehta
Copy link
Contributor Author

I created a theme (cool.json) with a command segment as suggested:

https://gist.github.com/AjayKMehta/1b5324a485a9db6e7d326276ab5786cf

The command is specified as "if ((Get-PSReadLineOption).HistorySaveStyle -ne 'SaveNothing'){'💾'} else {''}"

It seems to run the command the first time and not work subsequently. Even if I disable saving via Set-PSReadLineOption -HistorySaveStyle SaveNothing, I still see 💾 in the prompt.

Any help would be appreciated. Thanks.

JanDeDobbeleer added a commit that referenced this issue Sep 28, 2020
@JanDeDobbeleer
Copy link
Owner

It should not save state but run the command every time. I'll check!

@JanDeDobbeleer
Copy link
Owner

I can reproduce this. As this is ran on a new instance of pwsh, it will only work IF this is set globally via for example your $PROFILE. Let me see if I can make it so it runs directly in your shell (which could break if you don't know what you're doing).

@AjayKMehta
Copy link
Contributor Author

Thanks. That's what I figured as I tried changing the command to Get-Date and it worked fine.

@JanDeDobbeleer
Copy link
Owner

Be aware the new version is now known as Oh my Posh V3 :-)

Install-Module oh-my-posh -Scope CurrentUser -AllowPrerelease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants