all repos — dotfiles @ d59fbd2ea4d9ba33287b8b53ae0f69eb543f4ffb

my *nix dotfiles

nix/bin/battery.nix (view raw)

 1{ pkgs, ... }:
 2
 3let
 4  name = "bat";
 5in
 6pkgs.writeScriptBin name
 7  ''
 8    red="\e[31m"
 9    grn="\e[32m"
10    ylw="\e[33m"
11    cyn="\e[36m"
12    blu="\e[34m"
13    prp="\e[35m"
14    bprp="\e[35;1m"
15    rst="\e[0m"
16
17    bat_status=""
18    bat_status=$( cat /sys/class/power_supply/BAT0/capacity )
19    charging_status=$( cat /sys/class/power_supply/BAT0/status )
20
21    health() {
22    for i in {0..4}
23    do
24        if [[ $i -le $(( $bat_status/20 )) ]]; then
25            echo -ne "#[fg=colour1]· "
26        else
27            echo -ne "#[fg=colour8]· "
28        fi
29    done
30    echo
31    }
32
33    bat_status_small() {
34    if [[ "$charging_status" = *Charging* ]]; then
35        echo -ne "+$bat_status%"
36    else
37        echo -ne "$bat_status%"
38    fi
39    }
40
41    [ -z "$1" ] && {
42    bat_status_small
43    }
44
45    while getopts qi options 
46    do
47    case $options in
48        i)
49            bat_status_small
50            ;;
51        q)
52            if [[ "$charging_status" = *Charging* ]]; then
53                echo -ne "+ $(health)"
54            else
55                health
56            fi
57    esac
58    done
59  ''