diff options
author | EuAndreh <eu@euandre.org> | 2022-08-12 18:57:47 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-08-12 18:57:47 -0300 |
commit | 79dc0af8db711e15e3b5c9f50702652317ffdd30 (patch) | |
tree | 72f197844c0352b8b9970a7eaee8ae1d2f9e92f6 /bin/80 | |
parent | bin/color: Replace ad-hoc `assert_arg()` with `assert-arg` (diff) | |
download | dotfiles-79dc0af8db711e15e3b5c9f50702652317ffdd30.tar.gz dotfiles-79dc0af8db711e15e3b5c9f50702652317ffdd30.tar.xz |
bin/80: Add helper utility
Diffstat (limited to 'bin/80')
-rwxr-xr-x | bin/80 | 85 |
1 files changed, 85 insertions, 0 deletions
@@ -0,0 +1,85 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + 80 [FILENAME...] + 80 -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + FILENAME the name of the file to work on (default: + the list of file in the VCS repository) + + + List the lines in the files that contain more than 80 columns. + + + Examples: + + Check for all the files in the current repository: + + $ 80 + + + Detect on the given two files: + + $ 80 f1 f2 + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +len() { + awk ' + length > 80 { + printf "%s:%s:%s\n", FILENAME, FNR, $0 + } + ' "$1" +} + +if [ $# = 0 ]; then + vcs ls-files | while read -r f; do + len "$f" + done +else + for f in "$@"; do + len "$f" + done +fi |