feat: add check-help-width utility to detect terminal overflow

This commit is contained in:
Janik von Rotz committed 2026-10-12 17:06:14 +02:00
1 parent b21ed4078e
commit 578794065f
4 files changed
+104 -2

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
check-help-width() {
local term_width
term_width=$(tput cols 2>/dev/null || echo 80)
echo "Terminal width: $term_width"
echo
local max_line_width=0
local -a overflow_lines=()
while IFS= read -r line; do
local line_width=${#line}
if (( line_width > max_line_width )); then
max_line_width=$line_width
fi
# Skip table structure lines (separators, headers)
[[ "$line" =~ ^\|[-]+.* ]] && continue
[[ "$line" =~ ^\|[[:space:]]*Command[[:space:]]*\| ]] && continue
# Skip group header rows where option and description are empty
local -a fields
IFS='|' read -ra fields <<< "$line"
local opt_field="${fields[2]:-}"
local desc_field="${fields[3]:-}"
[[ -z "${opt_field// /}" && -z "${desc_field// /}" ]] && continue
if (( line_width > term_width )); then
overflow_lines+=("$line")
fi
done < <(help-table)
echo "Max table line width: $max_line_width"
if (( ${#overflow_lines[@]} > 0 )); then
echo
echo "Warning: The following commands exceed terminal width ($term_width):"
for line in "${overflow_lines[@]}"; do
printf ' %s\n' "$line"
done
return 1
else
echo "All commands fit within terminal width."
return 0
fi
}
chmw() {
check-help-width "$@"
}
+6
View File
@@ -106,6 +106,12 @@ rows+=("setup-completion|[shell]|Show shell completion instructions.")
rows+=("list-aliases||List all library command aliases.")
```
### check-help-width
```bash
rows+=("check-help-width||Show help lines that exceed terminal width.")
```
<!-- ===Task=== -->
## Files
+48 -2
View File
@@ -13,12 +13,13 @@ help-table() {
rows+=("dev-zensical-docs||Run Zensical documentation development server.")
rows+=("build-zensical-docs||Build the Zensical documentation website.")
rows+=("serve-zensical-docs||Serve the Zensical documentation build folder.")
rows+=("clone-taskfile||Clone or pull the taskfile.build repo.")
rows+=("lint||Lint code with shellcheck.")
rows+=("run-container||Run Docker image.")
rows+=("run-tests||Test with shellcheck.")
rows+=("set-git-origin||Change git origin to ssh.")
rows+=("update-install-script||Update install script with bin commands.")
rows+=("update-install-script||Update scripts.txt with bin commands.")
rows+=("update-task-template-help||Update task.template help rows from library.md.")
rows+=("check-help-width||Show help lines that exceed terminal width.")
rows+=("version||Show version of required tools.")
for row in "${rows[@]}"; do
@@ -93,6 +94,51 @@ help() {
echo
}
check-help-width() {
local term_width
term_width=$(tput cols 2>/dev/null || echo 80)
echo "Terminal width: $term_width"
echo
local max_line_width=0
local -a overflow_lines=()
while IFS= read -r line; do
local line_width=${#line}
if (( line_width > max_line_width )); then
max_line_width=$line_width
fi
# Skip table structure lines (separators, headers)
[[ "$line" =~ ^\|[-]+.* ]] && continue
[[ "$line" =~ ^\|[[:space:]]*Command[[:space:]]*\| ]] && continue
# Skip group header rows where option and description are empty
local -a fields
IFS='|' read -ra fields <<< "$line"
local opt_field="${fields[2]:-}"
local desc_field="${fields[3]:-}"
[[ -z "${opt_field// /}" && -z "${desc_field// /}" ]] && continue
if (( line_width > term_width )); then
overflow_lines+=("$line")
fi
done < <(help-table)
echo "Max table line width: $max_line_width"
if (( ${#overflow_lines[@]} > 0 )); then
echo
echo "Warning: The following commands exceed terminal width ($term_width):"
for line in "${overflow_lines[@]}"; do
printf ' %s\n' "$line"
done
return 1
else
echo "All commands fit within terminal width."
return 0
fi
}
clone-taskfile(){
if [[ ! -d "$HOME/taskfile.build" ]]; then
echo -e '\033[38;5;214mGit\033[0m: Clone taskfile repo'
+1
View File
@@ -21,6 +21,7 @@ help-table() {
rows+=("show-dotenv-setup||Show info about the dotenv setup.")
rows+=("setup-completion|[shell]|Show shell completion instructions.")
rows+=("list-aliases||List all library command aliases.")
rows+=("check-help-width||Show help lines that exceed terminal width.")
rows+=("===Files===| | ")
rows+=("ensure-directory|<path>|Ensure directory path exists.")
rows+=("create-symlink|<source><target>|Remove existing file/directory and create symlink.")