- Calculate the maximum line width of the reminders output in `show_reminders.sh` - Pass the calculated width and a temporary file to the tmux popup in `main.sh` - Ensure popup width is at least 40 and does not exceed the tmux window width - Improve display by preventing horizontal scrolling and better fitting content
26 lines
704 B
Bash
Executable File
26 lines
704 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
export LESSCHARSET=utf-8
|
|
unset LESS
|
|
|
|
# Se viene passato un file temporaneo come argomento, mostra il contenuto
|
|
if [ -n "$1" ] && [ -f "$1" ]; then
|
|
less -f -r -S +g --status-line -PM"Riga %lt/%L (%Pb\%)" "$1"
|
|
rm -f "$1"
|
|
exit 0
|
|
fi
|
|
|
|
# Altrimenti, genera l'output e calcola la larghezza
|
|
TERM_WIDTH=${TERM_WIDTH:-$(tput cols)}
|
|
TMP_FILE=$(mktemp)
|
|
|
|
# Cattura l'output di rem
|
|
rem -m -b1 -gaa -q -aa -iinclude_todo=1 -@2 -w"$TERM_WIDTH" >"$TMP_FILE"
|
|
|
|
# Calcola la lunghezza massima delle righe
|
|
MAX_LINE_WIDTH=$(awk '{ if (length > max) max = length } END { print max }' "$TMP_FILE")
|
|
|
|
# Restituisce il file temporaneo e la larghezza massima
|
|
echo "$TMP_FILE"
|
|
echo "$MAX_LINE_WIDTH"
|