#!/usr/bin/env bash calcurse_filter_between() { local start="$1" local end="$2" timeout 5 calcursed -G --filter-type=apt --filter-start-from="$start" --filter-end-to="$end" } dateoffset() { local dt="$1" local dt_offset="$2" local -a args=("+$dt") if [[ -n "$dt_offset" ]]; then args+=(-d "$dt_offset") fi date "${args[@]}" } case "$BLOCK_BUTTON" in 1) # send a notification with todays appointments notify "$(calcurse-upcoming -d 2)" ;; 3) # open calcurse in my terminal # https://purarue.xyz/d/cross-platform/launch?dark launch calcursed ;; esac calcurse_status() { # Find things on my calendar that are starting after now, today # and meetings that are on my calendar, at any time today today_coming_up="$(calcurse_filter_between "$(dateoffset '%m/%d/%Y %H:%M')" "$(dateoffset '%m/%d/%Y')" | wc -l)" tomorrow="$(calcurse_filter_between "$(dateoffset '%m/%d/%Y' '+1 day')" "$(dateoffset '%m/%d/%Y' '+1 day')" | wc -l)" if ((today_coming_up == 0 && tomorrow == 0)); then echo 0 # if today is zero, just 0/tomorrow elif ((today_coming_up == 0)); then printf '0/%s\n' "$tomorrow" else # today_coming_up > 0 in this case if ((tomorrow > 0)); then # print items upcoming / total items today printf '%s/%s\n' "$today_coming_up" "$tomorrow" else printf '%s\n' "$today_coming_up" fi fi } if [[ -z "$CALCURSE_DIR" ]]; then # shellcheck disable=SC2016 notify 'No $CALCURSE_DIR set' exit 1 fi caltext() { SYNC_CONFLICTS="$(sync-conflicts "$CALCURSE_DIR" 2>/dev/null | wc -l)" if [[ "$SYNC_CONFLICTS" -gt 0 ]]; then printf "%s \n" "$(calcurse_status)" else calcurse_status fi } if [[ -n "${STATUS_JSON:-}" ]]; then jq -rcn --arg text "$(caltext)" --arg hover "$(calcurse-upcoming -d 2)" '{"text": $text, "tooltip": $hover}' else caltext fi