Last active 1731171802

xbl-arch.sh Raw
1#!/bin/sh
2# Archlinux version
3# integer scheck inspired from: https://stackoverflow.com/a/16444570
4#
5# Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com>
6
7print_usage () {
8 echo >&2 "usage: $(basename ${0}) [0..100]"
9 exit 1
10}
11
12# check if argument given or not (list or set value)
13if [ $# -eq 1 ]
14then
15 # set value (select between ac or bat mode)
16 # check if argument is integer between 0,100
17 case $1 in
18 (*[!0-9]*|'')
19 print_usage
20 exit
21 ;;
22 (*)
23 if [ "$1" -ge 0 ] && [ "$1" -le 100 ] 2>/dev/null
24 then
25 # argument given and between 0,100
26 case $( cat /sys/class/power_supply/AC/online ) in
27
28 (0) # BATTERY
29 echo "$1" > ${HOME}/.backlight-bat
30 ;;
31
32 (1) # AC
33 echo "$1" > ${HOME}/.backlight-ac
34 ;;
35
36 esac
37 blight set ${1}%
38 else
39 # arg not between 0 and 100
40 print_usage
41 fi
42 ;;
43 esac
44else
45 # no args given, only list values
46 case $( cat /sys/class/power_supply/AC/online ) in
47 (0) # BATTERY
48 current=bat
49 ;;
50 (1) # AC
51 current=ac
52 ;;
53 esac
54
55 # 100% 24242
56
57 for status in ac bat
58 do
59 if [ "${status}" = "${current}" ]
60 then
61 echo -e "${status}: ★ \t$( cat ${HOME}/.backlight-${status} )" | tr "[:lower:]" "[:upper:]"
62 else
63 echo -e "${status}:\t$( cat ${HOME}/.backlight-${status} )" | tr "[:lower:]" "[:upper:]"
64 fi
65 done
66 value=$(python -c "print(round(100/24242*`blight get`))")
67 echo -e "CUR:\t$(python -c "print($value)")"
68fi
69