diff --git a/bin/coat b/bin/coat index e38b558b..2b116a9b 100755 --- a/bin/coat +++ b/bin/coat @@ -11,6 +11,49 @@ # @author Jerry Lee (oldratlee at gmail dot com) set -eEuo pipefail +# NOTE: DO NOT declare var PROG as readonly in ONE line! +PROG=$(basename -- "$0") +readonly PROG +readonly PROG_VERSION='2.x-dev' + +################################################################################ +# parse options +################################################################################ + +progVersion() { + printf '%s version: %s\n' "$PROG" "$PROG_VERSION" + printf 'cat executable: %s\n' "$(command -v cat)" + exit +} + +usage() { + cat <= 0; --idx)); do + [ "${args[idx]}" = --help ] && usage + [ "${args[idx]}" = --version ] && progVersion +done +unset args idx + +################################################################################ +# biz logic +################################################################################ + # if stdout is not a terminal, use `cat` directly. # '-t' check: is a terminal? # check isatty in bash https://stackoverflow.com/questions/10022323 diff --git a/bin/taoc b/bin/taoc index adf7e663..4534365e 100755 --- a/bin/taoc +++ b/bin/taoc @@ -11,6 +11,49 @@ # @author Jerry Lee (oldratlee at gmail dot com) set -eEuo pipefail +# NOTE: DO NOT declare var PROG as readonly in ONE line! +PROG=$(basename -- "$0") +readonly PROG +readonly PROG_VERSION='2.x-dev' + +################################################################################ +# parse options +################################################################################ + +progVersion() { + printf '%s version: %s\n' "$PROG" "$PROG_VERSION" + printf 'tac executable: %s\n' "$(command -v tac)" + exit +} + +usage() { + cat <= 0; --idx)); do + [ "${args[idx]}" = --help ] && usage + [ "${args[idx]}" = --version ] && progVersion +done +unset args idx + +################################################################################ +# biz logic +################################################################################ + # if stdout is not a terminal, use `tac` directly. # '-t' check: is a terminal? # check isatty in bash https://stackoverflow.com/questions/10022323 diff --git a/docs/shell.md b/docs/shell.md index ff81c3ae..b64e217e 100644 --- a/docs/shell.md +++ b/docs/shell.md @@ -154,48 +154,26 @@ line2 of file2 # 帮助信息 # 可以看到本人机器上实现代理的`cat`/`tac`命令是GNU的实现。 $ coat --help -Usage: cat [OPTION]... [FILE]... -Concatenate FILE(s) to standard output. - -With no FILE, or when FILE is -, read standard input. - - -A, --show-all equivalent to -vET - -b, --number-nonblank number nonempty output lines, overrides -n - -e equivalent to -vE - -E, --show-ends display $ at end of each line - -n, --number number all output lines - -s, --squeeze-blank suppress repeated empty output lines - -t equivalent to -vT - -T, --show-tabs display TAB characters as ^I - -u (ignored) - -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB - --help display this help and exit - --version output version information and exit - -Examples: - cat f - g Output f's contents, then standard input, then g's contents. - cat Copy standard input to standard output. - -GNU coreutils online help: -Full documentation at: -or available locally via: info '(coreutils) cat invocation' +Usage: coat [OPTION]... [FILE]... +cat lines colorfully. -$ taoc --help -Usage: tac [OPTION]... [FILE]... -Write each FILE to standard output, last line first. - -With no FILE, or when FILE is -, read standard input. +Support options: + --help display this help and exit + --version output version information and exit +All other options and arguments are delegated to command cat, +more info see the help/man of command cat(e.g. cat --help). +cat executable: /usr/local/opt/coreutils/libexec/gnubin/cat -Mandatory arguments to long options are mandatory for short options too. - -b, --before attach the separator before instead of after - -r, --regex interpret the separator as a regular expression - -s, --separator=STRING use STRING as the separator instead of newline - --help display this help and exit - --version output version information and exit - -GNU coreutils online help: -Full documentation -or available locally via: info '(coreutils) tac invocation' +$ taoc --help +Usage: taoc [OPTION]... [FILE]... +tac lines colorfully. + +Support options: + --help display this help and exit + --version output version information and exit +All other options and arguments are delegated to command tac, +more info see the help/man of command tac(e.g. tac --help). +tac executable: /usr/local/opt/coreutils/libexec/gnubin/tac ``` 注:上面示例中,没有彩色;在控制台上运行可以看出彩色效果,如下: