xbl-arch.sh
· 1.5 KiB · Bash
Raw
#!/bin/sh
# Archlinux version
# integer scheck inspired from: https://stackoverflow.com/a/16444570
#
# Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com>
print_usage () {
echo >&2 "usage: $(basename ${0}) [0..100]"
exit 1
}
# check if argument given or not (list or set value)
if [ $# -eq 1 ]
then
# set value (select between ac or bat mode)
# check if argument is integer between 0,100
case $1 in
(*[!0-9]*|'')
print_usage
exit
;;
(*)
if [ "$1" -ge 0 ] && [ "$1" -le 100 ] 2>/dev/null
then
# argument given and between 0,100
case $( cat /sys/class/power_supply/AC/online ) in
(0) # BATTERY
echo "$1" > ${HOME}/.backlight-bat
;;
(1) # AC
echo "$1" > ${HOME}/.backlight-ac
;;
esac
blight set ${1}%
else
# arg not between 0 and 100
print_usage
fi
;;
esac
else
# no args given, only list values
case $( cat /sys/class/power_supply/AC/online ) in
(0) # BATTERY
current=bat
;;
(1) # AC
current=ac
;;
esac
# 100% 24242
for status in ac bat
do
if [ "${status}" = "${current}" ]
then
echo -e "${status}: ★ \t$( cat ${HOME}/.backlight-${status} )" | tr "[:lower:]" "[:upper:]"
else
echo -e "${status}:\t$( cat ${HOME}/.backlight-${status} )" | tr "[:lower:]" "[:upper:]"
fi
done
value=$(python -c "print(round(100/24242*`blight get`))")
echo -e "CUR:\t$(python -c "print($value)")"
fi
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 | |
7 | print_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) |
13 | if [ $# -eq 1 ] |
14 | then |
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 |
44 | else |
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)")" |
68 | fi |
69 |