-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconky.sh
More file actions
executable file
·96 lines (76 loc) · 1.84 KB
/
conky.sh
File metadata and controls
executable file
·96 lines (76 loc) · 1.84 KB
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
#!/usr/bin/env bash
# Ensure bash even if called with sh
[ -z "$BASH_VERSION" ] && exec bash "$0" "$@"
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR" || exit 1
ACTION="${1:-start}"
# --------------------------------------------------
# Functions
# --------------------------------------------------
stop_conky() {
if pgrep -x conky >/dev/null; then
echo "[Conky] Stopping..."
pkill conky
sleep 1
# fallback (force)
if pgrep -x conky >/dev/null; then
echo "[Conky] Force stopping..."
pkill -9 conky
fi
echo "[Conky] Stopped."
else
echo "[Conky] Not running."
fi
}
start_conky() {
# Prevent multiple instances
if pgrep -x conky >/dev/null; then
echo "[Conky] Already running."
return
fi
# Init weather
bash "$DIR/init.sh"
STATUS=$?
if [ "$STATUS" -eq 2 ]; then
echo "[Conky] Weather disabled (not configured)"
elif [ "$STATUS" -ne 0 ]; then
echo "[Conky] Weather initialization failed"
fi
# Detect resolution
RES=$(xrandr 2>/dev/null | awk '/ primary/ {print $4}' | sed 's/+.*//')
if [ -z "$RES" ]; then
RES=$(xrandr 2>/dev/null | awk '/ connected/ {print $3}' | sed 's/+.*//' | sort -nr | head -n1)
fi
[ -z "$RES" ] && RES="2560x1440"
WIDTH=$(echo "$RES" | cut -d'x' -f1)
# Select config
if [ "$WIDTH" -ge 2560 ]; then
CONFIG="$DIR/conkyrc/.conkyrc_2k"
else
CONFIG="$DIR/conkyrc/.conkyrc_1080p"
fi
echo "[Conky] Detected resolution: $RES"
echo "[Conky] Starting with config: $CONFIG"
conky -c "$CONFIG" &
}
# --------------------------------------------------
# Dispatcher
# --------------------------------------------------
case "$ACTION" in
start)
start_conky
;;
stop)
stop_conky
;;
restart)
stop_conky
sleep 1
start_conky
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0