Skip to content

Instantly share code, notes, and snippets.

@sagittarius-a
Created January 6, 2025 14:48
Show Gist options
  • Select an option

  • Save sagittarius-a/c3595870f3b908606c98faaa6b25660c to your computer and use it in GitHub Desktop.

Select an option

Save sagittarius-a/c3595870f3b908606c98faaa6b25660c to your computer and use it in GitHub Desktop.
Fish right prompt: Display battery level (Linux)
# Requires `inxi` package to be installed
function fish_right_prompt -d "Write out the right prompt"
# Get battery percentage and status
set level (inxi --battery | python -c "import sys, re; input = sys.stdin.read(); line = input.split()[6]; print(re.sub('[()]', '', line))")
set battery_status (upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "state:" | awk '{ print $2 }')
# Define colors
# Normal colors
# black, red, green, yellow, blue, magenta, cyan, white
# Bright colors
# brblack, brred, brgreen, bryellow, brblue, brmagenta, brcyan, brwhite
set color_normal white
set color_charging yellow
set color_discharging red
set color_fully_charged green
# Determine color based on charging state
switch $battery_status
case "charging"
set color $color_charging
set icon πŸ”Œ
case "discharging"
set color $color_discharging
set icon πŸ”‹
case "fully-charged"
set color $color_fully_charged
set icon βœ…
case "*"
set color $color_normal
set icon ❔
end
# Display battery percentage
echo -e (set_color $color) "[ $level $icon ]" (set_color normal)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment