aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-08-12 18:57:47 -0300
committerEuAndreh <eu@euandre.org>2022-08-12 18:57:47 -0300
commit79dc0af8db711e15e3b5c9f50702652317ffdd30 (patch)
tree72f197844c0352b8b9970a7eaee8ae1d2f9e92f6 /bin
parentbin/color: Replace ad-hoc `assert_arg()` with `assert-arg` (diff)
downloaddotfiles-79dc0af8db711e15e3b5c9f50702652317ffdd30.tar.gz
dotfiles-79dc0af8db711e15e3b5c9f50702652317ffdd30.tar.xz
bin/80: Add helper utility
Diffstat (limited to 'bin')
-rwxr-xr-xbin/8085
1 files changed, 85 insertions, 0 deletions
diff --git a/bin/80 b/bin/80
new file mode 100755
index 0000000..b971f5d
--- /dev/null
+++ b/bin/80
@@ -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