File tree 1 file changed +16
-4
lines changed
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -34,12 +34,23 @@ readonly PROG_VERSION='2.6.0-dev'
34
34
# util functions
35
35
# ###############################################################################
36
36
37
+ redPrint () {
38
+ # if stdout is a terminal, turn on color output.
39
+ # '-t' check: is a terminal?
40
+ # check isatty in bash https://stackoverflow.com/questions/10022323
41
+ if [ -t 1 ]; then
42
+ printf ' \e[1;31m%s\e[0m\n' " $* "
43
+ else
44
+ printf ' %s\n' " $* "
45
+ fi
46
+ }
47
+
37
48
usage () {
38
49
local -r exit_code=${1:- 0}
39
50
(( $# > 0 )) && shift
40
51
local -r out=$(( (exit_code != 0 ) + 1 ))
41
52
42
- (( $# > 0 )) && printf ' %s\n\n ' " $* " >& " $out "
53
+ (( $# > 0 )) && redPrint " $* " $' \n ' >& " $out "
43
54
44
55
cat >& " $out " << EOF
45
56
Usage: ${PROG} [OPTION] [FILE]...
@@ -148,12 +159,13 @@ openOneFile() {
148
159
has_error=false
149
160
150
161
for file in " ${files[@]} " ; do
151
- [ ! -e " $file " ] && {
152
- printf ' %s\n' " $file not existed!"
162
+ [ -e " $file " ] || {
163
+ has_error=true
164
+ redPrint " $file not existed!" >&2
153
165
continue
154
166
}
155
167
156
- openOneFile " $file "
168
+ openOneFile " $file " || has_error=true
157
169
done
158
170
159
171
# set exit status
You can’t perform that action at this time.
0 commit comments