-
Notifications
You must be signed in to change notification settings - Fork 0
/
zsh-brew-services.zsh
76 lines (65 loc) · 2.09 KB
/
zsh-brew-services.zsh
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
# Autocompletion for homebrew-services.
#
# This script intercepts calls to the brew plugin and adds autocompletion
# for the services subcommand.
#
# Homebrew Services: https://github.com/Homebrew/homebrew-services
# Author: https://github.com/vasyharan
compdef _brew-services brew
_brew-services()
{
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
':command:->command' \
':subcmd:->subcmd' \
'*::options:->options'
case $state in
(command)
__call_brew_cask_or_brew_original
services_commands=(
'services:manage launchctl services'
)
_describe -t commands 'brew services command' services_commands ;;
(subcmd)
case "$line[1]" in
services)
if (( CURRENT == 3 )); then
local -a subcommands
subcommands=(
'cleanup:get rid of stale services and unused plists'
"list:list all services managed by 'brew services'"
'restart:gracefully restart selected service'
'start:start selected service'
'stop:stop selected service'
)
_describe -t commands "brew services subcommand" subcommands
fi ;;
*)
__call_brew_cask_or_brew_original ;;
esac ;;
(options)
local -a stopped_services started_services
local expl
case "$line[2]" in
start)
__brew_stopped_services
_wanted stopped_services expl 'stopped services' compadd -a stopped_services ;;
stop|restart)
__brew_started_services
_wanted started_services expl 'started services' compadd -a started_services ;;
esac ;;
esac
}
__brew_stopped_services() {
stopped_services=(`find /usr/local/Cellar -type f -name 'homebrew.mxcl.*.plist' | awk -F/ '{print $5}'`)
}
__brew_started_services() {
started_services=(`brew services list 2>/dev/null | awk '{print $1}'`)
}
__call_brew_cask_or_brew_original()
{
local ret=1
type _brew-cask &>/dev/null && _call_function ret _brew-cask || _call_function ret _brew
compdef _brew-services brew
}