-
Notifications
You must be signed in to change notification settings - Fork 69
/
homebrew.sh
207 lines (183 loc) · 5.21 KB
/
homebrew.sh
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env sh
# Purpose: Homebrew support
# Author : James Pearson
# License: Fair license (http://www.opensource.org/licenses/fair)
# Source : http://github.com/icy/pacapt/
# Copyright (C) 2010 - 2014 James Pearson
#
# Usage of the works is permitted provided that this instrument is
# retained with the works, so that any entity that uses the works is
# notified of this instrument.
#
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
_homebrew_init() {
:
}
homebrew_Qi() {
brew info "$@"
}
# NOTE: `Ql` will print list of packages! This is a `brew` feature
#
# NOTE: $ brew list # list all packages
# NOTE: $ brew list nano # list all nano's files (short list)
#
# NOTE: `homebrew` detects the stdout stream and modifies the result.
# NOTE: For example, `homebrew list nano` only gives short output
# NOTE: by default, but when being used with pipe it will print all
# NOTE: files (which can be very slow/long)
#
# NOTE: $ brew list nano | cat # list all files (full list)
#
homebrew_Ql() {
local_casks=
local_forumlas=
if [ $# -eq 0 ]; then
local_casks="$(brew list --casks)"
local_forumlas="$(brew list --formula)"
else
# FIXME: this awk is not perfect!
local_casks="$(brew list --casks | LIST="$*" awk '$0 ~ ENVIRON["LIST"]')"
local_forumlas="$(brew list --formula | LIST="$*" awk '$0 ~ ENVIRON["LIST"]')"
fi
if [ -z "$_TOPT" ]; then
for package in $local_casks; do
brew list --cask "$package" \
| grep ^/ \
| PACKAGE="$package" awk '{printf("%s %s\n", ENVIRON["PACKAGE"], $0)}'
done
for package in $local_forumlas; do
brew list --formula "$package" \
| PACKAGE="$package" awk '{printf("%s %s\n", ENVIRON["PACKAGE"], $0)}'
done
elif [ "$_TOPT" = "q" ]; then
for package in $local_casks; do
brew list --cask "$package" \
| grep ^/
done
for package in $local_forumlas; do
brew list --formula "$package"
done
fi
}
# Please note that `brew list` lists all packages,
# but `brew list nano` lists all files from `nano`.
# Hence we need to provide `grep` command here.
# FIXME: Also search in ... package description
# FIXME: `homebrew search` does search online/locally (both!)
# FIXME: and it may provide more options. We don't use them now.
homebrew_Qs() {
if [ -z "$_TOPT" ]; then
local_flags="--versions"
else
local_flags=""
fi
# shellcheck disable=SC2086
brew list $local_flags | grep "${@:-.}"
}
# FIXME # homebrew_Qo() {
# FIXME # local_pkg=
# FIXME # local_prefix=
# FIXME # local_cellar=
# FIXME #
# FIXME # # FIXME: What happens if the file is not exectutable?
# FIXME # cd "$(dirname -- "$(command -v "$@")")" || return
# FIXME #
# FIXME # local_pkg="$(pwd -P)/$(basename -- "$@")"
# FIXME # local_prefix="$(brew --prefix)"
# FIXME # local_cellar="$(brew --cellar)"
# FIXME #
# FIXME # for package in "${local_cellar}"/*; do
# FIXME # files=(${package}/*/${local_pkg/#${local_prefix}\//})
# FIXME # if [[ -e "${files[${#files[@]} - 1]}" ]]; then
# FIXME # echo "${package/#${local_cellar}\//}"
# FIXME # break
# FIXME # fi
# FIXME # done
# FIXME # }
homebrew_Qc() {
brew log "$@"
}
# FIXME: The result may vary and we don't have a fixed expectation
homebrew_Qu() {
brew outdated "$@"
}
homebrew_Q() {
if [ -z "$_TOPT" ]; then
local_flags="--versions"
else
local_flags=""
fi
# shellcheck disable=SC2086
brew list $local_flags --formula "$@"
# shellcheck disable=SC2086
brew list $local_flags --cask "$@"
}
# FIXME # homebrew_Rs() {
# FIXME # _require_programs join sort
# FIXME #
# FIXME # if [ $# -eq 0 ]; then
# FIXME # _die "pacapt(homebrew_Rs) missing arguments."
# FIXME # fi
# FIXME #
# FIXME # for _target in "$@"; do
# FIXME # brew rm "$_target"
# FIXME #
# FIXME # while [ "$(join <(sort <(brew leaves)) <(sort <(brew deps $_target)))" != "" ]
# FIXME # do
# FIXME # brew rm $(join <(sort <(brew leaves)) <(sort <(brew deps $_target)))
# FIXME # done
# FIXME # done
# FIXME # }
homebrew_R() {
brew remove "$@"
}
homebrew_Si() {
brew info "$@"
}
homebrew_Suy() {
brew update \
&& brew upgrade "$@"
}
homebrew_Su() {
brew upgrade "$@"
}
homebrew_Sy() {
brew update "$@"
}
homebrew_Ss() {
brew search "$@"
}
homebrew_Sc() {
brew cleanup "$@"
}
homebrew_Scc() {
brew cleanup -s "$@"
}
homebrew_Sccc() {
# See more discussion in
# https://github.com/icy/pacapt/issues/47
local_dcache="$(brew --cache)"
case "$local_dcache" in
""|"/"|" ")
_error "pacapt(homebrew_Sccc): Unable to delete '$local_dcache'."
;;
*)
# FIXME: This can be wrong. But it's an easy way
# FIXME: to avoid some warning from #shellcheck.
# FIXME: Please note that, $_dcache is not empty now.
rm -rf "${local_dcache:-/x/x/x/x/x/x/x/x/x/x/x//x/x/x/x/x/}/"
;;
esac
}
# NOTE: New version of homebrew will automatically invoke `brew cask install`
# NOTE: if formula is not available.
homebrew_S() {
# shellcheck disable=SC2086
2>&1 brew install $_TOPT "$@" \
| awk '{print; if ($0 ~ /brew cask install/) { exit(126); }}'
if [ "${?}" = 126 ]; then
_warn "Failed to install package, now trying with 'brew cask' as suggested..."
# shellcheck disable=SC2086
brew cask install $_TOPT "$@"
fi
}