File tree Expand file tree Collapse file tree 2 files changed +10
-27
lines changed Expand file tree Collapse file tree 2 files changed +10
-27
lines changed Original file line number Diff line number Diff line change 1010# @online-doc https://github.com/oldratlee/useful-scripts/blob/master/docs/shell.md#beer-colines
1111# @author Jerry Lee (oldratlee at gmail dot com)
1212
13+ set -e
14+ set -o pipefail
15+
1316# NOTE: $'foo' is the escape sequence syntax of bash
1417readonly ec=$' \033 ' # escape char
1518readonly eend=$' \033 [0m' # escape end
@@ -23,22 +26,7 @@ colorEcho() {
2326 [ -t 1 ] && echo " $ec [1;${color} m$@ $eend " || echo " $@ "
2427}
2528
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] 8383:beer : [ colines] ( ../colines )
8484----------------------
8585
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 ` 命令)。
8889
8990命令名` colines ` 意思是` COLorful LINES ` 。
9091
@@ -100,15 +101,9 @@ $ echo -e 'a\nb' | nl | colines
1001011 a
1011022 b
102103$ colines file1 file2.txt
103- ================================================================================
104- file1
105- ================================================================================
106104line1 of file1
107105line2 of file1
108106...
109- ================================================================================
110- file2.txt
111- ================================================================================
112107line1 of file2
113108line2 of file2
114109...
You can’t perform that action at this time.
0 commit comments