starship icon indicating copy to clipboard operation
starship copied to clipboard

Error when using battery module on Android Termux: Error in 'StarshipRoot' at 'battery': Unknown key

Open nikelborm opened this issue 2 years ago • 2 comments

Current Behavior

On my notebook, I have starship installed. It works without any warnings. I copied notebook's config into Termux on my Pixel 4 XL. And after that when I login it shows such warning (and battery percentage indicator doesn't work)

[WARN] - (starship::config): Failed to load config value: Error in 'StarshipRoot' at 'battery': Unknown key

Phone's prompt does not have battery info

u0_a291 in 🌐 localhost in ~ on 🌱 main 
❯ 

Expected Behavior

When I login on termux, warning does not show up and in my prompt I see my battery percentage as on my notebook:

~ on 🌱 main 
💀97% ❯ phone

Motivation for this is when users don't have direct or easy access to their phones, and they log into their phones via ssh to see some info like battery charge percent.

Additional context/Screenshots

Version of starship package in termux:

u0_a291 in 🌐 localhost in ~ on 🌱 main took 4s 
❯ apt show starship
Package: starship
Version: 1.11.0
Maintainer: @termux
Installed-Size: 7647 kB
Depends: openssl, zlib
Homepage: https://starship.rs
Download-Size: 2140 kB
APT-Manual-Installed: yes
APT-Sources: https://packages.termux.dev/apt/termux-main stable/main aarch64 Packages
Description: A minimal, blazing fast, and extremely customizable prompt for any shell

Version of starship on my notebook:

- Starship version: 1.6.3
- bash version: GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
- Operating system: OracleLinux 18.0.0
- Terminal emulator: <unknown terminal> <unknown version>
- Git Commit Hash: 0a9fabe1
- Branch/Tag: v1.6.3
- Rust Version: rustc 1.60.0 (7737e0b5c 2022-04-04)
- Rust channel: stable-x86_64-unknown-linux-gnu release
- Build Time: 2022-04-27 08:20:44 +00:00

Possible Solution

Termux has the solution to use android APIs from CLI present as termux-api package:

u0_a291 in 🌐 localhost in ~ on 🌱 main 
✗ apt install termux-api
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  termux-api
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 22.0 kB of archives.
After this operation, 295 kB of additional disk space will be used.
Get:1 https://packages.termux.dev/apt/termux-main stable/main aarch64 termux-api aarch64 0.57 [22.0 kB]
Fetched 22.0 kB in 2s (12.2 kB/s)
Selecting previously unselected package termux-api.
(Reading database ... 10060 files and directories currently installed.)
Preparing to unpack .../termux-api_0.57_aarch64.deb ...
Unpacking termux-api (0.57) ...
Setting up termux-api (0.57) ...

u0_a291 in 🌐 localhost in ~ on 🌱 main took 2s 
❯ termux-battery-status
{
  "health": "GOOD",
  "percentage": 100,
  "plugged": "UNPLUGGED",
  "status": "DISCHARGING",
  "temperature": 34.70000076293945,
  "current": -404375
}

Environment in termux

  • Starship version: 1.11.0
  • bash version: GNU bash, version 5.2.9(1)-release (aarch64-unknown-linux-android)
  • Operating system: Android 13
  • Terminal emulator: termux version
  • Git Commit Hash:
  • Branch/Tag:
  • Rust Version: rustc 1.64.0 (a55dd71d5 2022-09-19)
  • Rust channel: 1.64.0-x86_64-unknown-linux-gnu release
  • Build Time: 2022-10-15 09:49:48 +00:00

Relevant Shell Configuration

❯ termux-info
Termux Variables:
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages.termux.dev/apt/termux-main/ stable main
Updatable packages:
pcre2/stable 10.40-1 aarch64 [upgradable from: 10.40]
termux-tools version:
1.31.0
Android version:
13
Kernel build information:
Linux localhost 4.14.276-gecab2e0c9918-ab8931408 #1 SMP PREEMPT Wed Aug 10 20:40:15 UTC 2022 aarch64 Android
Device manufacturer:
Google
Device model:
Pixel 4 XL

Starship Configuration

add_newline = false

[sudo]
style = "bold green"
symbol = "👩‍💻 cached_sudo"
disabled = false

[battery]
full_symbol = "🔋"
charging_symbol = "⚡️"
discharging_symbol = "💀"

[[battery.display]]
threshold = 15
style = "bold red"

[[battery.display]]  # "bold yellow" style when capacity is between 15% and 50%
threshold = 50
style = "bold yellow"

[[battery.display]]
threshold = 99
style = "bold green"

[character]
# symbol = "➜"
error_symbol = "✗"

[git_state]
cherry_pick = "🍒 PICKING"

[git_branch]
symbol = "🌱 "
truncation_length = 4
truncation_symbol = ""

[git_status]
conflicted = "🏳"
ahead = "🏎💨"
behind = "😰"
diverged = "😵"
untracked = "🤷‍"
stashed = "📦"
modified = "📝"
staged = "➕"
renamed = "👅"
deleted = "🗑"

[python]
symbol = "🐍 "
pyenv_version_name = true

[hostname]
style = "bold bright-green"
ssh_only = true
disabled = false

[time]
disabled = true
format = "🕙 %T "
utc_time_offset = 2
style = "white"

nikelborm avatar Nov 13 '22 19:11 nikelborm

I think this is going to be because the version you are using on your phone has been compiled without support for the battery module (this is an optional feature).

edit yep this has been removed in the termux package because the battery crate doesn't support termux.

andytom avatar Nov 27 '22 15:11 andytom

cargo install --no-default-features starship

ahaoboy avatar Apr 18 '24 14:04 ahaoboy