-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcat_func.sh
95 lines (75 loc) · 2.29 KB
/
mcat_func.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
function mcat() {
description='
#: Title: mcat
#: Synopsis: accepts multiple files from stdin and displays them consecutively
#: Date: 2016-05-30
#: Version: 0.0.5
#: Options: -h | --help: print short usage info
#: : -v | --version: print version number
#: : --tutorial: prints longer help info
'
function usage() {
echo
printf " %s\n\n" "${UNDERLINE}mcat:${NORMAL} batch file display with added whitespace."
printf " %s\n%s\n" "usage: mcat [-h],[--help],[--tutorial] aFile.txt bFile.txt cFile.txt"
}
function displaytutorial() {
echo "$tutorial" | sed 's/^/ /g' # | /usr/bin/less
}
function displayfiles() {
echo
for i in $shortArgs; do
printf " %s\n" "$i"
printf " %s\n\n" "$rule"
cat "$i" | sed 's/^/ /g'
echo; echo; echo
done
printf " %s\n" "$lastArg"
printf " %s\n\n" "$rule"
cat "$lastArg" | sed 's/^/ /g'
echo; echo
}
local tutorial='
mcat: displays multiple files with added whitespace to improve readability.
usage: mcat [-h],[--help],[--tutorial] aFile.txt bFile.txt cFile.txt
$ mcat /tmp/aFile.txt /tmp/bFile.txt /tmp/bbb.txt
/tmp/aFile.txt
---------------------------------------------------------------------------
one two
three four
/tmp/bFile.txt
---------------------------------------------------------------------------
five six
blah
/tmp/bbb.txt
---------------------------------------------------------------------------
blah what hello
blah stuff here
blah
blah
'
local theArgs="$@"
local lastArg="${!#}"
local length=$(($#-1))
local shortArgs=${@:1:$length}
local rule='========================='
local rule=$rule$rule$rule
case "$1" in
-h|--help)
usage
return 0
;;
--tutorial)
clear
echo
displaytutorial
return 0
;;
*)
displayfiles
;;
esac
}
export _ext='printf " %s\n" "${UNDERLINE}mcat:${NORMAL} batch file display with added whitespace."
printf " %s\n%s" "usage: mcat [-h],[--help],[--tutorial] aFile.txt bFile.txt cFile.txt"'