~chambln/dots

e46b4974aab094a9f12a1f3d6cda051cb99df0d3 — Gregory Chamberlain 14 days ago a6330ad
sh: Add ltw
1 files changed, 30 insertions(+), 0 deletions(-)

A sh/bin/ltw
A sh/bin/ltw => sh/bin/ltw +30 -0
@@ 0,0 1,30 @@
#!/bin/sh
# lint text width

usage() {
    printf 'Usage: %s [-w WIDTH] FILE... \n' "${0##*/}" >&2
    exit 2
}

WIDTH=80
while getopts w: OPT; do
    case $OPT in
        w) WIDTH=$OPTARG ;;
        ?) usage
    esac
done
shift $((OPTIND - 1))

[ $# -gt 0 ] || usage

s=0
for file do
    while ln=$((ln+1)) && IFS= read -r line; do
        if [ ${#line} -gt "$WIDTH" ]; then
            s=1
            printf '%s:%d:%d: %s\n' "$file" "$ln" "${#line}" "$line"
        fi
    done < "$file"
done

exit $s