-
Notifications
You must be signed in to change notification settings - Fork 1
/
addopenhouse.sh
executable file
·62 lines (52 loc) · 1.43 KB
/
addopenhouse.sh
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
#!/bin/bash
#
# Add open house to calendar
#
# Usage:
# addopenhouse.sh [ --no-dupe-check ] <title> <date> <description> <duration - minutes> <location>
#
CALENDAR="Personal"
if [ "$1" = "--no-dupe-check" ]
then
no_dupe_check="true"
shift
else
no_dupe_check=""
fi
TITLE="$1"
DATE="$2"
DESCRIPTION="$3"
DURATION="$4"
LOCATION="$5"
if [ ! "$LOCATION" ]
then
echo "Usage: addopenhouse.sh <title> <date> <description> <duration> <location>"
exit 2
fi
REMINDER=1440 # day
output="$(gcalcli --cache --calendar "$CALENDAR" search "\"$TITLE\"" --details url | grep .)"
if [ ! "$no_dupe_check" -a ! "$(echo "$output" | grep 'No Events Found...')" ]
then
echo "Probable duplicate:"
echo "$output"
exit 2
fi
NOAPTTITLE="$(echo "$TITLE" | sed 's/ APT.*//')"
NOAPTTITLE="$(echo "$NOAPTTITLE" | sed 's/ apt.*//')"
NOAPTTITLE="$(echo "$NOAPTTITLE" | sed 's/ Apt.*//')"
output="$(gcalcli --cache --calendar "$CALENDAR" search "\"$NOAPTTITLE\"" --details url | grep .)"
if [ ! "$no_dupe_check" -a ! "$(echo "$output" | grep 'No Events Found...')" ]
then
echo "Probable duplicate:"
echo "$output"
exit 2
fi
set -x
output="$(gcalcli add --calendar "$CALENDAR" --title "$TITLE" --when "$DATE" --duration "$DURATION" --description "$DESCRIPTION" --where "$LOCATION" --reminder "$REMINDER" --details url)"
url="$(echo "$output" | tr \ \\t \\n | grep http | head -1)"
if [ ! "$url" ]
then
echo "Can't find url. output: $output"
exit 5
fi
open $url