forked from pimterry/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_notes
59 lines (55 loc) · 1.64 KB
/
_notes
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
#compdef notes
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Simple delightful note taking, with more unix and less lock-in. (https://github.com/pimterry/notes)
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * pimterry et al.
#
# ------------------------------------------------------------------------------
__notes_cmd ()
{
local -a list
list=(
new:'Create new file'
ls:'<pattern> List notes by path'
find:'[pattern] Search notes by filename and path'
grep:'<pattern> Search notes by content'
search:'[pattern] Search notes by filename or content'
open:'<name> Open a notes for editing by full name'
rm:'[-r | --recursive] <name> Remove note, or folder if -r or --recursive is given]'
cat:'<name> Display a note by name'
--version:'Show version'
--help:'Show usage'
)
_describe -t sub-commands 'sub commands' list && _ret=0
}
_notes ()
{
# Look for configuration file at ~/.config/notes/config and use it
if [ -f ~/.config/notes/config ]; then
. ~/.config/notes/config
fi
local configured_dir=${NOTES_DIRECTORY%/}
local note_dir="${configured_dir:-$HOME/notes}"
if (($CURRENT == 2)); then
_alternative 'sub-commands:files:__notes_cmd' && _ret=0
elif (($CURRENT == 3)); then
case $words[2] in
open|o|rm|cat)
_path_files -W "${note_dir}" && _ret=0;;
new|n|ls)
_path_files -W "${note_dir}" -/ && _ret=0;;
esac
elif (($CURRENT >= 3)); then
case $words[2] in
rm)
_path_files -W "${note_dir}" && _ret=0;;
esac
fi
}