From 6432d37df3b080556d4a422c70b2901667089883 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Tue, 16 Dec 2025 18:29:45 +0100 Subject: [PATCH] add -w flag for custom widths --- README.md | 1 + allioli.awk | 6 ++---- allioli.sh | 17 ++++++++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9029416..9b62426 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Code largely based off of [https://github.com/bontibon/kjv.git](https://github.c usage: ./allioli [flags] [reference...] -l list books + -w set custom terminal width -W no line wrap -F no footnotes -g show only German (no Latin) diff --git a/allioli.awk b/allioli.awk index fd1281e..7a3a3f7 100644 --- a/allioli.awk +++ b/allioli.awk @@ -7,11 +7,9 @@ BEGIN { # $6 Verse FS = "\t" - MAX_WIDTH = 100 + MAX_WIDTH = 120 if (ENVIRON["ALLIOLI_MAX_WIDTH"] ~ /^[0-9]+$/) { - if (int(ENVIRON["ALLIOLI_MAX_WIDTH"]) < MAX_WIDTH) { - MAX_WIDTH = int(ENVIRON["ALLIOLI_MAX_WIDTH"]) - } + MAX_WIDTH = int(ENVIRON["ALLIOLI_MAX_WIDTH"]) } if (cmd == "ref") { diff --git a/allioli.sh b/allioli.sh index ee6b0cb..e145d9f 100755 --- a/allioli.sh +++ b/allioli.sh @@ -21,6 +21,7 @@ show_help() { echo "usage: $(basename "$0") [flags] [reference...]" echo echo " -l list books" + echo " -w set custom terminal width" echo " -W no line wrap" echo " -F no footnotes" echo " -g show only German (no Latin)" @@ -64,6 +65,14 @@ while [ $# -gt 0 ]; do # List all book names with their abbreviations get_data allioli.tsv | awk -v cmd=list "$(get_data allioli.awk)" exit + elif [ "$1" = "-w" ]; then + shift + if [ $# -eq 0 ] || [ -z "$1" ]; then + echo "error: -w requires a width argument" >&2 + exit 1 + fi + export ALLIOLI_MAX_WIDTH="$1" + shift elif [ "$1" = "-W" ]; then export ALLIOLI_NOLINEWRAP=1 shift @@ -83,9 +92,11 @@ while [ $# -gt 0 ]; do fi done -cols=$(tput cols 2>/dev/null) -if [ $? -eq 0 ]; then - export ALLIOLI_MAX_WIDTH="$cols" +if [ -z "$ALLIOLI_MAX_WIDTH" ]; then + cols=$(tput cols 2>/dev/null) + if [ $? -eq 0 ]; then + export ALLIOLI_MAX_WIDTH="$cols" + fi fi if [ $# -eq 0 ]; then