diff --git a/bin/check-help-width b/bin/check-help-width new file mode 100755 index 0000000..877f196 --- /dev/null +++ b/bin/check-help-width @@ -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 "$@" +} diff --git a/docs/library.md b/docs/library.md index 66129c4..d34dbf7 100644 --- a/docs/library.md +++ b/docs/library.md @@ -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.") +``` + ## Files diff --git a/task b/task index 4badcab..77cc8a5 100755 --- a/task +++ b/task @@ -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' diff --git a/task.template b/task.template index 9aa02c1..850b5b6 100755 --- a/task.template +++ b/task.template @@ -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||Ensure directory path exists.") rows+=("create-symlink||Remove existing file/directory and create symlink.")