OSDN Git Service

dbus pbnotify
[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 mkdir -p /tmp/notifications &>/dev/null
29 if ! pgrep dbus-monitor; then
30         while :; do
31                 dbus-monitor "interface='org.freedesktop.Notifications'" >/tmp/notifications/notif.txt
32                 sleep 10
33         done &
34 fi
35
36 if ! pgrep dunst; then
37         while :; do
38                 dunst
39                 sleep 10
40         done &
41 fi
42
43 [ -e /home/benjamin/paperbenni/monitor.sh ] &&
44         bash /home/benjamin/paperbenni/monitor.sh &
45
46 # chrome os wallpaper changer
47 [ -e /home/benjamin/paperbenni/menus/dm/wg.sh ] &&
48         bash /home/benjamin/paperbenni/menus/dm/wg.sh &
49
50 # apply german keybpard layout
51 if locale | grep -q 'de_DE'; then
52         setxkbmap -layout de
53 fi
54
55 # laptop specific background jobs
56 if [ -n "$ISLAPTOP" ]; then
57         command -v libinput-gestures \
58                 &>/dev/null &&
59                 libinput-gestures &
60         nm-applet &
61 fi
62
63 INTERNET="X"
64
65 REPETITIONS="xxxxxx"
66
67 command -v conky &>/dev/null && conky &
68
69 date=""
70
71 addstatus() {
72         date="$date[$@] "
73 }
74
75 # status bar loop
76 while :; do
77         if [ -e ~/.dwmsilent ]; then
78                 sleep 1m
79                 continue
80         fi
81
82         # run every 60 seconds
83         if [ "$REPETITIONS" = "xxxxxx" ]; then
84                 REPETITIONS="x"
85                 if ping -q -c 1 -W 1 8.8.8.8; then
86                         INTERNET="i"
87                 else
88                         INTERNET="^c#ff0000^X^d^"
89                 fi
90
91                 # battery indicator on laptop
92                 if [ -n "$ISLAPTOP" ]; then
93                         TMPBAT=$(acpi)
94                         if [[ $TMPBAT =~ "Charging" ]]; then
95                                 BATTERY="^c#00ff00^B"$(egrep -o '[0-9]*%' <<<"$TMPBAT")"^d^"
96                         else
97                                 BATTERY="B"$(egrep -o '[0-9]*%' <<<"$TMPBAT")
98                                 # make indicator red on low battery
99                                 if [ $(grep '[0-9]*' <<<$BATTERY) -lt 10 ]; then
100                                         BATTERY="^c#ff0000^$BATTERY^d^"
101                                 fi
102                         fi
103                 fi
104
105         else
106                 # increase counter
107                 REPETITIONS="$REPETITIONS"x
108         fi
109
110         addstatus "$(date +'%d-%m|%H:%M')"
111         addstatus "A$(amixer get Master | egrep -o '[0-9]{1,3}%' | head -1)"
112         [ -n "$ISLAPTOP" ] && addstatus "$BATTERY"
113         addstatus "$INTERNET"
114
115         xsetroot -name "$date"
116         date=""
117
118         sleep 10
119 done