#!/bin/bash # ╭─────────────────────────────────────────╮ # │ roundbox, rewriten by chatgpt in 2025 │ # │ (replaces old roundbox and multibox) │ # │ │ # │ usage examples: │ # │ echo "woot\nwoot" | roundbox │ # │ cat file.txt | roundbox │ # │ roundbox "woot\nwoot" │ # │ │ # │ note: If max line lenght > term width, │ # │ lines will be truncated │ # ╰─────────────────────────────────────────╯ # If there's an argument, use it; otherwise, read from stdin if [[ -n "$1" ]]; then input_text=$(printf "%b" "$1") else input_text=$(cat) fi # Normalize tabs input_text=$(printf "%s" "$input_text" | expand) # Terminal width logic term_width=$(tput cols) max_allowed_length=$(( term_width - 4 )) # 2 padding + 2 borders # Truncate long lines and compute max length max_length=0 trimmed_lines=() while IFS= read -r line; do # Truncate if needed if (( ${#line} > max_allowed_length )); then line=${line:0:max_allowed_length} fi trimmed_lines+=("$line") (( ${#line} > max_length )) && max_length=${#line} done <<< "$input_text" # Top border echo "╭$(printf '─%.0s' $(seq 1 $((max_length + 2))))╮" # Boxed lines for line in "${trimmed_lines[@]}"; do padding=$(( max_length - ${#line} )) printf "│ %s%*s │\n" "$line" "$padding" "" done # Bottom border echo "╰$(printf '─%.0s' $(seq 1 $((max_length + 2))))╯"