Giter Site home page Giter Site logo

Comments (8)

ivan-the-terrible avatar ivan-the-terrible commented on May 25, 2024

Looking at the Battery segment, it could be interesting to attach the logic there.

The main thing would be investigating how this works across operating systems. Looks like a creating a POC for Windows, but I could imagine something where you pass in a list within the omp.json of what you want to monitor, GIVEN there is some standardized way to query peripherals and their status.

@Marc013 would you be interesting in creating something using the Command segment that could theoretically handle this?

from oh-my-posh.

JanDeDobbeleer avatar JanDeDobbeleer commented on May 25, 2024

@ivan-the-terrible I feel this is a very specific use-case for now which would justify the use of Set-PoshContext and create multiple environment variables to add that context to and use in a text segment's template.

from oh-my-posh.

ivan-the-terrible avatar ivan-the-terrible commented on May 25, 2024

@JanDeDobbeleer oh nice! Yeah this would be a perfect use case for leveraging the template.

from oh-my-posh.

JanDeDobbeleer avatar JanDeDobbeleer commented on May 25, 2024

@ivan-the-terrible implementing this natively would also require finding the right syscall on Windows which is always a little challenging. There be dragons.

@Marc013 Can you proceed with my proposal above, or do you need a more elaborate sample?

from oh-my-posh.

Marc013 avatar Marc013 commented on May 25, 2024

@JanDeDobbeleer and @ivan-the-terrible ,
Thank you very much for you your quick response.

The purpose is to check the battery status of Bluetooth devices. In my opinion, this is a common use case as more and more devices are connected to Bluetooth.

Nevertheless, I tried the suggested Set-PoshContext solution.
Unfortunately, this is not an option because the pwsh command takes more than 1.5 seconds to execute, so the prompt is extremely delayed.

from oh-my-posh.

JanDeDobbeleer avatar JanDeDobbeleer commented on May 25, 2024

@Marc013 chances are this will take the same amount of time using golang (if I can find out how) as the underlying syscall will be identical.

from oh-my-posh.

Marc013 avatar Marc013 commented on May 25, 2024

Thank you for informing.
I will try to come up with an alternate solution.

from oh-my-posh.

JanDeDobbeleer avatar JanDeDobbeleer commented on May 25, 2024

@Marc013 you could run a scriptblock to assign the env vars (didn't test this):

$scriptblock = {
    $env:MOUSE_BATTERY_LEVEL = (Get-PnpDevice -Class Bluetooth -FriendlyName 'MX Master 3' | Get-PnpDeviceProperty -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2').Data
    $env:KEYBOARD_BATTERY_LEVEL = (Get-PnpDevice -Class Bluetooth -FriendlyName 'Keychron K3 Max' | Get-PnpDeviceProperty -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2').Data
}

function Set-BatteryLevels {
    Start-job -ScriptBlock $scriptblock
}

New-Alias -Name 'Set-PoshContext' -Value 'Set-BatteryLevels' -Scope Global -Force

from oh-my-posh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.