This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brit
executable file
·110 lines (95 loc) · 2.15 KB
/
brit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
#
# ||''\ ||''. '||' ['|']
# ||--< ||-+' || |
# ||__/ || \ .||. .|
#
# Description: A minimal brightness manager
# Dependencies: xbacklight
# Optionnal dependencies: notf
# Author: gawlk
# Contributors: none
# ---
# SETUP
# ---
IFS=$'\n'
ps=( $( ps -ax | grep "brit" ) )
# ---
# LOCAL
# ---
brit.args() {
local current=$( brit.current )
case "$1" in
"+" | "inc" )
if [[ $current -le 2 ]]
then
xbacklight -set 5
elif [[ $current -le 15 ]]
then
xbacklight -inc 5
elif [[ $current -le 50 ]]
then
xbacklight -inc 10
elif [[ $current -ge 60 ]]
then
xbacklight -inc 20
fi
;;
"-" | "dec" )
if [[ $current -le 5 ]]
then
xbacklight -set 2
elif [[ $current -gt 60 ]]
then
xbacklight -dec 20
elif [[ $current -gt 20 ]]
then
xbacklight -dec 10
elif [[ $current -gt 5 ]]
then
xbacklight -dec 5
fi
;;
"=" | "rst" )
xbacklight -set 30
;;
esac
}
brit.current() {
local value=$(xbacklight -get)
printf '%d\n' "${value%.*}"
}
brit.get_percentage() {
local current=$( brit.current )
local percentage
if [[ $current == 2 ]]
then
percentage=0
elif [[ $current -le 20 ]]
then
percentage=$(( ( current / 5 ) * 10 ))
elif [[ $current -le 60 ]]
then
percentage=$(( current + 20 ))
elif [[ $current == 80 ]]
then
percentage=90
elif [[ $current -gt 80 ]]
then
percentage=$current
fi
printf '%d\n' "$percentage"
}
# ---
# MAIN
# ---
brit.main() {
brit.args "$1"
local message="Brightness: $( brit.get_percentage )%"
notf "$message" &> /dev/null || printf '%s\n' "$message"
}
# ---
# LAUNCH
# ---
# Only if no other instance of brit is already executed
[[ ${#ps[@]} -lt 4 ]] && brit.main "$1"