-
Notifications
You must be signed in to change notification settings - Fork 2
/
daemons
executable file
·36 lines (30 loc) · 1021 Bytes
/
daemons
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
#!/bin/bash
# Finds and removes unwanted daemons and agents.
if echo "$*" | grep -Eq -- '--help\b|-h\b' || [[ -z $1 ]]; then
echo "usage: ${0##*/} [-h|--help] [PATTERN|FILE_PATH]" >&2
exit 1
fi
# shellcheck source=../.shell_control
# shellcheck disable=1091
source "$HOME/.shell_control" || echo "$(tput bold)error: ~/.shell_control not installed!$(tput sgr0)" >&2
# Creating an empty temporary workspace so that a given PATTERN will
# never accidentally match a FILE_PATH in the current working directory.
wd="$(mktemp -d -t tmp.XXXXXXXXXX)"
trap 'rm -rf $wd' EXIT
cd "$wd" || abort "could not create workspace"
if [[ ! -e $1 ]]; then
find \
/Library/LaunchAgents \
/Library/LaunchDaemons \
/System/Library/LaunchAgents \
/System/Library/LaunchDaemons \
~/Library/LaunchAgents \
~/Library/LaunchDaemons \
-type f \
2>/dev/null |
grep -Ei "$@"
else
run "sudo launchctl unload -w '$1'"
run "sudo rm -f '$1'"
fi
rm -rf "$wd"