aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/sdep-add24
-rwxr-xr-xscripts/sdep-checknow37
-rwxr-xr-xscripts/sdep-clear11
-rwxr-xr-xscripts/sdep-edit11
-rwxr-xr-xscripts/sdep-list65
5 files changed, 148 insertions, 0 deletions
diff --git a/scripts/sdep-add b/scripts/sdep-add
new file mode 100755
index 0000000..bb0b2c8
--- /dev/null
+++ b/scripts/sdep-add
@@ -0,0 +1,24 @@
1#!/bin/sh
2
3# Adds a line to SDEPDATA/once. It is possible to specify a date, which will be
4# read by date -d and prepended to the input text.
5# -d is a non-portable option of GNU date. On some other systems one can
6# accomplish the same with the -j option.
7
8# Usage: sdep-add [date]
9# Example: sdep-add "next monday"
10
11file="SDEPDATA/once"
12date=""
13
14[ -n "$1" ] && date=$(date -d "$1" +%Y-%m-%d)
15
16[ -n "$date" ] && printf "$date "
17
18read text
19
20if [ -n "$text" ]; then
21 printf "${date}\t${text}\n" >> "$file"
22else
23 echo "Event not saved"
24fi
diff --git a/scripts/sdep-checknow b/scripts/sdep-checknow
new file mode 100755
index 0000000..0319b5f
--- /dev/null
+++ b/scripts/sdep-checknow
@@ -0,0 +1,37 @@
1#!/bin/sh
2
3# Run this every minute (for example using cron) to receive a notification
4# when an event happens.
5#
6# The events are read from the following files in SDEPDATA folder:
7# once: events that only happen once; full date needs to be specified
8# daily: events that happen every day; only specify the time in HH:MM format
9# weekly: only specify Weekday + time
10# monthly: only specify day of the month + time
11
12# Requires: notify-send; the weekly part uses the non-portable -d option of
13# GNU date, which you might have to change if you are not on Linux (on some
14# systems you can accomplish the same with -j).
15
16notify="notify-send -t 3600000"
17title="$(date +%H:%M)"
18
19sdepnotify() {
20 sdep -w "" -s "" | while read text; do $notify "$title" "$text"; done
21}
22
23# One-off events
24sdepnotify <"SDEPDATA/once"
25
26# Daily events
27sed "s/^/$(date +%Y-%m-%d) /" <"SDEPDATA/daily" | sdepnotify
28
29# Weekly events - needs GNU date (try -j intead of -d on BSD)
30while read line; do
31 weekday=$(echo "$line" | sed "s/ .*$//")
32 echo "$line" | sed "s/^[ ]*[^ ]* /$(date -d $weekday +%Y-%m-%d) /"
33done <"SDEPDATA/weekly" | \
34sdepnotify
35
36# Monthly events
37sed "s/^[ ]*/$(date +%Y-%m-)/" <"SDEPDATA/daily" | sdepnotify
diff --git a/scripts/sdep-clear b/scripts/sdep-clear
new file mode 100755
index 0000000..814f853
--- /dev/null
+++ b/scripts/sdep-clear
@@ -0,0 +1,11 @@
1#!/bin/sh
2
3# Removes old events from specified file (default: SDEPDATA/once).
4
5# Usage: sdep-clear [file]
6
7file="SDEPDATA/${1:-once}"
8temp=$(mktemp)
9
10sdep -t <"$file" >"$temp"
11mv "$temp" "$file"
diff --git a/scripts/sdep-edit b/scripts/sdep-edit
new file mode 100755
index 0000000..5e8c491
--- /dev/null
+++ b/scripts/sdep-edit
@@ -0,0 +1,11 @@
1#!/bin/sh
2
3# Open specified file in sdep folder in editor.
4
5# Usage: sdep-edit [file]
6# No options = once
7
8file="SDEPFOLDER/${1:-once}"
9editor=${VISUAL:-vi}
10
11$editor "$file"
diff --git a/scripts/sdep-list b/scripts/sdep-list
new file mode 100755
index 0000000..a9e5405
--- /dev/null
+++ b/scripts/sdep-list
@@ -0,0 +1,65 @@
1#!/bin/sh
2
3# Lists events happening in a specific time range.
4# Recurring events are listed at most once, and only if their first occurrence
5# is in the range.
6#
7# The events are read from the following files in the SDEPDATA folder:
8# once: events that only happen once; full date needs to be specified
9# daily: events that happen every day; only specify the time in HH:MM format
10# weekly: only specify Weekday + time
11# monthly: only specify day of the month + time
12
13# This script uses relies on the non-portable -d option of GNU date.
14
15# Usage: sdep-list [today|tomorrow|week|nextweek|past|future]
16# No options = all
17
18from=""
19to=""
20w="%d %b %H:%M"
21
22case $1 in
23 today)
24 from="$(date +%Y-%m-%d) 0:00"
25 to="$(date +%Y-%m-%d) 23:59"
26 w="%H:%M"
27 ;;
28 tomorrow)
29 from="$(date -d tomorrow +%Y-%m-%d) 0:00"
30 to="$(date -d tomorrow +%Y-%m-%d) 23:59"
31 w="%H:%M"
32 ;;
33 week)
34 from="$(date -d 'last monday' +%Y-%m-%d) 0:00"
35 to="$(date -d sunday +%Y-%m-%d) 23:59"
36 w="%a %H:%M"
37 ;;
38 nextweek)
39 from="$(date -d 'next monday' +%Y-%m-%d) 0:00"
40 to="$(date -d 'next monday + 6 days' +%Y-%m-%d) 23:59"
41 w="%a %H:%M"
42 ;;
43 past)
44 to="$(date +'%Y-%m-%d %H:%M')"
45 ;;
46 future)
47 from="$(date +'%Y-%m-%d %H:%M')"
48 ;;
49 *)
50 ;;
51esac
52
53tempfile=$(mktemp)
54
55cat "SDEPDATA/once" > "$tempfile"
56sed "s/^/$(date +%Y-%m-%d) /" <"SDEPDATA/daily" | >> "$tempfile"
57while read line; do
58 weekday=$(echo "$line" | sed "s/ .*$//")
59 echo "$line" | sed "s/^[ ]*[^ ]* /$(date -d $weekday +%Y-%m-%d) /"
60done <"SDEPDATA/weekly" >> "$tempfile"
61sed "s/^[ ]*/$(date +%Y-%m-)/" <"SDEPDATA/daily" >> "$tempfile"
62
63sdep -w "$w" -f "$from" -t "$to" <"$tempfile"
64
65rm "$tempfile"

Generated with cgit - Back to sebastiano.tronto.net