Newer
Older
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
118
119
120
121
122
A simple bash function to add an appointment to a default calendar using khal.
```bash
function newcal(){
function usage(){
echo "USAGE: newcal --date [dd.mm|dd] --time [00:15|00] --title \"HEADLINE TITLE\" --notes \"Your Notes\""
return 1
}
if [[ -z $1 ]]; then
usage
return 1
fi
## khal printcalendars
local PCAL="personal" # Personal calendar
local ALARMS="20minutes,10minutes,5minutes" # Reminders
local TITLE_PREFIX="WhatEver Prefix // "
local DEFAULT_DUR="60" # Default appointment duration
local KHAL=$(which khal)
local VDIR=$(which vdirsyncer)
if [[ -z ${KHAL} || ! -e ${KHAL} ]] || [[ -z ${VDIR} || ! -e ${VDIR} ]]; then
echo "Please install and configure KHAL or VDIRSYNCER first!"
usage
fi
while [[ $# -ge 1 ]]
do
INPUT="$1"
case $INPUT in
--date)
DATE="$2"
shift
shift;;
--time)
TIME="$2"
shift
shift;;
--title)
TITLE="$2"
shift
shift;;
--notes)
NOTES="$2"
shift
shift;;
*)
echo "Wrong input: $INPUT"
return 1
;;
esac
done
## if date is only two digits, we assume the given day of the current month
if [[ ! -z ${DATE} ]] && [[ ${DATE} =~ ^[0-9]{1,2}$ ]]; then
local DATE="${DATE}.$(date +%m)"
elif [[ -z ${DATE} ]]; then
usage
return 1
fi
## if time is only two digits, we assume full hour
if [[ ! -z ${TIME} ]] && [[ ${TIME} =~ ^[0-9]{1,2}$ ]]; then
local TIME="${TIME}:00"
elif [[ -z ${TIME} ]]; then
usage
return 1
fi
## No title, no appointment
if [[ -z ${TITLE} ]]; then
usage
return 1
else
local TITLE="${TITLE_PREFIX}${TITLE}"
fi
## If alarms are empty, dont add an alarm
if [[ ! -z ${ALARMS} ]]; then
ALARM_SWITCH="--alarms ${ALARMS}"
else
ALARM_SWITCH=""
fi
if [[ ! -z ${NOTES} ]]; then
local TITLE="${TITLE} :: ${NOTES}"
fi
local END_TIME=$(date -d "${TIME} ${DEFAULT_DUR}min" +%R)
if [[ -z ${PCAL} || -z ${DATE} || -z ${TIME} || -z ${END_TIME} || -z ${TITLE} ]]; then
usage
return 1
else
## Add to personal calender
khal new --calendar ${PCAL} ${DATE}. ${TIME} ${END_TIME} ${ALARM_SWITCH} "${TITLE}" 1> /dev/null
local ERR=$?
if [[ ${ERR} != "0" ]]; then
echo "There was an error. KHAL exited with code ${ERR}"
return ${ERR}
else
echo -e $'\u2714'" Appointment added
- Title: ${TITLE}
- Date: ${DATE} From: ${TIME} to: ${END_TIME}
- Calendar: ${PCAL}
"
fi
sleep 1
vdirsyncer sync 1> /dev/null
local ERR=$?
if [[ ${ERR} != "0" ]]; then
echo "There was an error. vdirsyncer exited with code ${ERR}"
return ${ERR}
else
echo $'\u2714'" Updated Calendars... "
fi
return 0
fi
}
```