diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-03 13:35:17 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-03 13:35:17 +1200 |
commit | dd2447d2ca7276625a816ca53768fe1d3a47ce35 (patch) | |
tree | 6a4eba9d91912f6f0a81dd644d711e30aacf844b /bin/stbl | |
parent | Add test to check binscripts match manpages (diff) | |
download | dotfiles-dd2447d2ca7276625a816ca53768fe1d3a47ce35.tar.gz dotfiles-dd2447d2ca7276625a816ca53768fe1d3a47ce35.zip |
Strip stbl(1) down, make POSIX sh
Diffstat (limited to 'bin/stbl')
-rwxr-xr-x | bin/stbl | 54 |
1 files changed, 3 insertions, 51 deletions
@@ -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 |