-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.6h.sh
296 lines (219 loc) · 8.48 KB
/
Package.6h.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/bin/bash
# <bitbar.title>Package</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Shrey Choudhary</bitbar.author>
# <bitbar.author.github>SxC97</bitbar.author.github>
# <bitbar.desc>Plugin that displays total number of outdated packages.</bitbar.desc>
# <bitbar.dependencies>brew, brew-cask-outdated, pip, pipoutdated, npm, yarn, apm, gem, mas</bitbar.dependencies>
# Sets unicode encoding to UTF-8. Fixes issues with displaying *many* but not *all* unicode charecters.
export LANG="es_ES.UTF-8"
# Exports the plugin to your $PATH to allow execution. Make sure you run `chmod +x Package.6h.sh` after downloading
export PATH=/usr/local/bin:$PATH
# specify the package managers you want the program to use
USE='brew cask npm yarn apm mas pip'
# Checks to see if the brew command is avaliable and the package manager is in the enabled list above.
if [[ -x "$(command -v brew)" ]] && [[ $USE == *"brew"* ]]; then
# runs the outdated command and stores the output as a list variable.
brewLIST=$(brew outdated)
# checks to see if the returned list is empty. If so, it sets the outdated packages list to zero, if not, sets it to the line count of the list.
if [[ $brewLIST == "" ]]; then
BREW='0'
brewLIST=""
else
BREW=$(echo "$brewLIST" | wc -l)
fi
fi
# Checks to see if the brew command is avaliable and the package manager is in the enabled list above.
if [[ -x "$(command -v brew)" ]] && [[ $USE == *"cask"* ]]; then
# runs the outdated command and stores the output as a list variable.
caskLIST=$(brew-cask-outdated)
# checks to see if the returned list is empty. If so, it sets the outdated packages list to zero, if not, sets it to the line count of the list.
if [[ $caskLIST == "" ]]; then
CASK='0'
caskLIST=""
else
CASK=$(echo "$caskLIST" | wc -l)
fi
fi
# Checks to see if the pip command is avaliable and the package manager is in the enabled list above.
if [[ -x "$(command -v pip)" ]] && [[ $USE == *"pip"* ]]; then
# runs the outdated command and stores the output as a list variable.
pipLIST=$(pip list --outdated)
tempPIP=$(echo "$pipLIST" | wc -l)
# checks to see if the returned list is empty. If so, it sets the outdated packages list to zero, if not, sets it to the line count of the list.
if [[ $tempPIP -gt 1 ]]; then
PIP=$(($tempPIP - 2))
else
PIP="0"
pipLIST=""
fi
fi
# Checks to see if the npm command is avaliable and the package manager is in the enabled list above.
if [[ -x "$(command -v npm)" ]] && [[ $USE == *"npm"* ]]; then
# runs the outdated command and stores the output as a list variable.
npmLIST=$(npm outdated)
# checks to see if the returned list is empty. If so, it sets the outdated packages list to zero, if not, sets it to the line count of the list.
if [[ $npmLIST == "" ]]; then
NPM='0'
npmLIST=""
else
NPM=$(echo "npmLIST" | wc -l)
fi
fi
# Checks to see if the yarn command is avaliable and the package manager is in the enabled list above.
if [[ -x "$(command -v yarn)" ]] && [[ $USE == *"yarn"* ]]; then
# runs the outdated command and stores the output as a list variable.
yarnLIST=$(yarn outdated)
# checks to see if the returned list is empty. If so, it sets the outdated packages list to zero, if not, sets it to the line count of the list.
if [[ $yarnLIST == "" ]]; then
YARN='0'
yarnLIST=""
else
YARN=$(echo "$yarnLIST" | wc -l)
fi
fi
# Checks to see if the apm command is avaliable and the package manager is in the enabled list above.
if [[ -x "$(command -v apm)" ]] && [[ $USE == *"apm"* ]]; then
# runs the outdated command and stores the output as a list variable.
apmLIST="$(apm outdated)"
# checks to see if the returned list is empty. If so, it sets the outdated packages list to zero, if not, sets it to the line count of the list.
if [[ $apmLIST == *"empty"* ]]; then
APM='0'
apmLIST=""
else
tempAPM=$(echo "$apmLIST" | wc -l)
APM=$((tempAPM - 1))
fi
fi
# Checks to see if the gem command is avaliable and the package manager is in the enabled list above.
if [[ -x "$(command -v gem)" ]] && [[ $USE == *"gem"* ]]; then
# runs the outdated command and stores the output as a list variable.
gemLIST=$(gem outdated)
# checks to see if the returned list is empty. If so, it sets the outdated packages list to zero, if not, sets it to the line count of the list.
if [[ $gemLIST == "" ]]; then
GEM='0'
gemLIST=""
else
GEM=$(echo "$gemLIST" | wc -l)
fi
fi
# Checks to see if the mas command is avaliable and the package manager is in the enabled list above.
if [[ -x "$(command -v mas)" ]] && [[ $USE == *"mas"* ]]; then
# runs the outdated command and stores the output as a list variable.
masLIST=$(mas outdated)
# checks to see if the returned list is empty. If so, it sets the outdated packages list to zero, if not, sets it to the line count of the list.
if [[ $masLIST == "" ]]; then
MAS='0'
masLIST=""
else
MAS=$(echo "$masLIST" | wc -l)
fi
fi
# sum of all outdated packages
SUM=$(($BREW + $CASK + $PIP + $NPM + $YARN + $APM + $GEM + $MAS))
# icon to be displayed next to number of outdated packages. Feel free to customize.
ICON=""
# icon to be displayed if no packages are outdated. Change to `ZERO=""` if you want the widget to be invisible when no packages are out of date.
ZERO="✔︎"
if [[ $SUM -gt 0 ]]; then
FINAL="$SUM $ICON"
else
FINAL="$ZERO"
fi
echo "$FINAL"
# all echo statements below this point will be shown as a submenu
echo "---"
# option to upgrade all packages
echo "upgrade all: $SUM | bash='$0' param1=all terminal=false"
# option to upgrade brew packages
if [[ -x "$(command -v brew)" ]] && [[ $USE == *"brew"* ]]; then
echo "brew: $BREW | bash='$0' param1=brew terminal=true"
if ! [[ $brewLIST == "" ]]; then
echo "$(echo "$brewLIST" | awk 'BEGIN{ RS = "" ; FS = "\n" }{print "--"$0}')"
fi
fi
# option to upgrade cask packages
if [[ -x "$(command -v brew-cask-outdated)" ]] && [[ $USE == *"cask"* ]]; then
echo "cask: $CASK | bash='$0' param1=cask terminal=true"
if ! [[ $caskLIST == "" ]]; then
echo "$(echo "$caskLIST" | awk 'BEGIN{ RS = "" ; FS = "\n" }{print "--"$0}')"
fi
fi
# option to upgrade pip packages
if [[ -x "$(command -v pip)" ]] && [[ $USE == *"pip"* ]]; then
echo "pip: $PIP | bash='$0' param1=pip terminal=true"
if ! [[ $pipLIST == "" ]]; then
echo "$(echo "$pipLIST" | awk 'BEGIN{ RS = "" ; FS = "\n" }{for (i=3; i<=NF; i++) print "--"$i}')"
fi
fi
# option to upgrade npm packages
if [[ -x "$(command -v npm)" ]] && [[ $USE == *"npm"* ]]; then
echo "npn: $NPM | bash='$0' param1=npm terminal=true"
if ! [[ $npmLIST == "" ]]; then
echo "$(echo "$npmLIST" | awk 'BEGIN{ RS = "" ; FS = "\n" }{print "--"$0}')"
fi
fi
# option to upgrade yarn packages
if [[ -x "$(command -v yarn)" ]] && [[ $USE == *"yarn"* ]]; then
echo "yarn: $YARN | bash='$0' param1=yarn terminal=true"
if ! [[ $yarnLIST == "" ]]; then
echo "$(echo "$yarnLIST" | awk 'BEGIN{ RS = "" ; FS = "\n" }{print "--"$0}')"
fi
fi
# option to upgrade apm packages
if [[ -x "$(command -v apm)" ]] && [[ $USE == *"apm"* ]]; then
echo "apm: $APM | bash='$0' param1=apm terminal=true"
if ! [[ $apmLIST == "" ]]; then
echo "$(echo "$apmLIST" | awk 'BEGIN{ RS = "" ; FS = "\n" }{print "--"$0}')"
fi
fi
# option to upgrade gem packages
if [[ -x "$(command -v gem)" ]] && [[ $USE == *"gem"* ]]; then
echo "gem: $GEM | bash='$0' param1=gem terminal=true"
if ! [[ $gemLIST == "" ]]; then
echo "$(echo "$gemLIST" | awk 'BEGIN{ RS = "" ; FS = "\n" }{print "--"$0}')"
fi
fi
# option to upgrade MAS packages
if [[ -x "$(command -v mas)" ]] && [[ $USE == *"mas"* ]]; then
echo "mas: $MAS | bash='$0' param1=mas terminal=true"
if ! [[ $masLIST == "" ]]; then
echo "$(echo "$masLIST" | awk 'BEGIN{ RS = "" ; FS = "\n" }{print "--"$0}')"
fi
fi
# updates all
if [[ "$1" = "all" ]]; then
brew update && brew upgrade; brew cask upgrade; pipupgrade; npm update; yarn upgrade; apm update && apm upgrade; mas upgrade; sudo gem update
fi
# updates brew
if [[ "$1" = "brew" ]]; then
brew update && brew upgrade
fi
# updates brew-cask
if [[ "$1" = "cask" ]]; then
brew cask upgrade
fi
# updates pip
if [[ "$1" = "pip" ]]; then
pipupgrade
fi
# updates npm
if [[ "$1" = "npm" ]]; then
npm update
fi
# updates yarn
if [[ "$1" = "yarn" ]]; then
yarn upgrade
fi
# updates apm
if [[ "$1" = "apm" ]]; then
apm update && apm upgrade
fi
# updates gem
if [[ "$1" = "gem" ]]; then
sudo gem update
fi
# updates mas
if [[ "$1" = "mas" ]]; then
mas upgrade
fi