add -w flag for custom widths

This commit is contained in:
2025-12-16 18:29:45 +01:00
parent 7300ba933c
commit 6432d37df3
3 changed files with 17 additions and 7 deletions

View File

@@ -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 <n> set custom terminal width
-W no line wrap
-F no footnotes
-g show only German (no Latin)

View File

@@ -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") {

View File

@@ -21,6 +21,7 @@ show_help() {
echo "usage: $(basename "$0") [flags] [reference...]"
echo
echo " -l list books"
echo " -w <n> 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