-
Notifications
You must be signed in to change notification settings - Fork 2
/
gcal.nu
111 lines (100 loc) · 3.14 KB
/
gcal.nu
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
#gcalcli wrapper for accesing google calendar
export def "gcal help" [] {
print ([
"gcalcli wrapper:"
"METHODS"
"- gcal add"
"- gcal agenda"
"- gcal semana"
"- gcal mes"
"- gcal list"
] | str join "\n"
| nu-highlight
)
}
#add event to google calendar, also usable without arguments
export def "gcal add" [
calendar? #to which calendar add event
title? #event title
when? #date: yyyy.MM.dd hh:mm
where? #location
duration? #duration in minutes
] {
let calendar = if ($calendar | is-empty) {
gcal list -r | sort | input list -f (echo-g "Select calendar: ")
} else {
$calendar
}
let title = if ($title | is-empty) {input (echo-g "title: ")} else {$title}
let when = if ($when | is-empty) {input (echo-g "when: ")} else {$when}
let where = if ($where | is-empty) {input (echo-g "where: ")} else {$where}
let duration = if ($duration | is-empty) {input (echo-g "duration: ")} else {$duration}
gcalcli --calendar $"($calendar)" add --title $"($title)" --when $"($when)" --where $"($where)" --duration $"($duration)" --default-reminders
}
#show gcal agenda in selected calendars
#
# Examples
# agenda
# agenda --full
# agenda "--details=all"
# agenda --full "--details=all"
export def "gcal agenda" [
--full(-f) #show all calendars
...rest #extra flags for gcalcli between quotes (specified full needed)
] {
let calendars = gcal list -R (not $full) -f $full| str join "|"
gcalcli --calendar $"($calendars)" agenda --military ...$rest
}
#show gcal week in selected calendards
#
# Examples
# semana
# semana --full
# semana "--details=all"
# semana --full "--details=all"
export def "gcal semana" [
--full(-f) #show all calendars (export default: 0)
...rest #extra flags for gcalcli between quotes (specified full needed)
] {
let calendars = gcal list -R (not $full) -f $full | str join "|"
gcalcli --calendar $"($calendars)" calw ...$rest --military --monday
}
#show gcal month in selected calendards
#
# Examples
# mes
# mes --full
# mes "--details=all"
# mes --full "--details=all"
export def "gcal mes" [
--full(-f) #show all calendars (export default: 0)
...rest #extra flags for gcalcli between quotes (specified full needed)
] {
let calendars = gcal list -R (not $full) -f $full | str join "|"
gcalcli --calendar $"($calendars)" calm ...$rest --military --monday
}
#list available calendars
export def "gcal list" [
--readers(-r) #exclude read-only calendars
--readers_bool(-R) = false #same as -r, but bool flag
--full(-f) = true #if false, filter not wanted calendars
] {
gcalcli list
| ansi strip
| lines
| skip 2
| if $readers or $readers_bool {find -v reader} else {find ""}
| if $full {find ""} else {find -v Cuentas}
| drop
| str replace -a "owner" ""
| str replace "writer" ""
| str replace "reader" ""
| str replace " " ""
| str replace " " ""
| str trim
}
#re-authenticate gcalcli
export def "gcal reauth" [] {
rm ~/.gcalcli*
gcalcli --client-id $env.MY_ENV_VARS.api_keys.google.calendar.client_id --client-secret $env.MY_ENV_VARS.api_keys.google.calendar.client_secret --noauth_local_webserver list
}