add calendar alarms
This commit is contained in:
parent
abdc275d86
commit
749516aea6
65
hosts/profiles/desktop/cal-alarms.nix
Normal file
65
hosts/profiles/desktop/cal-alarms.nix
Normal file
|
@ -0,0 +1,65 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
systemd.services.cal-alarms = {
|
||||
serviceConfig.Type = "simple";
|
||||
path = [
|
||||
pkgs.libnotify
|
||||
pkgs.dunstify
|
||||
pkgs.khal
|
||||
];
|
||||
startAt = "*08:00:00";
|
||||
script = ''
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/khal-events"
|
||||
# events starting in the next TIMESPAN will trigger an alarm
|
||||
timespan='60min'
|
||||
|
||||
# this is needed for cronjobs and Xorg
|
||||
export DISPLAY=":0"
|
||||
snooze_string='💤 Snooze all.'
|
||||
dismiss_string='✅ Dismiss all.'
|
||||
# only show events with ⏰ symbol (=has alarm set)
|
||||
# remove arrows for all-day events to only have one notification
|
||||
# remove ⏰ symbol because it is obvious
|
||||
events="$(khal list --format \
|
||||
'{cancelled}{start-style}{to-style}{end-style} {title}{description-separator}{description}{location}{repeat-symbol}{alarm-symbol}' \
|
||||
now "${timespan}" \
|
||||
| sed -ne '/⏰/ p' \
|
||||
| sed -e 's/⏰//g' -e 's/\(↦\|↔\|⇥\)[^[:blank:]]*/all-day/g' \
|
||||
| column -tl 3)"
|
||||
|
||||
# get events that are new compared to cache file
|
||||
new_events="$(diff -NwU 0 "${cache_file}" - << EOF | sed -ne '/^\+[^+]/ p' \
|
||||
| sed -ne 's/^\+\([[:print:]].*\)$/\1/p'
|
||||
${events}
|
||||
EOF
|
||||
)"
|
||||
|
||||
[ -z "${new_events}" ] && exit 0
|
||||
|
||||
action="$(dunstify --action="default,Dismiss" --action="snooze,Snooze" "${new_events}")"
|
||||
|
||||
case "${action}" in
|
||||
"snooze")
|
||||
;;
|
||||
"default")
|
||||
printf '%s' "${events}" > "${cache_file}"
|
||||
;;
|
||||
*)
|
||||
printf '%s' "${events}" | grep -Fve "${input}" > "${cache_file}"
|
||||
;;
|
||||
esac
|
||||
'';
|
||||
serviceConfig = {
|
||||
User = "anish";
|
||||
Environment = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus";
|
||||
};
|
||||
};
|
||||
systemd.timers.cal-alarms = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
partOf = [ "cal-alarms.service" ];
|
||||
timerConfig.OnCalendar = [ "*:0/10" ];
|
||||
};
|
||||
}
|
|
@ -16,7 +16,10 @@ let
|
|||
in
|
||||
{
|
||||
# TODO modularize
|
||||
imports = [ ./battery-low-timer.nix ];
|
||||
imports = [
|
||||
./battery-low-timer.nix
|
||||
./cal-alarms.nix
|
||||
];
|
||||
|
||||
# Secrets used by home-manager modules
|
||||
age.secrets.fastmail.file = "${self}/secrets/fastmail.age";
|
||||
|
|
Loading…
Reference in a new issue