-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreensaverbar
executable file
·131 lines (112 loc) · 2.78 KB
/
screensaverbar
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/sh
_cols=$(tput cols)
halfcol=$(( _cols / 2 ))
# Usage: getval "KEY" file
# Return: string
# Description:
# Read a KEY=VALUE file and retrieve the Value of the passed KEY
getval(){
# Setting 'IFS' tells 'read' where to split the string.
while IFS='=' read -r key val; do
# Skip over lines containing comments.
# (Lines starting with '#').
[ "${key##\#*}" ] || continue
# '$key' stores the key.
# '$val' stores the value.
if [ "$key" = "$1" ]; then
printf '%s\n' "$val"
fi
done < "$2"
}
# ~/.config/better-xsecurelock/
CONFIG_DIR="${XDG_CONFIG_HOME:-~/.config}/better-xsecurelock"
#config file
CONF="${CONFIG_DIR}/config"
bat_icon=""
FANCY_BAT_ICON=""
FANCY_BAT_ICON=$(getval "FANCY_BAT_ICON" "$CONF")
if [ -n "$FANCY_BAT_ICON" ]; then
bat1i=
bat2i=
bat3i=
bat4i=
bat5i=
else
bat1i=▁
bat2i=▂
bat3i=▄
bat4i=▆
bat5i=█
fi
getbat() {
bat_level=$(cat /sys/class/power_supply/BAT0/capacity)
case "$bat_level" in
[0-9]|1[0-9])
bat_icon="$bat1i"
;;
2[0-9]|3[0-9])
bat_icon="$bat2i"
;;
4[0-9]|5[0-9])
bat_icon="$bat3i"
;;
6[0-9]|7[0-9])
bat_icon="$bat4i"
;;
8[0-9]|9[0-9]|100)
bat_icon="$bat5i"
;;
esac
printf '%s %3s' "$bat_icon" "${bat_level}%"
}
wbat=6
wday=10
wtime=8
spaces=6
padding=$(( halfcol - (( wday + wtime + wbat + spaces ) / 2 ) ))
[ -z "$AuthFgColor" ] && AuthFgColor="#c1c1c3"
AuthFgColor="${AuthFgColor#*#}"
fgr=$(printf '0x%0.2s\n' "${AuthFgColor}")
fgr=$(printf '%d\n' "$fgr")
fgg=$(printf '0x%0.2s\n' "${AuthFgColor#??}")
fgg=$(printf '%d\n' "$fgg")
fgb=$(printf '0x%0.2s\n' "${AuthFgColor#????}")
fgb=$(printf '%d\n' "$fgb")
[ -z "$AuthBgColor" ] && AuthBgColor="#5f7397"
AuthBgColor="${AuthBgColor#*#}"
bgr=$(printf '0x%0.2s\n' "${AuthBgColor}")
bgr=$(printf '%d\n' "$bgr")
bgg=$(printf '0x%0.2s\n' "${AuthBgColor#??}")
bgg=$(printf '%d\n' "$bgg")
bgb=$(printf '0x%0.2s\n' "${AuthBgColor#????}")
bgb=$(printf '%d\n' "$bgb")
# fgcol="${fgr};${fgg};${fgb}"
# bgcol="${bgr};${bgg};${bgb}"
# esc='\033'
# echo $_cols
exit_handler() {
printf '\33[?25h'
}
hex_wid=$(printf '0x%08x\n' "$WINDOWID")
ontop () {
xdotool windowraise "$hex_wid"
}
printf '\33[?25l'
cont=1
while [ "$cont" = 1 ]; do
ontop
cday=$(date '+%Y %m %d')
ctime=$(date '+%T')
cbat="$(getbat)"
printf ' %*s ' "$wday" "$cday"
printf '%*s' "$padding" " "
printf '\033[38;2;%s;%s;%sm' "${fgr}" "${fgg}" "${fgb}"
printf '\033[48;2;%s;%s;%sm' "${bgr}" "${bgg}" "${bgb}"
printf ' %*s ' "$wtime" "$ctime"
printf '\033[0m'
printf '%*s' "$padding" " "
printf ' %*s ' "$wbat" "$cbat"
printf '\r'
sleep 0.5
done
trap 'exit_handler' EXIT