File tree 2 files changed +10
-27
lines changed
2 files changed +10
-27
lines changed Original file line number Diff line number Diff line change 10
10
# @online-doc https://github.com/oldratlee/useful-scripts/blob/master/docs/shell.md#beer-colines
11
11
# @author Jerry Lee (oldratlee at gmail dot com)
12
12
13
+ set -e
14
+ set -o pipefail
15
+
13
16
# NOTE: $'foo' is the escape sequence syntax of bash
14
17
readonly ec=$' \033 ' # escape char
15
18
readonly eend=$' \033 [0m' # escape end
@@ -23,22 +26,7 @@ colorEcho() {
23
26
[ -t 1 ] && echo " $ec [1;${color} m$@ $eend " || echo " $@ "
24
27
}
25
28
26
- readonly seperator=" ================================================================================"
27
-
28
- if [ $# -eq 0 ]; then
29
- # Bash read line does not read leading spaces https://stackoverflow.com/questions/29689172
30
- while IFS= read -r line; do
31
- colorEcho " $line "
32
- done
33
- else
34
- for a; do
35
- [ $# -gt 1 ] && {
36
- echo " $seperator "
37
- echo " $a "
38
- echo " $seperator "
39
- }
40
- while IFS= read -r line; do
41
- colorEcho " $line "
42
- done < " $a "
43
- done
44
- fi
29
+ # Bash read line does not read leading spaces https://stackoverflow.com/questions/29689172
30
+ cat " $@ " | while IFS= read -r line; do
31
+ colorEcho " $line "
32
+ done
Original file line number Diff line number Diff line change @@ -83,8 +83,9 @@ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAz+ETZEgoLeIiC0rjWewdDs0sbo8c...==
[email protected]
83
83
:beer : [ colines] ( ../colines )
84
84
----------------------
85
85
86
- 彩色` cat ` 出文件行,方便人眼区分不同的行。
87
- 支持` Linux ` 、` Mac ` 、` Windows ` (` cygwin ` 、` MSSYS ` )。
86
+ 彩色` cat ` 出文件行,方便人眼区分不同的行。
87
+ 支持` Linux ` 、` Mac ` 、` Windows ` (` cygwin ` 、` MSSYS ` )。
88
+ 命令支持选项、功能和使用方式与[ ` cat ` 命令] ( https://linux.die.net/man/1/cat ) 完全一样(实际上在实现上全部代码给` cat ` 命令)。
88
89
89
90
命令名` colines ` 意思是` COLorful LINES ` 。
90
91
@@ -100,15 +101,9 @@ $ echo -e 'a\nb' | nl | colines
100
101
1 a
101
102
2 b
102
103
$ colines file1 file2.txt
103
- ================================================================================
104
- file1
105
- ================================================================================
106
104
line1 of file1
107
105
line2 of file1
108
106
...
109
- ================================================================================
110
- file2.txt
111
- ================================================================================
112
107
line1 of file2
113
108
line2 of file2
114
109
...
You can’t perform that action at this time.
0 commit comments