-
Notifications
You must be signed in to change notification settings - Fork 1
/
launchctl-completion.bash
executable file
·81 lines (75 loc) · 1.76 KB
/
launchctl-completion.bash
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
#!bash
#
# git-flow-completion
# ===================
#
# Bash completion support for launchctl (mostly)
#
#
# Installation
# ------------
#
# 1. Install this file. Either:
#
# a. Place it in a `bash-completion.d` folder:
#
# * /etc/bash-completion.d
# * /usr/local/etc/bash-completion.d
# * ~/bash-completion.d
#
# b. Or, copy it somewhere (e.g. ~/.launchctl-completion.sh) and put the following line in
# your .bashrc:
#
# source ~/.launchctl-completion.sh
#
#
#
# The Fine Print
# --------------
#
# Copyright (c) 2010 [Justin Hileman](http://justinhileman.com)
#
# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
__launchctl_list_labels ()
{
launchctl list | awk 'NR>1 && $3 !~ /0x[0-9a-fA-F]+\.(anonymous|mach_init)/ {print $3}'
}
__launchctl_list_started ()
{
launchctl list | awk 'NR>1 && $3 !~ /0x[0-9a-fA-F]+\.(anonymous|mach_init)/ && $1 !~ /-/ {print $3}'
}
__launchctl_list_stopped ()
{
launchctl list | awk 'NR>1 && $3 !~ /0x[0-9a-fA-F]+\.(anonymous|mach_init)/ && $1 ~ /-/ {print $3}'
}
_launchctl ()
{
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
# Subcommand list
local subcommands="load unload submit remove start stop list help"
[[ ${COMP_CWORD} -eq 1 ]] && {
COMPREPLY=( $(compgen -W "${subcommands}" -- ${cur}) )
return
}
case "$prev" in
remove|list)
COMPREPLY=( $(compgen -W "$(__launchctl_list_labels)" -- ${cur}) )
return
;;
start)
COMPREPLY=( $(compgen -W "$(__launchctl_list_stopped)" -- ${cur}) )
return
;;
stop)
COMPREPLY=( $(compgen -W "$(__launchctl_list_started)" -- ${cur}) )
return
;;
load|unload)
COMPREPLU=( $(compgen -d $(pwd)) )
return
;;
esac
}
complete -F _launchctl launchctl