/
brew-file
110 lines (107 loc) · 3.17 KB
/
brew-file
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#compdef brew-file
_brew_file_options () {
# Using brew commands make it slow...
#local val=$(brew file commands)
#local commands=$(echo $val|grep 'commands: '|sed 's/commands: //')
#local commands_hyphen=$(echo $val|grep 'commands_hyphen: '|
# sed 's/commands_hyphen: //')
#local commands=$(echo $val|grep 'options: '|sed 's/options: //')
local commands="install brew init dump set_repo set_local pull push clean clean_non_request update edit \
cat casklist get_files commands version help"
local commands_hyphen="-i --init -s --set_repo --set_local -c --clean --clean_non_request -u --update -e \
--edit --cat --commands -v --version -h --help"
local options="-f --file -b --backup -F --format --form --leaves --on_request -U --noupgrade \
-r --repo -n --nolink --caskonly --appstore --no_appstore -C -y --yes -V --verbose"
if [ "$1" = "commands" ];then
echo $commands
elif [ "$1" = "commands_hyphen" ];then
echo $commands_hyphen
elif [ "$1" = "options" ];then
echo $options
elif [ "$1" = "all_commands" ];then
echo $commands $commands_hyphen
else
echo $commands $commands_hyphen $options
fi
}
_brew_file_check_commands () {
if [ -n "$ZSH_VERSION" ];then
local w
w=("${words[@]:1}")
else
local w=("${COMP_WORDS[@]:1}")
fi
local cmds
cmds=($(_brew_file_options all_commands))
local c
for c in "${w[@]}";do
if echo " ${cmds[*]} "|grep -q " $c ";then
echo "$c"
return 0
fi
done
return 1
}
_brew_file () {
if [ -n "$ZSH_VERSION" ];then
local cword=$CURRENT
local w
w=("${words[@]}")
else
local cword=$COMP_CWORD
local w=("${COMP_WORDS[@]}")
fi
if [ $cword -gt 2 ] && [ "$1" = "brew" ] && [ "$2" = "file" ];then
local cur=${w[cword-1]}
local prev=${w[cword-2]}
else
local cur=${w[cword]}
local prev=${w[cword-1]}
fi
if [ "$prev" = "-f" ];then
if [ "$ZSH_VERSION" != "" ];then
_files
else
COMPREPLY=($(compgen -f "${cur}"))
fi
else
local complist=""
if [ "$prev" = "-F" ] || [ "$prev" = "--format" ];then
complist="file brewdler"
elif [ "$prev" = "-V" ] || [ "$prev" = "--verbose" ];then
complist="0 1 2"
elif cmd=$(_brew_file_check_commands);then
if [ "${cur:0:1}" = "-" ];then
local minopt='-f --file -F --format --leaves -y --yes -v --verbose'
case $cmd in
install|pull|push|edit|-e|--edit)
complist="$minopt -U --noupgrade";;
brew)
complist="$minopt";;
init|dump|-i|--init|update|-u|--update)
complist="$minopt -n --nolink --caskonly -U --noupgrade";;
set_repo|-s|--set_repo)
complist="$minopt -r --repo";;
clean|-c|--clean)
complist="$minopt -C";;
*)
complist=""
esac
else
complist=""
fi
else
complist="$(_brew_file_options commands)"
fi
if [ "$ZSH_VERSION" != "" ];then
compadd $(echo $complist)
else
COMPREPLY=($(compgen -W "$complist" -- "${cur}"))
fi
fi
}
if [ "$ZSH_VERSION" != "" ];then
compdef _brew_file brew-file
else
complete -o default -F _brew_file brew-file
fi