blob: c80426dc53bea7ae0f0798670a341c494f31fdcf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#!/bin/sh
## Mail2Khal
#
# Converts an email passed as stdin into a khal calendar event.
# To use in conjunction with neomutt add this to the config:
#
# macro attach c '<pipe-message>mail2khal<enter>'
#
which khal >/dev/null 2>&1 || \
( echo "Install 'khal' to use this script." && exit 1 )
TMP="$(mktemp --tmpdir=$TMPDIR mail2khal.XXXXXXXX.md)"
echo "
> Fill all sections of this markdown file (time and title are
> mandatory). Quote blocks (like this one) are ignored. Empty
> lines are ignored unless in the description section.
# Calendar
university
# Title
# Time
> Valid examples are:
> [dd/mm[/yyyy]] [hh:mm] [[dd/mm[/yyyy]] [hh:mm]]
> {today,tomorrow,monday,...,sunday} can be used as date
# Location
# Tags
# Description
# Ignored
> Anything after this point is ignored.
" > "$TMP"
cat - >> "$TMP"
# Make the necessary changes in Nvim
nvim "$TMP"
awk '
/^>/ { next }
/^# Calendar$/ {
state = 1
cal = ""
next
}
/^# Title$/ {
state = state + 1
title = ""
next
}
/^# Time$/ {
state = state + 1
time = ""
next
}
/^# Location$/ {
state = state + 1
loc = ""
next
}
/^# Tags$/ {
state = state + 1
tags = ""
next
}
/^# Description$/ {
state = state + 1
desc = ""
next
}
/^# Ignored$/ {
cmd = "khal new"
if (length(cal) > 0) {
cmd = cmd " -a " cal
}
if (length(loc) > 0) {
cmd = cmd " -l \"" loc "\""
}
if (length(tags) > 0) {
cmd = cmd " -g \"" tags "\""
}
cmd = cmd " \"" time "\""
cmd = cmd " \"" title
if (length(desc) > 0) {
cmd = cmd " :: " desc
}
cmd = cmd "\""
system(cmd)
exit
}
state == 1 && NF {
cal = cal $0
}
state == 2 && NF {
title = title $0
}
state == 3 && NF {
time = time $0
}
state == 4 && NF {
loc = loc $0
}
state == 5 && NF {
tags = tags $0
}
state == 6 {
desc = desc "\n" $0
}
' "$TMP"
|