cal as preview

This commit is contained in:
Ämin Baumeler 2025-06-10 22:33:10 +02:00
parent 7cd8d0ffa8
commit 9558a1d593

View File

@ -112,6 +112,13 @@ EOF
EOF EOF
) )
export AWK_NEW export AWK_NEW
AWK_CAL=$(
cat <<'EOF'
@@include src/awk/cal.awk
EOF
)
export AWK_CAL
### END OF AWK SCRIPTS ### END OF AWK SCRIPTS
## Colors ## Colors
@ -381,6 +388,52 @@ if [ "${1:-}" = "--preview" ]; then
exit exit
fi fi
if [ "${1:-}" = "--preview-week" ]; then
sign=$(echo "$2" | cut -d '|' -f 1)
if [ "$sign" = "+" ]; then
startdate=$(echo "$2" | cut -d '|' -f 2)
set -- $(date -d "$startdate" +"%Y %m %d")
year=$1
month=$2
day=$3
set -- $(date -d "today" +"%Y %m %d")
year_cur=$1
month_cur=$2
day_cur=$3
# Previous month
if [ "$month" -eq 1 ]; then
month_pre=12
year_pre=$((year - 1))
else
month_pre=$((month - 1))
year_pre=$year
fi
# Next month
if [ "$month" -eq 12 ]; then
month_nex=1
year_nex=$((year + 1))
else
month_nex=$((month + 1))
year_nex=$year
fi
# Highlight today
if [ "$month_pre" -eq "$month_cur" ] && [ "$year_pre" -eq "$year_cur" ]; then
var_pre=$day_cur
fi
if [ "$month" -eq "$month_cur" ] && [ "$year" -eq "$year_cur" ]; then
var=$day_cur
fi
if [ "$month_nex" -eq "$month_cur" ] && [ "$year_nex" -eq "$year_cur" ]; then
var_nex=$day_cur
fi
# show
cal "$month_pre" "$year_pre" | awk -v cur="${var_pre:-}" "$AWK_CAL"
cal "$month" "$year" | awk -v cur="${var:-}" -v day="$day" "$AWK_CAL"
cal "$month_nex" "$year_nex" | awk -v cur="${var_nex:-}" "$AWK_CAL"
fi
exit
fi
if [ "${1:-}" = "--delete" ]; then if [ "${1:-}" = "--delete" ]; then
fpath=$(echo "$2" | cut -d '|' -f 4 | sed "s/ /|/g") fpath=$(echo "$2" | cut -d '|' -f 4 | sed "s/ /|/g")
if [ -n "$fpath" ]; then if [ -n "$fpath" ]; then
@ -480,6 +533,8 @@ selection=$(
--ansi \ --ansi \
--no-clear \ --no-clear \
--no-scrollbar \ --no-scrollbar \
--preview-window=right,21 \
--preview="$0 --preview-week {}" \
--expect="ctrl-n" \ --expect="ctrl-n" \
--bind="load:pos($DISPLAY_POS)" \ --bind="load:pos($DISPLAY_POS)" \
--bind="ctrl-u:become($0 --date '$DISPLAY_DATE_PREV')" \ --bind="ctrl-u:become($0 --date '$DISPLAY_DATE_PREV')" \