This repository was archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers
More file actions
59 lines (50 loc) · 1.16 KB
/
helpers
File metadata and controls
59 lines (50 loc) · 1.16 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
#!/bin/bash
anywait(){
for pid in "$@"; do
while kill -0 "$pid" 2> /dev/null; do
echo -n "."
sleep 0.5
done
done
}
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "%s" "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
}
mac_find_active_service() {
services="$(networksetup -listnetworkserviceorder | grep 'Hardware Port')"
while read -r line; do
sname="$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $2}')"
sdev="$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $4}')"
#echo "Current service: $sname, $sdev, $currentservice"
if [ -n "$sdev" ]; then
ifconfig "$sdev" 2>/dev/null | grep 'status: active' > /dev/null 2>&1
rc="$?"
if [ "$rc" -eq 0 ]; then
currentservice="$sname"
fi
fi
done <<< "$services"
if [ -n "$currentservice" ]; then
echo "$currentservice"
else
>&2 echo "Could not find current service"
exit 1
fi
}
mac_notify() {
/usr/bin/osascript -e "display notification \"$*\""
}
detect_os() {
echo $(uname -s)
}