-
Notifications
You must be signed in to change notification settings - Fork 2
/
geek.nu
115 lines (106 loc) · 2.5 KB
/
geek.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
112
113
114
115
#geeknote wrapper for accesing evernote
export def "geek help" [] {
print ([
"geeknote wrapper: git clone git://github.com/jeffkowalski/geeknote.git"
"METHODS:"
"- geek find"
"- geek show"
"- geek edit"
"- geek create"
"- geek export"
]
| str join "\n"
| nu-highlight
)
}
#geeknote find
export def "geek find" [
search:string #search term in title
...rest:string #extra flags for geeknote
#
#Example
#geek find ssh
#geek find ssh "--tag linux"
] {
let result = if ($rest | is-empty) {
do -i {geeknote find --search $search}
| complete
| get stdout
} else {
let command = "geeknote find --search " + $search + " " + ($rest | str join ' ')
do -i {nu -c $command}
| complete
| get stdout
}
$result
| lines
| drop nth 1
| str replace ': 2' '¬ 2'
| each {|it|
$it | split row '¬' | last
}
}
#geeknote show
export def "geek show" [
item:int #search term in title
...rest:string #extra flags for geeknote show (--raw)
#
#Example (after a geek find)
#geek show 1
#geek show 1 "--raw"
] {
let result = if ($rest | is-empty) {
do -i {geeknote show $item}
| complete
| get stdout
} else {
let command = "geeknote show " + ($item | into string) + " " + ($rest | str join ' ')
do -i {nu -c $command}
| complete
| get stdout
}
$result
| nu-highlight
| lines
}
#geeknote edit
export def "geek edit" [
item:int #search term in title
...rest:string #extra flags for geeknote show (--raw)
#
#Example (after a geek find)
#geek edit 1
#geek edit 1 "--tag new_tag"
] {
if ($rest | is-empty) {
geeknote edit $item
} else {
let command = "geeknote edit " + ($item | into string) + " " + ($rest | str join ' ')
nu -c $command
}
}
#geeknote create
export def "geek create" [
commands:string #list of commands to create a note
#
#Example
#geek create "--title 'a note'"
#geek create "--title 'a note' --tag linux --content 'the content'"
] {
nu -c ("geeknote create " + $commands)
}
#export evernote notes to enex files
export def "geek export" [
folder = "evernote" # export folder name
#
#Needs evernote-backup pip package.
#It is automatically installed if not.
] {
pip show evernote-backup
if $env.LAST_EXIT_CODE != 0 {pip install --user evernote-backup}
mkdir $folder
cd $folder
evernote-backup init-db --oauth
evernote-backup sync
evernote-backup export $folder
}