├── .gitignore ├── README.md ├── bain ├── example └── Arch.png └── images ├── arch.png ├── debian.png └── manjaro.png /.gitignore: -------------------------------------------------------------------------------- 1 | background.png 2 | out.png 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bain - the battery indicator 2 | 3 | ![Arch Example](example/Arch.png) 4 | \*green: discharge, yellow: charge, red: battery percentage < 30% 5 | 6 | ## How to use? 7 | 8 | * Make sure you have these programs installed on your machine: [git](https://git-scm.com/), [imagemagick](https://imagemagick.org), and [feh](https://feh.finalrewind.org). 9 | 10 | * Clone the repository into `~/.bain` 11 | 12 | ```bash 13 | git clone https://github.com/amirashabani/bain ~/.bain 14 | ``` 15 | 16 | * Make it executable 17 | 18 | ```bash 19 | chmod +x ~/.bain/bain 20 | ``` 21 | 22 | * Copy it to `/usr/local/bin`, so that the command is recognized by your terminal. Make sure to run it with `sudo`. 23 | ```bash 24 | sudo cp ~/.bain/bain /usr/local/bin 25 | ``` 26 | 27 | * Run the script from your startup file (e.g. `.xinitrc`). Make sure to use `&` at the end of the command as it is a blocking script. 28 | ```bash 29 | bain arch & 30 | ``` 31 | 32 | * Restart your X session (log out and log back in). 33 | ```bash 34 | pkill X 35 | ``` 36 | -------------------------------------------------------------------------------- /bain: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | create_and_set() { 4 | original_image=$1 5 | battery_percentage=$2 6 | battery_status=$3 7 | image_size=`identify -format '%wx%h' $original_image` 8 | 9 | if [[ "$battery_status" == "Charging" ]]; then 10 | color='#FFFF00' 11 | else 12 | if [ "$battery_percentage" -ge 30 ]; then 13 | color='#5BC236' 14 | else 15 | color='#BF131C' 16 | fi 17 | fi 18 | convert $original_image \ 19 | \( +clone -gravity South -crop x$battery_percentage% -fuzz 50% -fill $color -opaque '#8FBCBB' -background transparent -extent $image_size \) \ 20 | -gravity Center -composite -background '#2E3440' -extent 3840x2160 $tmp_directory/background.png 21 | 22 | feh --no-fehbg --bg-scale $tmp_directory/background.png 23 | } 24 | 25 | find_battery_path() { 26 | local file 27 | for file in /sys/class/power_supply/*; do 28 | read power_supply < "$file"/type 29 | if [ "$power_supply" = "Battery" ]; then 30 | declare -r battery_found=1 31 | echo "$file" 32 | break 33 | fi 34 | done 35 | 36 | if [ -z "$battery_found" ]; then 37 | echo "Couldn't find battery" 38 | exit 1 39 | fi 40 | 41 | } 42 | 43 | tmp_directory=/tmp/bain 44 | mkdir -p $tmp_directory 45 | 46 | file="$HOME/.bain/images/$1.png" 47 | battery_path=$(find_battery_path) 48 | last_capacity=`< $battery_path/capacity` 49 | last_status=`< $battery_path/status` 50 | create_and_set $file $last_capacity $last_status 51 | 52 | while true 53 | do 54 | current_capacity=`< $battery_path/capacity` 55 | current_status=`< $battery_path/status` 56 | 57 | if [[ "$current_capacity" != "$last_capacity" ]] || [[ "$current_status" != "$last_status" ]] 58 | then 59 | create_and_set $file $current_capacity $current_status 60 | last_capacity=$current_capacity 61 | last_status=$current_status 62 | fi 63 | sleep 5 64 | done 65 | -------------------------------------------------------------------------------- /example/Arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amishbni/bain/29200235922de8710dac5c54296d8b77e33952dd/example/Arch.png -------------------------------------------------------------------------------- /images/arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amishbni/bain/29200235922de8710dac5c54296d8b77e33952dd/images/arch.png -------------------------------------------------------------------------------- /images/debian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amishbni/bain/29200235922de8710dac5c54296d8b77e33952dd/images/debian.png -------------------------------------------------------------------------------- /images/manjaro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amishbni/bain/29200235922de8710dac5c54296d8b77e33952dd/images/manjaro.png --------------------------------------------------------------------------------