This repository has been archived by the owner on Jan 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
neuron.kak
57 lines (41 loc) · 1.48 KB
/
neuron.kak
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
define-command -docstring '
Creates a new neuron note and opens it.
All the arguments are appended after the `neuron new` command.
' -params .. neuron-new %{ evaluate-commands %sh{
printf "%s\n" "edit \"$(neuron new "$@" 2>/dev/null)\""
} }
define-command -docstring '
Performs an interactive neuron search in a new terminal window.
Whatever file is selected will be opened.
All the arguments are appended after the `neuron search` command.
' -params .. neuron-search-and-open %{ evaluate-commands %sh{
script="$(mktemp)"
cat << EOF > $script
#!/usr/bin/env bash
found_file="\$(neuron search $@)"
if [ -n "\$found_file" ]; then
printf "%s\n" "evaluate-commands -client \"$kak_client\" edit \"\$found_file\"" | kak -p $kak_session
fi
rm "$script"
EOF
chmod +x "$script"
printf "%s\n" "terminal \"$script\""
} }
define-command -docstring '
Performs an interactive neuron search in a new terminal window.
Whatever file is selected, its zettel ID will be inserted into the current cursor position.
All the arguments are appended after the `neuron search` command.
' -params .. neuron-search-and-insert %{ evaluate-commands %sh{
script="$(mktemp)"
cat << EOF > $script
#!/usr/bin/env bash
found_file="\$(neuron search $@)"
if [ -n "\$found_file" ]; then
stripped_name="\$(basename -s ".md" "\$found_file")"
printf "%s\n" "execute-keys -client \"$kak_client\" \"i\$stripped_name<esc>\"" | kak -p $kak_session
fi
rm "$script"
EOF
chmod +x "$script"
printf "%s\n" "terminal \"$script\""
} }