aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/tl40
-rw-r--r--man/man1/tl.110
2 files changed, 12 insertions, 38 deletions
diff --git a/bin/tl b/bin/tl
index a341a3bb..f3f44abb 100755
--- a/bin/tl
+++ b/bin/tl
@@ -1,37 +1,15 @@
-#!/usr/bin/env bash
+#!/bin/sh
# Tag lines from files or stdin with a string prefix or suffix.
-self=tl
-
-# Define usage function
-usage() {
- printf 'USAGE: %s [-h] [-p PREFIX] [-s SUFFIX] [--] [FILE1 FILE2 ...]\n' "$self"
-}
-
-# Start with empty prefix/suffix, or use the environment variables
-prefix=$TL_PREFIX
-suffix=$TL_SUFFIX
# Parse options out, give help if necessary
while getopts 'hp:s:' opt ; do
case $opt in
-
- # -h: Print help
- h)
- usage
- exit
- ;;
-
- # -p: Specify prefix
p)
- prefix=$OPTARG
+ pref=$OPTARG
;;
-
- # -s: Specify suffix
s)
- suffix=$OPTARG
+ suff=$OPTARG
;;
-
- # Unknown option
\?)
usage >&2
exit 2
@@ -40,12 +18,8 @@ while getopts 'hp:s:' opt ; do
done
shift "$((OPTIND-1))"
-# Need at least one tag
-(($#)) || set /dev/stdin
-
-# Print each line as we read it, prepending the tags, separated by spaces
-for file ; do
- while IFS= read -r line ; do
- printf '%s%s%s\n' "$prefix" "$line" "$suffix"
- done < "$file"
+# Print each line as we read it, adding the tags
+cat -- "${@:--}" |
+while IFS= read -r line ; do
+ printf '%s%s%s\n' "$pref" "$line" "$suff"
done
diff --git a/man/man1/tl.1 b/man/man1/tl.1
index 9e82d3a3..4cbc8025 100644
--- a/man/man1/tl.1
+++ b/man/man1/tl.1
@@ -1,16 +1,16 @@
-.TH TL 1 "February 2016" "Manual page for tl"
+.TH TL 1 "Augusr 2016" "Manual page for tl"
.SH NAME
.B tl
-\- tag lines with a string prefix or suffix
+\- tag lines with a string prefix and/or suffix
.SH USAGE
-.B tl [-h] [-p PREFIX] [-s SUFFIX] [--] [FILE1 FILE2 ...]
+.B tl [-p PREFIX] [-s SUFFIX] [--] [FILE1 FILE2 ...]
.SH DESCRIPTION
Tag lines from files or stdin with a string prefix or suffix before writing
them to stdout. Specifying neither prefix nor suffix is acceptable, in which
case the stream is simply reproduced on stdout, acting like cat(1).
.P
-Option -h gives help. Specify a prefix with -p, and/or a suffix with -s. If no
-file arguments are given, defaults to reading standard input.
+Specify a prefix with -p, and/or a suffix with -s. If no file arguments are
+given, defaults to reading standard input.
.P
$ tl -p 'file: ' /path/to/file
$ dmesg | tl -s ' (stdout)'