OSDN Git Service

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