Last active 1731171844

xbl-openbsd.sh Raw
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
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 $( 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
44else
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 }')"
65fi
66