Created
January 6, 2025 14:48
-
-
Save sagittarius-a/c3595870f3b908606c98faaa6b25660c to your computer and use it in GitHub Desktop.
Fish right prompt: Display battery level (Linux)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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