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
|
module memo {
def visibility [] {
[
{value: "PRIVATE", description: "Private"},
{value: "PROTECTED", description: "Only logged-in users"},
{value: "PUBLIC", description: "Public"}
]
}
export def main [
content?: string # Memo content
--pin(-p) # Pin the memo
--visibility(-v): string@visibility # Visibility of the memo
] {
let configFile = '~/.config/memos/config.json' | path expand
let configExists = $configFile | path exists
if (not $configExists) {
print $"Could not find a config file at ($configFile)"
return
}
let config = (open $configFile)
mut content = $content
if ($content == null) {
let temp = (mktemp --tmpdir --suffix .md)
^$env.EDITOR $temp
$content = (open $temp)
rm $temp
}
if ($content | str trim | is-empty) {
print "Content is required"
return
}
let url = $config.url | str trim --right --char '/'
let resp = http post --headers {Authorization: $"Bearer ($config.token)"} --content-type application/json $"($url)/api/v1/memos" {
state: "NORMAL",
content: $content,
visibility: $visibility,
pinned: $pin
}
$"($url)/($resp.name)"
}
}
use memo *
|