2
2
3
3
# Create a new directory and enter it
4
4
function mkd() {
5
- mkdir -p " $@ " && cd " $_ " ;
5
+ mkdir -p " $@ " && cd " $_ " || return ;
6
6
}
7
7
8
8
# Change working directory to the top-most Finder window location
9
9
function cdf() { # short for `cdfinder`
10
- cd " $( osascript -e ' tell app "Finder" to POSIX path of (insertion location as alias)' ) " ;
10
+ cd " $( osascript -e ' tell app "Finder" to POSIX path of (insertion location as alias)' ) " || return ;
11
11
}
12
12
13
13
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
14
14
function targz() {
15
- local tmpFile=" ${@ %/ } .tar" ;
15
+ local tmpFile=" ${* %/ } .tar" ;
16
16
tar -cvf " ${tmpFile} " --exclude=" .DS_Store" " ${@ } " || return 1;
17
17
18
18
size=$(
@@ -51,24 +51,24 @@ function fs() {
51
51
else
52
52
local arg=-sh;
53
53
fi
54
- if [[ -n " $@ " ]]; then
54
+ if [[ -n " $* " ]]; then
55
55
du $arg -- " $@ " ;
56
56
else
57
57
du $arg .[^.]* ./* ;
58
58
fi ;
59
59
}
60
60
61
61
# Use Git’s colored diff when available
62
- hash git & > /dev/null;
63
- if [ $? -eq 0 ]; then
62
+ if hash git & > /dev/null; then
64
63
function diff() {
65
64
git diff --no-index --color-words " $@ " ;
66
65
}
67
66
fi ;
68
67
69
68
# Create a data URL from a file
70
69
function dataurl() {
71
- local mimeType=$( file -b --mime-type " $1 " ) ;
70
+ local mimeType;
71
+ mimeType=$( file -b --mime-type " $1 " ) ;
72
72
if [[ $mimeType == text/* ]]; then
73
73
mimeType=" ${mimeType} ;charset=utf-8" ;
74
74
fi
@@ -86,9 +86,10 @@ function server() {
86
86
87
87
# Compare original and gzipped file size
88
88
function gz() {
89
- local origsize=$( wc -c < " $1 " ) ;
90
- local gzipsize=$( gzip -c " $1 " | wc -c) ;
91
- local ratio=$( echo " $gzipsize * 100 / $origsize " | bc -l) ;
89
+ local origsize, gzipsize, ratio;
90
+ origsize=$( wc -c < " $1 " ) ;
91
+ gzipsize=$( gzip -c " $1 " | wc -c) ;
92
+ ratio=$( echo " $gzipsize * 100 / $origsize " | bc -l) ;
92
93
printf " orig: %d bytes\n" " $origsize " ;
93
94
printf " gzip: %d bytes (%2.2f%%)\n" " $gzipsize " " $ratio " ;
94
95
}
@@ -106,15 +107,17 @@ function getcertnames() {
106
107
return 1;
107
108
fi ;
108
109
109
- local domain=" ${1} " ;
110
+ local domain, tmp, certText;
111
+
112
+ domain=" ${1} " ;
110
113
echo " Testing ${domain} …" ;
111
114
echo " " ; # newline
112
115
113
- local tmp=$( echo -e " GET / HTTP/1.0\nEOT" \
116
+ tmp=$( echo -e " GET / HTTP/1.0\nEOT" \
114
117
| openssl s_client -connect " ${domain} :443" -servername " ${domain} " 2>&1 ) ;
115
118
116
119
if [[ " ${tmp} " = * " -----BEGIN CERTIFICATE-----" * ]]; then
117
- local certText=$( echo " ${tmp} " \
120
+ certText=$( echo " ${tmp} " \
118
121
| openssl x509 -text -certopt " no_aux, no_header, no_issuer, no_pubkey, \
119
122
no_serial, no_sigdump, no_signame, no_validity, no_version" ) ;
120
123
echo " Common Name:" ;
@@ -134,7 +137,7 @@ function getcertnames() {
134
137
135
138
# Normalize `open` across Linux, macOS, and Windows.
136
139
# This is needed to make the `o` function (see below) cross-platform.
137
- if [ ! $( uname -s) = ' Darwin' ]; then
140
+ if [ ! " $( uname -s) " = ' Darwin' ]; then
138
141
if grep -q Microsoft /proc/version; then
139
142
# Ubuntu on Windows using the Linux subsystem
140
143
alias open=' explorer.exe' ;
0 commit comments