aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-03 13:35:17 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-03 13:35:17 +1200
commitdd2447d2ca7276625a816ca53768fe1d3a47ce35 (patch)
tree6a4eba9d91912f6f0a81dd644d711e30aacf844b
parentAdd test to check binscripts match manpages (diff)
downloaddotfiles-dd2447d2ca7276625a816ca53768fe1d3a47ce35.tar.gz
dotfiles-dd2447d2ca7276625a816ca53768fe1d3a47ce35.zip
Strip stbl(1) down, make POSIX sh
-rwxr-xr-xbin/stbl54
-rw-r--r--man/man1/stbl.112
2 files changed, 7 insertions, 59 deletions
diff --git a/bin/stbl b/bin/stbl
index 2304000f..546349a0 100755
--- a/bin/stbl
+++ b/bin/stbl
@@ -1,58 +1,10 @@
-#!/usr/bin/env bash
+#!/bin/sh
# Strip a trailing blank line from the given files with ed(1)
-self=stbl
-
-# Print usage information
-usage() {
- printf '%s: usage: %s [-hv] [--] FILE1 [FILE2...]\n' \
- "$self" "$self"
-}
-
-# Flag for whether to print diagnostics to stderr or not; defaults to off
-declare -i verbose
-verbose=0
-
-# Process options
-while getopts 'hv' opt ; do
- case $opt in
-
- # -h: Print help
- h)
- usage
- exit 0
- ;;
-
- # -v: Print diagnostics to stderr
- v)
- verbose=1
- ;;
-
- # Unknown option
- \?)
- usage >&2
- exit 2
- ;;
- esac
-done
-shift "$((OPTIND-1))"
-
-# Check we have arguments left
-if ! (($#)) ; then
- usage >&2
+if [ "$#" -eq 0 ] ; then
+ printf 2>&1 'stbl: Need at least one file to edit\n'
exit 2
fi
-
-# Check we have ed(1)
-hash ed || exit
-
-# Iterate through the arguments
for fn ; do
-
- # If verbose is set, print what we're doing
- ((verbose)) && printf '%s: %s\n' \
- "$self" "$fn" >&2
-
- # Run the ed script to strip the trailing blank lines
ed -s -- "$fn" <<'EOF'
$g/^ *$/d
w
diff --git a/man/man1/stbl.1 b/man/man1/stbl.1
index 1462f80f..dfb930ab 100644
--- a/man/man1/stbl.1
+++ b/man/man1/stbl.1
@@ -1,15 +1,11 @@
-.TH STBL 1 "March 2016" "Manual page for stbl"
+.TH STBL 1 "August 2016" "Manual page for stbl"
.SH NAME
.B stbl
\- strip a trailing blank line from a file
.SH USAGE
-.B stbl [-hv] FILE1 [FILE2 ...]
+.B stbl FILE1 [FILE2 ...]
.SH DESCRIPTION
-Applies ed(1) to remove a trailing newline from each of the given files.
-.P
-Option -h gives help, option -v turns on verbose output.
-.P
- $ stbl .bashrc
- $ stbl -v project/*.c project/*.h
+Applies ed(1) to remove one trailing newline, if present, from each of the
+given files.
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>