Compare commits
8 Commits
7a22f73d36
...
f025ecd0bb
Author | SHA1 | Date | |
---|---|---|---|
f025ecd0bb | |||
5ebcc4feb6 | |||
3a95c1e162 | |||
c9759a0fc5 | |||
9558a1d593 | |||
7cd8d0ffa8 | |||
e4fe586db3 | |||
6357eddbec |
18
src/awk/cal.awk
Normal file
18
src/awk/cal.awk
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
BEGIN {
|
||||||
|
BLACK = "\033[1;30m"
|
||||||
|
GREEN = "\033[1;32m"
|
||||||
|
RED = "\033[1;31m"
|
||||||
|
FAINT = "\033[2m"
|
||||||
|
BOLD = "\033[1m"
|
||||||
|
BG = "\033[41m"
|
||||||
|
OFF = "\033[m"
|
||||||
|
day = day + 0
|
||||||
|
cur = cur + 0
|
||||||
|
}
|
||||||
|
NR == 1 { print GREEN $0 OFF; next }
|
||||||
|
NR == 2 { print FAINT $0 OFF; next }
|
||||||
|
{
|
||||||
|
sub("\\y"cur"\\y", BG BLACK BOLD cur OFF)
|
||||||
|
sub("\\y"day"\\y", RED BOLD day OFF)
|
||||||
|
print
|
||||||
|
}
|
200
src/main.sh
200
src/main.sh
@ -32,7 +32,7 @@ if [ -z "${FZF_VCAL_USE_EXPORTED:-}" ]; then
|
|||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
if command -v "fzf" >/dev/null; then
|
if command -v "fzf" >/dev/null; then
|
||||||
FZF="fzf"
|
FZF="fzf --black"
|
||||||
else
|
else
|
||||||
err "Did not find the command-line fuzzy finder fzf."
|
err "Did not find the command-line fuzzy finder fzf."
|
||||||
exit 1
|
exit 1
|
||||||
@ -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
|
||||||
@ -313,10 +320,7 @@ __refresh_data() {
|
|||||||
export WEEKLY_DATA_FILE
|
export WEEKLY_DATA_FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -z "${APPROX_DATA_FILE:-}" ]; then
|
## Start
|
||||||
__refresh_data
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--help" ]; then
|
if [ "${1:-}" = "--help" ]; then
|
||||||
echo "Usage: $0 [OPTION]"
|
echo "Usage: $0 [OPTION]"
|
||||||
echo ""
|
echo ""
|
||||||
@ -324,6 +328,7 @@ if [ "${1:-}" = "--help" ]; then
|
|||||||
echo " --help Show this help and exit"
|
echo " --help Show this help and exit"
|
||||||
echo " --new Create new entry"
|
echo " --new Create new entry"
|
||||||
echo " --today Show today's appointments"
|
echo " --today Show today's appointments"
|
||||||
|
echo " --goto Interactively enter date to jump to"
|
||||||
echo " --day <day> Show appointments of specified day"
|
echo " --day <day> Show appointments of specified day"
|
||||||
echo " --date <date> Show week of specified date"
|
echo " --date <date> Show week of specified date"
|
||||||
exit
|
exit
|
||||||
@ -333,6 +338,17 @@ if [ "${1:-}" = "--today" ]; then
|
|||||||
exec $0 --day "today"
|
exec $0 --day "today"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--goto" ]; then
|
||||||
|
DISPLAY_DATE=""
|
||||||
|
while [ -z "$DISPLAY_DATE" ]; do
|
||||||
|
printf "Enter date you want to jump to, e.g., today + 1 month or 2024-1-14: " >/dev/tty
|
||||||
|
read -r tmp
|
||||||
|
if date -d "$tmp"; then
|
||||||
|
DISPLAY_DATE="$tmp"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "${1:-}" = "--new" ]; then
|
if [ "${1:-}" = "--new" ]; then
|
||||||
collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
|
collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
|
||||||
fpath=""
|
fpath=""
|
||||||
@ -340,7 +356,7 @@ if [ "${1:-}" = "--new" ]; then
|
|||||||
uuid=$($UUIDGEN)
|
uuid=$($UUIDGEN)
|
||||||
fpath="$ROOT/$collection/$uuid.ics"
|
fpath="$ROOT/$collection/$uuid.ics"
|
||||||
done
|
done
|
||||||
startsec=$(date -d "$2" +"%s")
|
startsec=$(date -d "${2:-today 8:00}" +"%s")
|
||||||
endsec=$((startsec + 3600))
|
endsec=$((startsec + 3600))
|
||||||
start=$(__canonical_datetime_hm "$startsec")
|
start=$(__canonical_datetime_hm "$startsec")
|
||||||
end=$(__canonical_datetime_hm "$endsec")
|
end=$(__canonical_datetime_hm "$endsec")
|
||||||
@ -364,6 +380,58 @@ if [ "${1:-}" = "--new" ]; then
|
|||||||
rm "$filetmp"
|
rm "$filetmp"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "${APPROX_DATA_FILE:-}" ]; then
|
||||||
|
__refresh_data
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--day" ]; then
|
||||||
|
DISPLAY_DATE="${2:-today}"
|
||||||
|
export DISPLAY_DATE
|
||||||
|
selection=$(
|
||||||
|
__show_day |
|
||||||
|
$FZF \
|
||||||
|
--reverse \
|
||||||
|
--ansi \
|
||||||
|
--no-sort \
|
||||||
|
--no-input \
|
||||||
|
--margin='20%' \
|
||||||
|
--border='double' \
|
||||||
|
--border-label="🗓️ $(date -d "$DISPLAY_DATE" +"%A %e %B %Y")" \
|
||||||
|
--color=label:bold:green \
|
||||||
|
--border-label-pos=3 \
|
||||||
|
--cycle \
|
||||||
|
--delimiter='|' \
|
||||||
|
--with-nth='{5}' \
|
||||||
|
--accept-nth='1,2,3,4' \
|
||||||
|
--preview="$0 --preview {}" \
|
||||||
|
--expect="ctrl-n,esc,backspace,q" \
|
||||||
|
--bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)" \
|
||||||
|
--bind="ctrl-alt-d:become($0 --delete {})"
|
||||||
|
)
|
||||||
|
key=$(echo "$selection" | head -1)
|
||||||
|
line=$(echo "$selection" | tail -1)
|
||||||
|
if [ "$line" = "$key" ]; then
|
||||||
|
line=""
|
||||||
|
fi
|
||||||
|
hour=$(echo "$line" | cut -d '|' -f 1)
|
||||||
|
start=$(echo "$line" | cut -d '|' -f 2)
|
||||||
|
end=$(echo "$line" | cut -d '|' -f 3)
|
||||||
|
fpath=$(echo "$line" | cut -d '|' -f 4 | sed "s/ /|/g")
|
||||||
|
if [ "$key" = "ctrl-n" ]; then
|
||||||
|
if echo "$hour" | grep ":"; then
|
||||||
|
hour="$DAY_START"
|
||||||
|
fi
|
||||||
|
exec $0 --new "$DISPLAY_DATE $hour:00"
|
||||||
|
elif [ -z "$key" ] && [ -n "$fpath" ]; then
|
||||||
|
fpath="$ROOT/$fpath"
|
||||||
|
__edit "$start" "$end" "$fpath"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--date" ]; then
|
||||||
|
DISPLAY_DATE="$2"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "${1:-}" = "--preview" ]; then
|
if [ "${1:-}" = "--preview" ]; then
|
||||||
hour=$(echo "$2" | cut -d '|' -f 1)
|
hour=$(echo "$2" | cut -d '|' -f 1)
|
||||||
start=$(echo "$2" | cut -d '|' -f 2)
|
start=$(echo "$2" | cut -d '|' -f 2)
|
||||||
@ -381,6 +449,54 @@ 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"
|
||||||
|
) | awk '{ l[NR%8] = l[NR%8] " " $0 } END {for (i in l) if (i>0) print l[i] }'
|
||||||
|
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
|
||||||
@ -407,63 +523,26 @@ if [ "${1:-}" = "--delete" ]; then
|
|||||||
exec $0 --day "$DISPLAY_DATE"
|
exec $0 --day "$DISPLAY_DATE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${1:-}" = "--day" ]; then
|
if [ "${1:-}" = "--all" ]; then
|
||||||
DISPLAY_DATE="$2"
|
cat "$APPROX_DATA_FILE"
|
||||||
export DISPLAY_DATE
|
exit
|
||||||
selection=$(
|
|
||||||
__show_day |
|
|
||||||
$FZF \
|
|
||||||
--reverse \
|
|
||||||
--ansi \
|
|
||||||
--no-sort \
|
|
||||||
--no-input \
|
|
||||||
--margin='20%' \
|
|
||||||
--border='double' \
|
|
||||||
--border-label="🗓️ $(date -d "$DISPLAY_DATE" +"%A %e %B %Y")" \
|
|
||||||
--color=label:bold:green \
|
|
||||||
--border-label-pos=3 \
|
|
||||||
--delimiter='|' \
|
|
||||||
--with-nth='{5}' \
|
|
||||||
--accept-nth='1,2,3,4' \
|
|
||||||
--preview="$0 --preview {}" \
|
|
||||||
--expect="ctrl-n,esc,backspace" \
|
|
||||||
--bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)" \
|
|
||||||
--bind="ctrl-alt-d:become($0 --delete {})"
|
|
||||||
)
|
|
||||||
key=$(echo "$selection" | head -1)
|
|
||||||
line=$(echo "$selection" | tail -1)
|
|
||||||
hour=$(echo "$line" | cut -d '|' -f 1)
|
|
||||||
start=$(echo "$line" | cut -d '|' -f 2)
|
|
||||||
end=$(echo "$line" | cut -d '|' -f 3)
|
|
||||||
fpath=$(echo "$line" | cut -d '|' -f 4 | sed "s/ /|/g")
|
|
||||||
if [ "$key" = "ctrl-n" ]; then
|
|
||||||
if echo "$hour" | grep ":"; then
|
|
||||||
hour="$DAY_START"
|
|
||||||
fi
|
|
||||||
exec $0 --new "$DISPLAY_DATE $hour:00"
|
|
||||||
elif [ -n "$fpath" ]; then
|
|
||||||
fpath="$ROOT/$fpath"
|
|
||||||
__edit "$start" "$end" "$fpath"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${1:-}" = "--date" ]; then
|
|
||||||
DISPLAY_DATE="$2"
|
|
||||||
fi
|
|
||||||
DISPLAY_DATE=${DISPLAY_DATE:-today}
|
DISPLAY_DATE=${DISPLAY_DATE:-today}
|
||||||
DISPLAY_DATE=$(date -d "$DISPLAY_DATE" +"%D")
|
DISPLAY_DATE=$(date -d "$DISPLAY_DATE" +"%D")
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--list" ]; then
|
||||||
|
__list
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
DISPLAY_POS=$((8 - $(date -d "$DISPLAY_DATE" +"%u")))
|
DISPLAY_POS=$((8 - $(date -d "$DISPLAY_DATE" +"%u")))
|
||||||
DISPLAY_DATE_PREV=$(date -d "$DISPLAY_DATE -1 week" +"%D")
|
DISPLAY_DATE_PREV=$(date -d "$DISPLAY_DATE -1 week" +"%D")
|
||||||
DISPLAY_DATE_NEXT=$(date -d "$DISPLAY_DATE +1 week" +"%D")
|
DISPLAY_DATE_NEXT=$(date -d "$DISPLAY_DATE +1 week" +"%D")
|
||||||
DISPLAY_DATE_PREV_MONTH=$(date -d "$DISPLAY_DATE -1 month" +"%D")
|
DISPLAY_DATE_PREV_MONTH=$(date -d "$DISPLAY_DATE -1 month" +"%D")
|
||||||
DISPLAY_DATE_NEXT_MONTH=$(date -d "$DISPLAY_DATE +1 month" +"%D")
|
DISPLAY_DATE_NEXT_MONTH=$(date -d "$DISPLAY_DATE +1 month" +"%D")
|
||||||
|
|
||||||
selection=$(
|
selection=$(
|
||||||
(
|
__list |
|
||||||
cat "$APPROX_DATA_FILE"
|
|
||||||
yes " " | head -n 50
|
|
||||||
__list
|
|
||||||
) |
|
|
||||||
$FZF \
|
$FZF \
|
||||||
--tac \
|
--tac \
|
||||||
--no-sort \
|
--no-sort \
|
||||||
@ -474,24 +553,35 @@ selection=$(
|
|||||||
--accept-nth=1,2 \
|
--accept-nth=1,2 \
|
||||||
--no-info \
|
--no-info \
|
||||||
--ansi \
|
--ansi \
|
||||||
--no-clear \
|
|
||||||
--no-scrollbar \
|
--no-scrollbar \
|
||||||
|
--preview-window=up,7,border-bottom \
|
||||||
|
--preview="$0 --preview-week {}" \
|
||||||
--expect="ctrl-n" \
|
--expect="ctrl-n" \
|
||||||
|
--bind="change:reload($0 --all)+hide-preview" \
|
||||||
|
--bind="backward-eof:reload($0 --list)+show-preview" \
|
||||||
--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')" \
|
||||||
--bind="ctrl-d:become($0 --date '$DISPLAY_DATE_NEXT')" \
|
--bind="ctrl-d:become($0 --date '$DISPLAY_DATE_NEXT')" \
|
||||||
--bind="ctrl-alt-u:become($0 --date '$DISPLAY_DATE_PREV_MONTH')" \
|
--bind="ctrl-alt-u:become($0 --date '$DISPLAY_DATE_PREV_MONTH')" \
|
||||||
--bind="ctrl-alt-d:become($0 --date '$DISPLAY_DATE_NEXT_MONTH')" \
|
--bind="ctrl-alt-d:become($0 --date '$DISPLAY_DATE_NEXT_MONTH')" \
|
||||||
|
--bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)" \
|
||||||
|
--bind="ctrl-g:become($0 --goto)" \
|
||||||
--bind="ctrl-l:become($0)"
|
--bind="ctrl-l:become($0)"
|
||||||
)
|
)
|
||||||
|
|
||||||
key=$(echo "$selection" | head -1)
|
key=$(echo "$selection" | head -1)
|
||||||
line=$(echo "$selection" | tail -1)
|
line=$(echo "$selection" | tail -1)
|
||||||
|
if [ "$line" = "$key" ]; then
|
||||||
|
line=""
|
||||||
|
fi
|
||||||
sign=$(echo "$line" | cut -d '|' -f 1)
|
sign=$(echo "$line" | cut -d '|' -f 1)
|
||||||
startdate=$(echo "$line" | cut -d '|' -f 2)
|
startdate=$(echo "$line" | cut -d '|' -f 2)
|
||||||
if [ "$key" = "ctrl-n" ]; then
|
if [ "$key" = "ctrl-n" ]; then
|
||||||
# Add new
|
# Add new
|
||||||
exec $0 --new "$startdate $DAY_START:00"
|
if [ "$sign" = "~" ]; then
|
||||||
|
startdate=""
|
||||||
|
fi
|
||||||
|
exec $0 --new "${startdate:-today} $DAY_START:00"
|
||||||
fi
|
fi
|
||||||
if [ -z "$key" ] && [ -z "$line" ]; then
|
if [ -z "$key" ] && [ -z "$line" ]; then
|
||||||
rm "$WEEKLY_DATA_FILE" "$APPROX_DATA_FILE"
|
rm "$WEEKLY_DATA_FILE" "$APPROX_DATA_FILE"
|
||||||
|
Loading…
Reference in New Issue
Block a user