OSDN Git Service

red battery indicator on low charge
[instantos/instantOS.git] / autostart.sh
1 #!/usr/bin/env bash
2
3 ####################################################
4 ## script for paperbenni-dwm autostart            ##
5 ####################################################
6
7 bashes=$(pgrep bash | wc -l)
8 if [ "$bashes" -gt 2 ]; then
9         echo "already running"
10         exit
11 fi
12
13 if acpi | grep -q '%'; then
14         export ISLAPTOP="true"
15         echo "laptop detected"
16 else
17         echo "not a laptop"
18 fi
19
20 if command -v picom &>/dev/null; then
21         picom &
22 else
23         compton &
24 fi
25
26 sleep 1
27
28 if command -v deadd &>/dev/null; then
29         if ! pgrep deadd; then
30                 while :; do
31                         deadd
32                         sleep 30
33                 done &
34         fi
35 fi
36
37 # chrome os wallpaper changer
38 [ -e /home/benjamin/paperbenni/menus/dm/wg.sh ] &&
39         bash /home/benjamin/paperbenni/menus/dm/wg.sh
40
41 [ -e /home/benjamin/paperbenni/monitor.sh ] &&
42         bash /home/benjamin/paperbenni/monitor.sh
43
44 # apply german keybpard layout
45 if locale | grep -q 'de_DE'; then
46         setxkbmap -layout de
47 fi
48
49 # laptop specific background jobs
50 if [ -n "$ISLAPTOP" ]; then
51         command -v libinput-gestures \
52                 &>/dev/null &&
53                 libinput-gestures &
54         nm-applet &
55 fi
56
57 INTERNET="X"
58
59 REPETITIONS="xxxxxx"
60
61 command -v conky &>/dev/null && conky &
62
63 date=""
64
65 addstatus() {
66         date="$date[$@] "
67 }
68
69 # status bar loop
70 while :; do
71         if [ -e ~/.dwmsilent ]; then
72                 sleep 1m
73                 continue
74         fi
75
76         # run every 60 seconds
77         if [ "$REPETITIONS" = "xxxxxx" ]; then
78                 REPETITIONS="x"
79                 if ping -q -c 1 -W 1 8.8.8.8; then
80                         INTERNET="i"
81                 else
82                         INTERNET="^c#ff0000^X^d^"
83                 fi
84
85                 # battery indicator on laptop
86                 if [ -n "$ISLAPTOP" ]; then
87                         TMPBAT=$(acpi)
88                         if [[ $TMPBAT =~ "Charging" ]]; then
89                                 BATTERY="^c#00ff00^B"$(egrep -o '[0-9]*%' <<<"$TMPBAT")"^d^"
90                         else
91                                 BATTERY="B"$(egrep -o '[0-9]*%' <<<"$TMPBAT")
92                                 # make indicator red on low battery
93                                 if [ $(grep '[0-9]*' <<<$BATTERY) -lt 10 ]; then
94                                         BATTERY="^c#ff0000^$BATTERY^d^"
95                                 fi
96                         fi
97                 fi
98
99         else
100                 # increase counter
101                 REPETITIONS="$REPETITIONS"x
102         fi
103
104         addstatus "$(date +'%d-%m|%H:%M')"
105         addstatus "A$(amixer get Master | egrep -o '[0-9]{1,3}%' | head -1)"
106         [ -n "$ISLAPTOP" ] && addstatus "$BATTERY"
107         addstatus "$INTERNET"
108
109         xsetroot -name "$date"
110         date=""
111
112         sleep 10
113 done