- 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
79 lines
2.1 KiB
Bash
Executable File
79 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Function to read tmux options with default values
|
|
get_tmux_option() {
|
|
local option="$1"
|
|
local default_value="$2"
|
|
local option_value
|
|
option_value=$(tmux show-option -gqv "$option")
|
|
if [ -z "$option_value" ]; then
|
|
echo "$default_value"
|
|
else
|
|
echo "$option_value"
|
|
fi
|
|
}
|
|
|
|
# Example: read user configuration
|
|
# my_option=$(get_tmux_option "@plugin_option" "default_value")
|
|
|
|
function get_datetime {
|
|
date "+%d/%m/%Y %H:%M"
|
|
}
|
|
|
|
function show_reminders {
|
|
local datetime
|
|
datetime=$(get_datetime)
|
|
|
|
# Ottieni la larghezza della finestra tmux corrente
|
|
local tmux_width
|
|
tmux_width=$(tmux display-message -p '#{window_width}')
|
|
|
|
# Esporta la larghezza per lo script
|
|
export TERM_WIDTH="$tmux_width"
|
|
|
|
# Esegui lo script per generare l'output e ottenere le informazioni
|
|
local output
|
|
output=$("$CURRENT_DIR/show_reminders.sh")
|
|
|
|
local tmp_file
|
|
local max_line_width
|
|
tmp_file=$(echo "$output" | head -n1)
|
|
max_line_width=$(echo "$output" | tail -n1)
|
|
|
|
# Imposta larghezza minima 40, massima = larghezza finestra tmux
|
|
local popup_width
|
|
if [ -z "$max_line_width" ] || [ "$max_line_width" -lt 40 ]; then
|
|
popup_width=40
|
|
elif [ "$max_line_width" -gt "$tmux_width" ]; then
|
|
popup_width="99%"
|
|
else
|
|
# Aggiungi qualche carattere per margini
|
|
popup_width=$((max_line_width + 4))
|
|
if [ "$popup_width" -gt "$tmux_width" ]; then
|
|
popup_width="$tmux_width"
|
|
fi
|
|
fi
|
|
|
|
tmux display-popup -T "#[align=centre]Today's Reminders - $datetime" -w "$popup_width" -h 60% -x C -y C -E -- "$CURRENT_DIR/show_reminders.sh" "$tmp_file"
|
|
}
|
|
|
|
function show_calendar {
|
|
local datetime
|
|
datetime=$(get_datetime)
|
|
tmux display-popup -T "#[align=centre]Next 4 Weeks - $datetime" -w 99% -h 99% -x C -y C -E -- "$CURRENT_DIR/show_calendar.sh"
|
|
}
|
|
|
|
function main {
|
|
if [ "$1" == "reminders" ]; then
|
|
show_reminders
|
|
else
|
|
show_calendar
|
|
fi
|
|
}
|
|
|
|
main "$@"
|