aboutsummaryrefslogtreecommitdiff
path: root/bin/80
diff options
context:
space:
mode:
Diffstat (limited to 'bin/80')
-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