-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.sh
executable file
·68 lines (56 loc) · 1.27 KB
/
services.sh
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
#!/bin/bash
# Declare array of services and pretty human readable names
declare -a services=(
"com.apple.Safari"
"com.google.Chrome"
"spotify"
"com.docker"
"slack"
)
declare -a serviceNames=(
"Safari"
"Chrome"
"Spotify"
"Docker"
"Slack"
)
declare -a serviceStatus=()
# Get status of all my services
for service in "${services[@]}"
do
status=`launchctl list | grep "$service"`
if [[ ! -z $status ]]; then
serviceStatus+=("active")
else
serviceStatus+=("inactive")
fi
done
# Maximum column width
#width=$((49-2))
width=70
# Current line and line length
line=" "
lineLen=0
echo ""
echo "Services running:"
for i in ${!serviceStatus[@]}
do
# Next line and next line length
next=" ${serviceNames[$i]}: \e[5m${serviceStatus[$i]}"
nextLen=$((1+${#next}))
# If the current line will exceed the max column with then echo the current line and start a new line
if [[ $((lineLen+nextLen)) -gt width ]]; then
printf "$line\n"
lineLen=0
line=" "
fi
lineLen=$((lineLen+nextLen))
# Color the next line green if it's active, else red
if [[ "${serviceStatus[$i]}" == "active" ]]; then
line+="\e[32m\e[0m${serviceNames[$i]}: \e[32m● ${serviceStatus[$i]}\e[0m "
else
line+="${serviceNames[$i]}: \e[31m▲ ${serviceStatus[$i]}\e[0m "
fi
done
# echo what is left
printf "$line\n"