1
- cite about-plugin
1
+ # shellcheck shell=bash
2
2
about-plugin ' Proxy Tools'
3
3
4
- disable-proxy ()
5
- {
4
+ function disable-proxy() {
6
5
about ' Disables proxy settings for Bash, npm and SSH'
7
6
group ' proxy'
8
7
@@ -20,46 +19,43 @@ disable-proxy ()
20
19
svn-disable-proxy
21
20
}
22
21
23
- enable-proxy ()
24
- {
22
+ function enable-proxy() {
25
23
about ' Enables proxy settings for Bash, npm and SSH'
26
24
group ' proxy'
27
25
28
- export http_proxy=$ BASH_IT_HTTP_PROXY
29
- export https_proxy=$ BASH_IT_HTTPS_PROXY
30
- export HTTP_PROXY=$ http_proxy
31
- export HTTPS_PROXY=$ https_proxy
32
- export ALL_PROXY=$ http_proxy
33
- export no_proxy=$ BASH_IT_NO_PROXY
34
- export NO_PROXY=$ no_proxy
26
+ export http_proxy=" ${ BASH_IT_HTTP_PROXY:- } "
27
+ export https_proxy=" ${ BASH_IT_HTTPS_PROXY:- } "
28
+ export HTTP_PROXY=" ${ http_proxy:- } "
29
+ export HTTPS_PROXY=" ${ https_proxy:- } "
30
+ export ALL_PROXY=" ${ http_proxy:- } "
31
+ export no_proxy=" ${ BASH_IT_NO_PROXY:- } "
32
+ export NO_PROXY=" ${ no_proxy:- } "
35
33
echo " Enabled proxy environment variables"
36
34
37
35
npm-enable-proxy
38
36
ssh-enable-proxy
39
37
svn-enable-proxy
40
38
}
41
39
42
- enable-proxy-alt ()
43
- {
40
+ function enable-proxy-alt() {
44
41
about ' Enables alternate proxy settings for Bash, npm and SSH'
45
42
group ' proxy'
46
43
47
- export http_proxy=$ BASH_IT_HTTP_PROXY_ALT
48
- export https_proxy=$ BASH_IT_HTTPS_PROXY_ALT
49
- export HTTP_PROXY=$ http_proxy
50
- export HTTPS_PROXY=$ https_proxy
51
- export ALL_PROXY=$ http_proxy
52
- export no_proxy=$ BASH_IT_NO_PROXY
53
- export NO_PROXY=$ no_proxy
44
+ export http_proxy=" ${ BASH_IT_HTTP_PROXY_ALT:- } "
45
+ export https_proxy=" ${ BASH_IT_HTTPS_PROXY_ALT:- } "
46
+ export HTTP_PROXY=" ${ http_proxy:- } "
47
+ export HTTPS_PROXY=" ${ https_proxy:- } "
48
+ export ALL_PROXY=" ${ http_proxy:- } "
49
+ export no_proxy=" ${ BASH_IT_NO_PROXY:- } "
50
+ export NO_PROXY=" ${ no_proxy:- } "
54
51
echo " Enabled alternate proxy environment variables"
55
52
56
- npm-enable-proxy $ http_proxy $ https_proxy
53
+ npm-enable-proxy " ${ http_proxy:- } " " ${ https_proxy:- } "
57
54
ssh-enable-proxy
58
- svn-enable-proxy $ http_proxy
55
+ svn-enable-proxy " ${ http_proxy:- } "
59
56
}
60
57
61
- show-proxy ()
62
- {
58
+ function show-proxy() {
63
59
about ' Shows the proxy settings for Bash, Git, npm and SSH'
64
60
group ' proxy'
65
61
@@ -75,8 +71,7 @@ show-proxy ()
75
71
ssh-show-proxy
76
72
}
77
73
78
- proxy-help ()
79
- {
74
+ function proxy-help() {
80
75
about ' Provides an overview of the bash-it proxy configuration'
81
76
group ' proxy'
82
77
97
92
bash-it-show-proxy
98
93
}
99
94
100
- bash-it-show-proxy ()
101
- {
95
+ function bash-it-show-proxy() {
102
96
about ' Shows the bash-it proxy settings'
103
97
group ' proxy'
104
98
@@ -110,141 +104,130 @@ bash-it-show-proxy ()
110
104
env | grep -e " BASH_IT.*PROXY"
111
105
}
112
106
113
- npm-show-proxy ()
114
- {
107
+ function npm-show-proxy() {
115
108
about ' Shows the npm proxy settings'
116
109
group ' proxy'
117
110
118
- if $( command -v npm & > /dev/null ) ; then
111
+ if _command_exists npm; then
119
112
echo " "
120
113
echo " npm"
121
114
echo " ==="
122
- echo " npm HTTP proxy: " ` npm config get proxy`
123
- echo " npm HTTPS proxy: " ` npm config get https-proxy`
124
- echo " npm proxy exceptions: " ` npm config get noproxy`
115
+ echo " npm HTTP proxy: $( npm config get proxy) "
116
+ echo " npm HTTPS proxy: $( npm config get https-proxy) "
117
+ echo " npm proxy exceptions: $( npm config get noproxy) "
125
118
fi
126
119
}
127
120
128
- npm-disable-proxy ()
129
- {
121
+ function npm-disable-proxy() {
130
122
about ' Disables npm proxy settings'
131
123
group ' proxy'
132
124
133
- if $( command -v npm & > /dev/null ) ; then
125
+ if _command_exists npm; then
134
126
npm config delete proxy
135
127
npm config delete https-proxy
136
128
npm config delete noproxy
137
129
echo " Disabled npm proxy settings"
138
130
fi
139
131
}
140
132
141
- npm-enable-proxy ()
142
- {
133
+ function npm-enable-proxy() {
143
134
about ' Enables npm proxy settings'
144
135
group ' proxy'
145
136
146
- local my_http_proxy=${1:- $BASH_IT_HTTP_PROXY }
147
- local my_https_proxy=${2:- $BASH_IT_HTTPS_PROXY }
148
- local my_no_proxy=${3:- $BASH_IT_NO_PROXY }
137
+ local my_http_proxy=" ${1:- ${ BASH_IT_HTTP_PROXY:- } } "
138
+ local my_https_proxy=" ${2:- ${ BASH_IT_HTTPS_PROXY:- } } "
139
+ local my_no_proxy=" ${3:- ${ BASH_IT_NO_PROXY:- } } "
149
140
150
- if $( command -v npm & > /dev/null ) ; then
151
- npm config set proxy $ my_http_proxy
152
- npm config set https-proxy $ my_https_proxy
153
- npm config set noproxy $ my_no_proxy
141
+ if _command_exists npm; then
142
+ npm config set proxy " ${ my_http_proxy:? } " || return
143
+ npm config set https-proxy " ${ my_https_proxy:? } " || return
144
+ npm config set noproxy " ${ my_no_proxy:- } " || return
154
145
echo " Enabled npm proxy settings"
155
146
fi
156
147
}
157
148
158
- git-global-show-proxy ()
159
- {
149
+ function git-global-show-proxy() {
160
150
about ' Shows global Git proxy settings'
161
151
group ' proxy'
162
152
163
- if $( command -v git & > /dev/null ) ; then
153
+ if _command_exists git; then
164
154
echo " "
165
155
echo " Git (Global Settings)"
166
156
echo " ====================="
167
- echo " Git (Global) HTTP proxy: " ` git config --global --get http.proxy`
168
- echo " Git (Global) HTTPS proxy: " ` git config --global --get https.proxy`
157
+ echo " Git (Global) HTTP proxy: $( git config --global --get http.proxy) "
158
+ echo " Git (Global) HTTPS proxy: $( git config --global --get https.proxy) "
169
159
fi
170
160
}
171
161
172
- git-global-disable-proxy ()
173
- {
162
+ function git-global-disable-proxy() {
174
163
about ' Disables global Git proxy settings'
175
164
group ' proxy'
176
165
177
- if $( command -v git & > /dev/null ) ; then
166
+ if _command_exists git; then
178
167
git config --global --unset-all http.proxy
179
168
git config --global --unset-all https.proxy
180
169
echo " Disabled global Git proxy settings"
181
170
fi
182
171
}
183
172
184
- git-global-enable-proxy ()
185
- {
173
+ function git-global-enable-proxy() {
186
174
about ' Enables global Git proxy settings'
187
175
group ' proxy'
188
176
189
- if $( command -v git & > /dev/null ) ; then
177
+ if _command_exists git; then
190
178
git-global-disable-proxy
191
179
192
- git config --global --add http.proxy $ BASH_IT_HTTP_PROXY
193
- git config --global --add https.proxy $ BASH_IT_HTTPS_PROXY
180
+ git config --global --add http.proxy " ${ BASH_IT_HTTP_PROXY:? } "
181
+ git config --global --add https.proxy " ${ BASH_IT_HTTPS_PROXY:? } "
194
182
echo " Enabled global Git proxy settings"
195
183
fi
196
184
}
197
185
198
- git-show-proxy ()
199
- {
186
+ function git-show-proxy() {
200
187
about ' Shows current Git project proxy settings'
201
188
group ' proxy'
202
189
203
- if $( command -v git & > /dev/null ) ; then
190
+ if _command_exists git; then
204
191
echo " Git Project Proxy Settings"
205
192
echo " ====================="
206
- echo " Git HTTP proxy: " ` git config --get http.proxy`
207
- echo " Git HTTPS proxy: " ` git config --get https.proxy`
193
+ echo " Git HTTP proxy: $( git config --get http.proxy) "
194
+ echo " Git HTTPS proxy: $( git config --get https.proxy) "
208
195
fi
209
196
}
210
197
211
- git-disable-proxy ()
212
- {
198
+ function git-disable-proxy() {
213
199
about ' Disables current Git project proxy settings'
214
200
group ' proxy'
215
201
216
- if $( command -v git & > /dev/null ) ; then
202
+ if _command_exists git; then
217
203
git config --unset-all http.proxy
218
204
git config --unset-all https.proxy
219
205
echo " Disabled Git project proxy settings"
220
206
fi
221
207
}
222
208
223
- git-enable-proxy ()
224
- {
209
+ function git-enable-proxy() {
225
210
about ' Enables current Git project proxy settings'
226
211
group ' proxy'
227
212
228
- if $( command -v git & > /dev/null ) ; then
213
+ if _command_exists git; then
229
214
git-disable-proxy
230
215
231
- git config --add http.proxy $ BASH_IT_HTTP_PROXY
232
- git config --add https.proxy $ BASH_IT_HTTPS_PROXY
216
+ git config --add http.proxy " ${ BASH_IT_HTTP_PROXY:? } "
217
+ git config --add https.proxy " ${ BASH_IT_HTTPS_PROXY:? } "
233
218
echo " Enabled Git project proxy settings"
234
219
fi
235
220
}
236
221
237
-
238
- svn-show-proxy ()
239
- {
222
+ function svn-show-proxy() {
240
223
about ' Shows SVN proxy settings'
241
224
group ' proxy'
242
225
243
- if $( command -v svn & > /dev/null ) && $( command -v python2 & > /dev/null ) ; then
226
+ if _command_exists svn && _command_exists python2; then
244
227
echo " "
245
228
echo " SVN Proxy Settings"
246
229
echo " =================="
247
- python2 - << END
230
+ python2 - << END
248
231
import ConfigParser, os
249
232
config = ConfigParser.ConfigParser()
250
233
config.read(os.path.expanduser('~/.subversion/servers'))
@@ -265,13 +248,12 @@ END
265
248
fi
266
249
}
267
250
268
- svn-disable-proxy ()
269
- {
251
+ function svn-disable-proxy() {
270
252
about ' Disables SVN proxy settings'
271
253
group ' proxy'
272
254
273
- if $( command -v svn & > /dev/null ) && $( command -v python2 & > /dev/null ) ; then
274
- python2 - << END
255
+ if _command_exists svn_command_exists python2; then
256
+ python2 - << END
275
257
import ConfigParser, os
276
258
config = ConfigParser.ConfigParser()
277
259
config.read(os.path.expanduser('~/.subversion/servers'))
@@ -294,15 +276,14 @@ END
294
276
fi
295
277
}
296
278
297
- svn-enable-proxy ()
298
- {
279
+ function svn-enable-proxy() {
299
280
about ' Enables SVN proxy settings'
300
281
group ' proxy'
301
282
302
- if $( command -v svn & > /dev/null ) && $( command -v python2 & > /dev/null ) ; then
303
- local my_http_proxy=${1:- $BASH_IT_HTTP_PROXY }
283
+ if _command_exists svn _command_exists python2; then
284
+ local my_http_proxy=" ${1:- ${ BASH_IT_HTTP_PROXY:- } } "
304
285
305
- python2 - " $my_http_proxy " " $BASH_IT_NO_PROXY " << END
286
+ python2 - " ${ my_http_proxy:? } " " ${ BASH_IT_NO_PROXY:- } " << END
306
287
import ConfigParser, os, sys, urlparse
307
288
pieces = urlparse.urlparse(sys.argv[1])
308
289
host = pieces.hostname
@@ -331,12 +312,11 @@ END
331
312
fi
332
313
}
333
314
334
- ssh-show-proxy ()
335
- {
315
+ function ssh-show-proxy() {
336
316
about ' Shows SSH config proxy settings (from ~/.ssh/config)'
337
317
group ' proxy'
338
318
339
- if [ -f ~ /.ssh/config ] ; then
319
+ if [ -f ~ /.ssh/config ]; then
340
320
echo " "
341
321
echo " SSH Config Enabled in ~/.ssh/config"
342
322
echo " ==================================="
@@ -368,25 +348,22 @@ ssh-show-proxy ()
368
348
fi
369
349
}
370
350
371
- ssh-disable-proxy ()
372
- {
351
+ function ssh-disable-proxy() {
373
352
about ' Disables SSH config proxy settings'
374
353
group ' proxy'
375
354
376
- if [ -f ~ /.ssh/config ] ; then
377
- sed -e' s/^.*ProxyCommand/# ProxyCommand/' " ${BASH_IT_SED_I_PARAMETERS[@]} " ~ /.ssh/config
355
+ if [ -f ~ /.ssh/config ]; then
356
+ sed -e' s/^.*ProxyCommand/# ProxyCommand/' " ${BASH_IT_SED_I_PARAMETERS[@]} " ~ /.ssh/config
378
357
echo " Disabled SSH config proxy settings"
379
358
fi
380
359
}
381
360
382
-
383
- ssh-enable-proxy ()
384
- {
361
+ function ssh-enable-proxy() {
385
362
about ' Enables SSH config proxy settings'
386
363
group ' proxy'
387
364
388
- if [ -f ~ /.ssh/config ] ; then
389
- sed -e' s/# ProxyCommand/ ProxyCommand/' " ${BASH_IT_SED_I_PARAMETERS[@]} " ~ /.ssh/config
365
+ if [ -f ~ /.ssh/config ]; then
366
+ sed -e' s/# ProxyCommand/ ProxyCommand/' " ${BASH_IT_SED_I_PARAMETERS[@]} " ~ /.ssh/config
390
367
echo " Enabled SSH config proxy settings"
391
368
fi
392
369
}
0 commit comments