forked from Homebrew/homebrew-cask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_installed_launchjob_ids
executable file
·90 lines (67 loc) · 2 KB
/
list_installed_launchjob_ids
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
#!/bin/bash
#
# list_installed_launchjob_ids
#
###
### settings
###
set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions
###
### global variables
###
# prefer GNU xargs
xargs="$(/usr/bin/which gxargs || printf '/usr/bin/xargs')"
###
### functions
###
launchjob_id_source_1 () {
/usr/bin/find ~/Library/LaunchAgents/ \
~/Library/LaunchDaemons/ \
/Library/LaunchAgents/ \
/Library/LaunchDaemons/ \
-type f -print0 2>/dev/null | \
"$xargs" -0 /usr/bin/perl -0777 -ne \
'while (m{<key>\s*Label\s*</key>\s*<string>([^<]+?)</string>}sg) { print "$1\n" }'
}
merge_sources () {
/usr/bin/sort | /usr/bin/uniq
}
clean_sources () {
/usr/bin/egrep -v '^com\.apple\.'
}
mark_up_sources () {
/usr/bin/perl -pe 's{\n}{\000}sg' | \
"$xargs" -0 -I{} -n1 /bin/bash -c \
'printf "{}"; /bin/launchctl list "{}" >/dev/null 2>&1 && printf " (+)"; printf "\n"'
}
###
### main
###
_list_installed_launchjob_ids () {
{
launchjob_id_source_1;
} | \
merge_sources | \
clean_sources | \
mark_up_sources
}
# process args
if [[ $1 =~ ^-+h(elp)?$ ]]; then
printf "list_installed_launchjob_ids
List all installed launchjob IDs, which may be useful
in a Cask uninstall stanza, eg
uninstall launchctl: 'job.id.goes.here'
Launchctl jobs attributed to Apple will be ommitted.
If a launchctl job is currently loaded, and visible to the current
user, it will be followed by a plus symbol '(+)' in the output.
This can be verified via the command
/bin/launchctl list 'job.id.goes.here'
See CONTRIBUTING.md and 'man launchctl' for more information.
"
exit
fi
# dispatch main
_list_installed_launchjob_ids "${@}"
#