JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.01k stars 2.37k forks source link

Battery info not working. #2479

Closed bend-n closed 2 years ago

bend-n commented 2 years ago

Code of Conduct

What happened?

Battery problems.

2022/07/03 08:31:45 error: BatteryInfo
[{Design:read /sys/class/power_supply/BAT0/energy_full_design: no such device}]

Unable to use the battery segment

Theme

{
  "type": "battery",
  "style": "powerline",
  "powerline_symbol": "\uE0B0",
  "foreground": "#193549",
  "background": "#ffeb3b",
  "background_templates": [
    "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}",
    "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}",
    "{{if eq \"Full\" .State.String}}#4caf50{{end}}"
  ],
  "template": " {{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}\uF295 ",
  "properties": {
    "discharging_icon": "\uE231 ",
    "charging_icon": "\uE234 ",
    "charged_icon": "\uE22F "
  }
}

What OS are you seeing the problem on?

Linux

Which shell are you using?

No response

Log output

Version: 8.10.2

Segments:

ConsoleTitle(true)   -  15 ms - fish::BAT0
session(true)        -   0 ms -  bendn@klunk 
path(true)           -   0 ms -   BAT0 
command(false)       -  18 ms - 
executiontime(true)  -   0 ms -  羽0ms 
exit(true)           -   0 ms -   
shell(true)          -   0 ms -   fish 
command(true)        -  65 ms -  08:36滛  (26.99°C) feels 30.6°C (c) 

Run duration: 104.807921ms

Cache path: /home/bendn/.cache/oh-my-posh

Config path: /home/bendn/prompt.omp.json

Logs:

2022/07/03 08:36:47 debug: Getenv

2022/07/03 08:36:47 Getenv duration: 24.784µs, args: XDG_CACHE_HOME
2022/07/03 08:36:47 CachePath duration: 77.725µs, args: 
2022/07/03 08:36:47 debug: Getenv
/home/bendn/prompt.omp.json
2022/07/03 08:36:47 Getenv duration: 4.872µs, args: POSH_THEME
2022/07/03 08:36:47 resolveConfigPath duration: 12.494µs, args: 
2022/07/03 08:36:47 Init duration: 235.226µs, args: 
2022/07/03 08:36:47 Flags duration: 352ns, args: 
2022/07/03 08:36:47 config.loadConfig duration: 969.806µs, args: 
2022/07/03 08:36:47 Flags duration: 95ns, args: 
2022/07/03 08:36:47 debug: Getenv

2022/07/03 08:36:47 Getenv duration: 2.861µs, args: OMP_CACHE_DISABLED
2022/07/03 08:36:47 Root duration: 1.814µs, args: 
2022/07/03 08:36:47 Shell duration: 14.945025ms, args: 
2022/07/03 08:36:47 ErrorCode duration: 146ns, args: 
2022/07/03 08:36:47 debug: Getenv

2022/07/03 08:36:47 Getenv duration: 4.779µs, args: WSL_DISTRO_NAME
2022/07/03 08:36:47 IsWsl duration: 10.839µs, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 65.751µs, args: 
2022/07/03 08:36:47 PathSeparator duration: 158ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 64ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 65ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 50ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 50ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 48ns, args: 
2022/07/03 08:36:47 debug: User
bendn
2022/07/03 08:36:47 User duration: 2.321µs, args: 
2022/07/03 08:36:47 debug: Host
klunk
2022/07/03 08:36:47 Host duration: 7.747µs, args: 
2022/07/03 08:36:47 GOOS duration: 100ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 15.155159ms, args: 
2022/07/03 08:36:47 Flags duration: 303ns, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 4.282µs, args: 
2022/07/03 08:36:47 GOOS duration: 83ns, args: 
2022/07/03 08:36:47 debug: Getenv

2022/07/03 08:36:47 Getenv duration: 2.572µs, args: SSH_CONNECTION
2022/07/03 08:36:47 debug: Getenv

2022/07/03 08:36:47 Getenv duration: 1.852µs, args: SSH_CLIENT
2022/07/03 08:36:47 TemplateCache duration: 119ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 228ns, args: 
2022/07/03 08:36:47 Shell duration: 344ns, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 4.491µs, args: 
2022/07/03 08:36:47 GOOS duration: 90ns, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 1.773µs, args: 
2022/07/03 08:36:47 Flags duration: 174ns, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 3.089µs, args: 
2022/07/03 08:36:47 GOOS duration: 106ns, args: 
2022/07/03 08:36:47 GOOS duration: 57ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 72ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 63ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 49ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 48ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 48ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 49ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 48ns, args: 
2022/07/03 08:36:47 PathSeparator duration: 142ns, args: 
2022/07/03 08:36:47 GOOS duration: 49ns, args: 
2022/07/03 08:36:47 debug: Getenv

2022/07/03 08:36:47 Getenv duration: 2.121µs, args: WSL_DISTRO_NAME
2022/07/03 08:36:47 IsWsl duration: 5.218µs, args: 
2022/07/03 08:36:47 StackCount duration: 165ns, args: 
2022/07/03 08:36:47 error: DirIsWritable
User doesn't have permission to write to this directory
2022/07/03 08:36:47 DirIsWritable duration: 38.311µs, args: 
2022/07/03 08:36:47 TemplateCache duration: 103ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 210ns, args: 
2022/07/03 08:36:47 Shell duration: 198ns, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 4.331µs, args: 
2022/07/03 08:36:47 GOOS duration: 91ns, args: 
2022/07/03 08:36:47 HasCommand duration: 61.597µs, args: bash
2022/07/03 08:36:47 debug: RunCommand

2022/07/03 08:36:47 RunCommand duration: 18.307775ms, args: bash -c git_branch
2022/07/03 08:36:47 RunShellCommand duration: 18.322224ms, args: bash git_branch
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 4.46µs, args: 
2022/07/03 08:36:47 GOOS duration: 141ns, args: 
2022/07/03 08:36:47 ExecutionTime duration: 244ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 359ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 291ns, args: 
2022/07/03 08:36:47 Shell duration: 390ns, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 3.441µs, args: 
2022/07/03 08:36:47 GOOS duration: 138ns, args: 
2022/07/03 08:36:47 ErrorCode duration: 106ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 97ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 226ns, args: 
2022/07/03 08:36:47 Shell duration: 410ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 290ns, args: 
2022/07/03 08:36:47 Flags duration: 145ns, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 5.057µs, args: 
2022/07/03 08:36:47 GOOS duration: 163ns, args: 
2022/07/03 08:36:47 Shell duration: 299ns, args: 
2022/07/03 08:36:47 Flags duration: 191ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 115ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 224ns, args: 
2022/07/03 08:36:47 Shell duration: 195ns, args: 
2022/07/03 08:36:47 debug: Pwd
/sys/class/power_supply/BAT0
2022/07/03 08:36:47 Pwd duration: 4.179µs, args: 
2022/07/03 08:36:47 GOOS duration: 173ns, args: 
2022/07/03 08:36:47 HasCommand duration: 1.672µs, args: bash
2022/07/03 08:36:47 debug: RunCommand
08:36滛  (26.99°C) feels 30.6°C (c)
2022/07/03 08:36:47 RunCommand duration: 65.054707ms, args: bash -c weather
2022/07/03 08:36:47 RunShellCommand duration: 65.070544ms, args: bash weather
2022/07/03 08:36:47 TemplateCache duration: 361ns, args: 
2022/07/03 08:36:47 TemplateCache duration: 220ns, args: 
2022/07/03 08:36:47 Shell duration: 540ns, args: 
2022/07/03 08:36:47 debug: Getenv

2022/07/03 08:36:47 Getenv duration: 16.857µs, args: XDG_CACHE_HOME
2022/07/03 08:36:47 CachePath duration: 118.726µs, args: 
2022/07/03 08:36:47 Flags duration: 119ns, args: 
JanDeDobbeleer commented 2 years ago

@bend-n to troubleshoot, can you give me the full content of the /sys/class/power_supply/ folder? Thanks!

bend-n commented 2 years ago
 cd /sys/class/power_supply/BAT0
 tree
.
├── alarm
├── capacity
├── capacity_level
├── cycle_count
├── device -> ../../../PNP0C0A:00
├── energy_full
├── energy_full_design
├── energy_now
├── hwmon2
│   ├── device -> ../../BAT0
│   ├── in0_input
│   ├── name
│   ├── power
│   │   ├── autosuspend_delay_ms
│   │   ├── control
│   │   ├── runtime_active_time
│   │   ├── runtime_status
│   │   └── runtime_suspended_time
│   ├── subsystem -> ../../../../../../../../../../class/hwmon
│   └── uevent
├── manufacturer
├── model_name
├── power
│   ├── autosuspend_delay_ms
│   ├── control
│   ├── runtime_active_time
│   ├── runtime_status
│   └── runtime_suspended_time
├── power_now
├── present
├── serial_number
├── status
├── subsystem -> ../../../../../../../../../class/power_supply
├── technology
├── type
├── uevent
├── voltage_min_design
└── voltage_now
JanDeDobbeleer commented 2 years ago

@bend-n I should've specified as a zip file, I need the actual folder (sys/class/power_supply) and files so I can use this to run the logic on. Sorry.

bend-n commented 2 years ago

bat0.zip

JanDeDobbeleer commented 2 years ago

@bend-n thx, I can reproduce it. Will try to fix this later today.

JanDeDobbeleer commented 2 years ago

@bend-n let me know if this works. I might have just refactored too much.

bend-n commented 2 years ago

@JanDeDobbeleer It works! ... Mostly.. Its always on the "charging_icon", even when fully charged, it wont change to the "charged_icon". Its a minor thing, which I can fix with a bunch of ifs, but still. Also, where is the documentation for the if statement? (nvm, found @https://ohmyposh.dev/docs/configuration/templates#template-logic)

JanDeDobbeleer commented 2 years ago

@bend-n hmm, it could mean the state isn't properly provided. 'll see if I can debug that one.

github-actions[bot] commented 8 months ago

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.