|
|
|
@ -17,7 +17,6 @@ if [ "${1:-}" = "--help" ]; then
|
|
|
|
|
echo " --day [date] Show appointments of specified day (today)"
|
|
|
|
|
echo " --week [date] Show week of specified date (today)"
|
|
|
|
|
echo " --import file Import iCalendar file"
|
|
|
|
|
echo " --import-ni file Import iCalendar file non-interactively"
|
|
|
|
|
echo " --git cmd Run git command cmd relative to calendar root"
|
|
|
|
|
echo " --git-init Enable the use of git"
|
|
|
|
|
echo ""
|
|
|
|
@ -124,7 +123,7 @@ if [ "${1:-}" = "--preview-event" ]; then
|
|
|
|
|
start=$(datetime_str "$start" "%a ")
|
|
|
|
|
end=$(datetime_str "$end" "%a ")
|
|
|
|
|
location=$(awk -v field="LOCATION" "$AWK_GET" "$fpath")
|
|
|
|
|
echo "📅 ${CYAN}$start${OFF} → ${CYAN}$end${OFF}"
|
|
|
|
|
echo "📅 ${CYAN}$start${OFF} -> ${CYAN}$end${OFF}"
|
|
|
|
|
if [ -n "${location:-}" ]; then
|
|
|
|
|
echo "📍 ${CYAN}$location${OFF}"
|
|
|
|
|
fi
|
|
|
|
@ -138,8 +137,7 @@ fi
|
|
|
|
|
# Print preview of week.
|
|
|
|
|
#
|
|
|
|
|
# @input $2: Line from week view
|
|
|
|
|
# @req $AWK_CALSHIFT: Awk script to make `cal` output to start on Mondays
|
|
|
|
|
# @req $AWK_CALANNOT: Awk script to annotate calendar
|
|
|
|
|
# @req $AWK_CAL: Awk script to annotate calendar
|
|
|
|
|
if [ "${1:-}" = "--preview-week" ]; then
|
|
|
|
|
sign=$(echo "$2" | cut -d '|' -f 1)
|
|
|
|
|
if [ "$sign" = "+" ]; then
|
|
|
|
@ -190,12 +188,12 @@ if [ "${1:-}" = "--preview-week" ]; then
|
|
|
|
|
fi
|
|
|
|
|
# show
|
|
|
|
|
(
|
|
|
|
|
cal "$month_pre2" "$year_pre2" | awk "$AWK_CALSHIFT" | awk -v cur="${var_pre2:-}" "$AWK_CALANNOT"
|
|
|
|
|
cal "$month_pre" "$year_pre" | awk "$AWK_CALSHIFT" | awk -v cur="${var_pre:-}" "$AWK_CALANNOT"
|
|
|
|
|
cal "$month" "$year" | awk "$AWK_CALSHIFT" | awk -v cur="${var:-}" -v day="$day" "$AWK_CALANNOT"
|
|
|
|
|
cal "$month_nex" "$year_nex" | awk "$AWK_CALSHIFT" | awk -v cur="${var_nex:-}" "$AWK_CALANNOT"
|
|
|
|
|
cal "$month_nex2" "$year_nex2" | awk "$AWK_CALSHIFT" | awk -v cur="${var_nex2:-}" "$AWK_CALANNOT"
|
|
|
|
|
cal "$month_nex3" "$year_nex3" | awk "$AWK_CALSHIFT" | awk -v cur="${var_nex3:-}" "$AWK_CALANNOT"
|
|
|
|
|
cal "$month_pre2" "$year_pre2" | awk -v cur="${var_pre2:-}" "$AWK_CAL"
|
|
|
|
|
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"
|
|
|
|
|
cal "$month_nex2" "$year_nex2" | awk -v cur="${var_nex2:-}" "$AWK_CAL"
|
|
|
|
|
cal "$month_nex3" "$year_nex3" | awk -v cur="${var_nex3:-}" "$AWK_CAL"
|
|
|
|
|
) | awk '{ l[NR%8] = l[NR%8] " " $0 } END {for (i in l) if (i>0) print l[i] }'
|
|
|
|
|
fi
|
|
|
|
|
exit
|
|
|
|
@ -242,8 +240,6 @@ __view_day() {
|
|
|
|
|
shift
|
|
|
|
|
fpath="$(echo "$1" | sed 's/|/ /g')" # we will use | as delimiter (need to convert back!)
|
|
|
|
|
shift
|
|
|
|
|
collection="$1"
|
|
|
|
|
shift
|
|
|
|
|
description="$(echo "$*" | sed 's/|/:/g')" # we will use | as delimiter
|
|
|
|
|
#
|
|
|
|
|
daystart=$(date -d "$today 00:00:00" +"%s")
|
|
|
|
@ -263,7 +259,7 @@ __view_day() {
|
|
|
|
|
else
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
echo "$s|$e|$starttime|$endtime|$fpath|$collection|$description"
|
|
|
|
|
echo "$s|$e|$starttime|$endtime|$fpath|$description"
|
|
|
|
|
done)
|
|
|
|
|
fi
|
|
|
|
|
echo "$sef" | sort -n | awk -v today="$today" -v daystart="$DAY_START" -v dayend="$DAY_END" "$AWK_DAYVIEW"
|
|
|
|
@ -450,14 +446,12 @@ fi
|
|
|
|
|
###
|
|
|
|
|
### AWK scripts
|
|
|
|
|
### AWK_APPROX: Generate approximate data of all files
|
|
|
|
|
### AWK_CALSHIFT: Shift calendar to start weeks on Mondays
|
|
|
|
|
### AWK_CALANNOT: Annotate calendar
|
|
|
|
|
### AWK_CAL: Annotate output of `cal`
|
|
|
|
|
### AWK_DAYVIEW: Generate view of the day
|
|
|
|
|
### AWK_GET: Print field of iCalendar file
|
|
|
|
|
### AWK_MERGE: Generate list of weeks with associated iCalendar files
|
|
|
|
|
### AWK_NEW: Make new iCalendar file
|
|
|
|
|
### AWK_PARSE: Timezone aware parsing of iCalendar file for day view
|
|
|
|
|
### AWK_SET: Set value of specific field in iCalendar file
|
|
|
|
|
### AWK_UPDATE: Update iCalendar file
|
|
|
|
|
### AWK_WEEKVIEW: Generate view of the week
|
|
|
|
|
###
|
|
|
|
@ -511,21 +505,9 @@ AWK_NEW=$(
|
|
|
|
|
EOF
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
AWK_CALSHIFT=$(
|
|
|
|
|
AWK_CAL=$(
|
|
|
|
|
cat <<'EOF'
|
|
|
|
|
@@include src/awk/calshift.awk
|
|
|
|
|
EOF
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
AWK_CALANNOT=$(
|
|
|
|
|
cat <<'EOF'
|
|
|
|
|
@@include src/awk/calannot.awk
|
|
|
|
|
EOF
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
AWK_SET=$(
|
|
|
|
|
cat <<'EOF'
|
|
|
|
|
@@include src/awk/set.awk
|
|
|
|
|
@@include src/awk/cal.awk
|
|
|
|
|
EOF
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -620,7 +602,6 @@ __datetime_human_machine() {
|
|
|
|
|
### __edit
|
|
|
|
|
### __new
|
|
|
|
|
### __delete
|
|
|
|
|
### __import_to_collection
|
|
|
|
|
|
|
|
|
|
# __edit()
|
|
|
|
|
# Edit iCalendar file.
|
|
|
|
@ -771,71 +752,13 @@ __delete() {
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# __import_to_collection()
|
|
|
|
|
# Import iCalendar file to specified collection. The only modification made to
|
|
|
|
|
# the file is setting the UID.
|
|
|
|
|
#
|
|
|
|
|
# @input $1: path to iCalendar file
|
|
|
|
|
# @input $2: collection name
|
|
|
|
|
# @req $ROOT: Path that contains the collections (see configuration)
|
|
|
|
|
# @req $UUIDGEN: `uuidgen` command
|
|
|
|
|
# @req $AWK_SET: Awk script to set field value
|
|
|
|
|
__import_to_collection() {
|
|
|
|
|
file="$1"
|
|
|
|
|
collection="$2"
|
|
|
|
|
fpath=""
|
|
|
|
|
while [ -f "$fpath" ] || [ -z "$fpath" ]; do
|
|
|
|
|
uuid=$($UUIDGEN)
|
|
|
|
|
fpath="$ROOT/$collection/$uuid.ics"
|
|
|
|
|
done
|
|
|
|
|
filetmp=$(mktemp)
|
|
|
|
|
awk -v field="UID" -v value="$uuid" "$AWK_SET" "$file" >"$filetmp"
|
|
|
|
|
mv "$filetmp" "$fpath"
|
|
|
|
|
if [ -n "${GIT:-}" ]; then
|
|
|
|
|
$GIT add "$fpath"
|
|
|
|
|
$GIT commit -m "Imported event" -- "$fpath"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
### Extra command-line options
|
|
|
|
|
### --import-ni
|
|
|
|
|
### --import
|
|
|
|
|
### --git
|
|
|
|
|
### --git-init
|
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
# --import-ni
|
|
|
|
|
# Import iCalendar file noninteractively
|
|
|
|
|
#
|
|
|
|
|
# @input $2: Absolute path to iCalendar file
|
|
|
|
|
# @input $3: Collection
|
|
|
|
|
# @req $COLLECTION_LABELS: Mapping between collections and labels (see configuration)
|
|
|
|
|
# @req $ROOT: Path that contains the collections (see configuration)
|
|
|
|
|
# @return: On success, returns 0, otherwise 1
|
|
|
|
|
if [ "${1:-}" = "--import-ni" ]; then
|
|
|
|
|
shift
|
|
|
|
|
file="${1:-}"
|
|
|
|
|
collection="${2:-}"
|
|
|
|
|
if [ ! -f "$file" ]; then
|
|
|
|
|
err "File \"$file\" does not exist"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
for c in $(echo "$COLLECTION_LABELS" | sed "s|=[^;]*;| |g"); do
|
|
|
|
|
if [ "$collection" = "$c" ]; then
|
|
|
|
|
cexists="yes"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
if [ -n "${cexists:-}" ] && [ -d "$ROOT/$collection" ]; then
|
|
|
|
|
__import_to_collection "$file" "$collection"
|
|
|
|
|
else
|
|
|
|
|
err "Collection \"$collection\" does not exist"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# --import
|
|
|
|
|
# Import iCalendar file.
|
|
|
|
|
#
|
|
|
|
@ -843,6 +766,8 @@ fi
|
|
|
|
|
# @req $COLLECTION_LABELS: Mapping between collections and lables (see configuration)
|
|
|
|
|
# @req $AWK_PARSE: Parse awk script
|
|
|
|
|
# @req $AWK_GET: Awk script to extract fields from iCalendar file
|
|
|
|
|
# @req $ROOT: Path that contains the collections (see configuration)
|
|
|
|
|
# @req $UUIDGEN: `uuidgen` command
|
|
|
|
|
# @req $FZF: `fzf` command
|
|
|
|
|
# @req $CAT: Program to print
|
|
|
|
|
# @return: On success, returns 0, otherwise 1
|
|
|
|
@ -891,7 +816,16 @@ if [ "${1:-}" = "--import" ]; then
|
|
|
|
|
if [ -z "$collection" ]; then
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
__import_to_collection "$file" "$collection"
|
|
|
|
|
fpath=""
|
|
|
|
|
while [ -f "$fpath" ] || [ -z "$fpath" ]; do
|
|
|
|
|
uuid=$($UUIDGEN)
|
|
|
|
|
fpath="$ROOT/$collection/$uuid.ics"
|
|
|
|
|
done
|
|
|
|
|
cp -v "$file" "$fpath"
|
|
|
|
|
if [ -n "${GIT:-}" ]; then
|
|
|
|
|
$GIT add "$fpath"
|
|
|
|
|
$GIT commit -m "Imported event" -- "$fpath"
|
|
|
|
|
fi
|
|
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
"no")
|
|
|
|
@ -946,7 +880,7 @@ __refresh_data
|
|
|
|
|
|
|
|
|
|
### Exports
|
|
|
|
|
# The preview calls run in subprocesses. These require the following variables:
|
|
|
|
|
export ROOT CAT AWK_GET AWK_CALSHIFT AWK_CALANNOT CYAN WHITE ITALIC OFF
|
|
|
|
|
export ROOT CAT AWK_GET AWK_CAL CYAN WHITE ITALIC OFF
|
|
|
|
|
# The reload commands also run in subprocesses, and use in addition
|
|
|
|
|
export COLLECTION_LABELS DAY_START DAY_END AWK_DAYVIEW AWK_WEEKVIEW AWK_PARSE
|
|
|
|
|
# as well as the following variables that will be dynamically specified. So, we
|
|
|
|
@ -1061,19 +995,13 @@ while true; do
|
|
|
|
|
)+transform(
|
|
|
|
|
[ -n \"\${TZ:-}\" ] && echo \"change-list-label:\$WHITE\$ITALIC(\$TZ)\$OFF\"
|
|
|
|
|
)+transform(
|
|
|
|
|
[ -n \"\$(echo {} | cut -d '|' -f 5)\" ] && echo show-preview
|
|
|
|
|
echo {} | grep \|\| || echo show-preview
|
|
|
|
|
)" \
|
|
|
|
|
--bind="start:hide-preview" \
|
|
|
|
|
--bind="j:down+hide-preview+transform([ -n \"\$(echo {} | cut -d '|' -f 5)\" ] && echo show-preview)" \
|
|
|
|
|
--bind="k:up+hide-preview+transform([ -n \"\$(echo {} | cut -d '|' -f 5)\" ] && echo show-preview)" \
|
|
|
|
|
--bind="ctrl-j:down+hide-preview+transform([ -n \"\$(echo {} | cut -d '|' -f 5)\" ] && echo show-preview)" \
|
|
|
|
|
--bind="ctrl-k:up+hide-preview+transform([ -n \"\$(echo {} | cut -d '|' -f 5)\" ] && echo show-preview)" \
|
|
|
|
|
--bind="down:down+hide-preview+transform([ -n \"\$(echo {} | cut -d '|' -f 5)\" ] && echo show-preview)" \
|
|
|
|
|
--bind="up:up+hide-preview+transform([ -n \"\$(echo {} | cut -d '|' -f 5)\" ] && echo show-preview)" \
|
|
|
|
|
--bind="j:down+hide-preview+transform:echo {} | grep \|\| || echo show-preview" \
|
|
|
|
|
--bind="k:up+hide-preview+transform:echo {} | grep \|\| || echo show-preview" \
|
|
|
|
|
--bind="l:hide-preview+reload:$0 --reload-day {1} '+1 day'" \
|
|
|
|
|
--bind="h:hide-preview+reload:$0 --reload-day {1} '-1 day'" \
|
|
|
|
|
--bind="right:hide-preview+reload:$0 --reload-day {1} '+1 day'" \
|
|
|
|
|
--bind="left:hide-preview+reload:$0 --reload-day {1} '-1 day'" \
|
|
|
|
|
--bind="ctrl-l:hide-preview+reload:$0 --reload-day {1} '+1 week'" \
|
|
|
|
|
--bind="ctrl-h:hide-preview+reload:$0 --reload-day {1} '-1 week'" \
|
|
|
|
|
--bind="alt-l:hide-preview+reload:$0 --reload-day {1} '+1 month'" \
|
|
|
|
@ -1146,8 +1074,6 @@ while true; do
|
|
|
|
|
--bind="k:up" \
|
|
|
|
|
--bind="l:unbind(load)+reload:$0 --reload-week {2} '+1 week'" \
|
|
|
|
|
--bind="h:unbind(load)+reload:$0 --reload-week {2} '-1 week'" \
|
|
|
|
|
--bind="right:unbind(load)+reload:$0 --reload-week {2} '+1 week'" \
|
|
|
|
|
--bind="left:unbind(load)+reload:$0 --reload-week {2} '-1 week'" \
|
|
|
|
|
--bind="ctrl-l:unbind(load)+reload:$0 --reload-week {2} '+1 month'" \
|
|
|
|
|
--bind="ctrl-h:unbind(load)+reload:$0 --reload-week {2} '-1 month'" \
|
|
|
|
|
--bind="alt-l:unbind(load)+reload:$0 --reload-week {2} '+1 year'" \
|
|
|
|
|