Aqui está uma função que eu coloquei que você poderia usar para imprimir itens relacionados à ajuda, um de cada vez. Eu usei o exemplo de -m
e a longa sequência de ajuda da pergunta. A função codifica com firmeza uma largura de 10 para a primeira coluna e calcula o espaço restante para a coluna 2.
#!/bin/bash
function printhelp() (
c1width=10
cols=$(tput cols)
c2width=$((cols - c1width - 1))
readarray -t lines < <(printf '%s' "$2" | fmt -w $c2width)
for((line=0; line < ${#lines[*]}; line++))
do
if [ $line -eq 0 ]
then
col1="$1"
else
col1=" "
fi
printf "%-${c1width}s %-${c2width}s\n" "$col1" "${lines[line]}"
done
)
optf='-m'
optd='This is a very very very very very very very very very very very very very very very very very very very very long sentence'
printhelp "$optf" "$optd"
Exemplo de saída em uma tela de 50 colunas:
-m This is a very very very very very
very very very very very very very
very very very very very very very
very long sentence
e em uma tela de 80 colunas:
-m This is a very very very very very very very very very very very
very very very very very very very very very long sentence
e em uma tela de 130 colunas:
-m This is a very very very very very very very very very very very very very very very very very very very very
long sentence
e em uma tela de 150 colunas:
-m This is a very very very very very very very very very very very very very very very very very very very very long sentence