cdotfis-mac/dotfiles/.local/bin/service.sh

41 lines
678 B
Bash
Executable File

#!/usr/bin/env bash
usage() {
cat << EOF
usage: ${0##*/} [command]
-h Print this help message.
-e Start (load) agent or daemon.
-d Stop (unload) agent or daemon.
-u If it is a user agent or daemon.
EOF
}
runScript() {
while getopts ':he:d:u' flag; do
case $flag in
h)
usage
exit 0
;;
e)
action="sudo launchctl load -w $(realpath $2)"
;;
d)
action="sudo launchctl unload -w $(realpath $2)"
;;
u)
action="${action:5}"
;;
?)
printf '%s: invalid option -''%s'\\n "${0##*/}" "$OPTARG"
exit 1
;;
esac
done
eval "$action"
}
runScript "$@"