xbl-openbsd.sh
· 1.5 KiB · Bash
Raw
#!/bin/sh
# OpenBSD 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 $( sysctl -n hw.power ) in
(0) # BATTERY
echo "$1" > ${HOME}/.backlight-bat
;;
(1) # AC
echo "$1" > ${HOME}/.backlight-ac
;;
esac
doas wsconsctl display.brightness=$1
else
# arg not between 0 and 100
print_usage
fi
;;
esac
else
# no args given, only list values
case $( sysctl -n hw.power ) in
(0) # BATTERY
current=bat
;;
(1) # AC
current=ac
;;
esac
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
echo -e "CUR:\t$(doas wsconsctl display.brightness | awk -F= '{ print $2 }')"
fi
1 | #!/bin/sh |
2 | # OpenBSD 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 $( sysctl -n hw.power ) 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 | doas wsconsctl display.brightness=$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 $( sysctl -n hw.power ) in |
47 | (0) # BATTERY |
48 | current=bat |
49 | ;; |
50 | (1) # AC |
51 | current=ac |
52 | ;; |
53 | esac |
54 | |
55 | for status in ac bat |
56 | do |
57 | if [ "${status}" = "${current}" ] |
58 | then |
59 | echo -e "${status}: ★ \t$( cat ${HOME}/.backlight-${status} )" | tr "[:lower:]" "[:upper:]" |
60 | else |
61 | echo -e "${status}:\t$( cat ${HOME}/.backlight-${status} )" | tr "[:lower:]" "[:upper:]" |
62 | fi |
63 | done |
64 | echo -e "CUR:\t$(doas wsconsctl display.brightness | awk -F= '{ print $2 }')" |
65 | fi |
66 |