Skip to content

Commit 04ee8af

Browse files
authored
Merge pull request #33 from RODNOTGOD/master
Add new zsh completion and update README.md
2 parents fa925b0 + 1402af2 commit 04ee8af

File tree

3 files changed

+68
-6
lines changed

3 files changed

+68
-6
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,34 @@ curl https://cdn.rawgit.com/pimterry/notes/v0.2.0/notes > /usr/local/bin/notes &
2929

3030
By default your notes live in ~/notes, but you can change that to anywhere you like by setting the `$NOTES_DIRECTORY` environmental variable. See [how do I configure this?](#how-do-i-configure-this) for more details.
3131

32-
#### Installing Bash completion
32+
#### Installing auto completion
3333

34-
`notes` includes bash autocompletion, to let you tab-complete commands and your note names. This requires Bash > 4.0 and [bash-completion](https://github.com/scop/bash-completion) to be installed - it's probably available from your friendly local package manager.
34+
`notes` includes auto completion, to let you tab-complete commands and your note names. This requires Bash > 4.0 and [bash-completion](https://github.com/scop/bash-completion) or Zsh to be installed - it's probably available from your friendly local package manager.
3535

36-
To enable completion for notes, copy the completion script into your bash completion directory, and it should be automatically loaded. The bash completion directory is `/usr/share/bash-completion/completions/` on a typical Debian install, or `/usr/local/etc/bash_completion.d/` on OSX with `bash-completion` from homebrew. You may be able to find your own bash completion directory by running the following command:
36+
To enable completion for notes, copy the completion script into your bash or zsh completion directory, and it should be automatically loaded. The bash completion directory is `/usr/share/bash-completion/completions/` on a typical Debian install, or `/usr/local/etc/bash_completion.d/` on OSX with `bash-completion` from homebrew. The zsh completion directory is `/usr/share/zsh/functions/Completion/` in Linux. You may be able to find your own bash completion directory by running the following command:
3737

3838
pkg-config --variable=completionsdir bash-completion
3939

4040
Installing the completions might be as follows:
4141

42+
Bash
4243
```bash
4344
curl https://cdn.rawgit.com/pimterry/notes/v0.2.0/notes.bash_completion > /usr/share/bash-completion/completions/notes
4445
```
4546

47+
Zsh
48+
On *buntu based distros
49+
```bash
50+
curl https://cdn.rawgit.com/pimterry/notes/v0.2.0/notes._notes > /usr/local/share/site-functions/_notes
51+
```
52+
On other Unix distros the command should as follows
53+
```bash
54+
curl https://cdn.rawgit.com/pimterry/notes/v0.2.0/notes._notes > /usr/share/zsh/site-functions/_notes
55+
```
56+
4657
You'll need to open a new shell for this to take effect.
4758

48-
## How do I configure this?
59+
# How do I configure this?
4960

5061
To get started with you'll want to set `$EDITOR` to your favourite text editor, and probably `$NOTES_DIRECTORY` to the directory in which you'd like to use to store your notes (this defaults to `~/notes`). You'll typically want to set these as environment variables in your `.bashrc`, `.zshrc`, or similar.
5162

@@ -103,7 +114,6 @@ All the above works. Here's what's coming next:
103114

104115
- [ ] More interesting and nicer looking file/grep search result formatting, perhaps only when not piping? (https://github.com/pimterry/notes/issues/27)
105116
- [ ] Make the file extension optional (https://github.com/pimterry/notes/issues/24)
106-
- [ ] zsh command and note name autocompletion (https://github.com/pimterry/notes/issues/25)
107117
- [ ] Interactive mode? `notes` could open a scrollable list of notes, open your editor when you pick one, and reappear after you close it. (https://github.com/pimterry/notes/issues/17)
108118
- [ ] Tree view (https://github.com/pimterry/notes/issues/26)
109119
- [ ] Easy way to see short notes snippets in find/grep/tree? Could be option (`--snippets`) or by piping to a command (`notes find | notes snippets`). Maybe call it `head`? (https://github.com/pimterry/notes/issues/22)

_notes

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#compdef notes
2+
# ------------------------------------------------------------------------------
3+
# Description
4+
# -----------
5+
#
6+
# Simple delightful note taking, with more unix and less lock-in. (https://github.com/pimterry/notes)
7+
#
8+
# ------------------------------------------------------------------------------
9+
# Authors
10+
# -------
11+
#
12+
# * pimterry et al.
13+
#
14+
# ------------------------------------------------------------------------------
15+
16+
__notes_cmd ()
17+
{
18+
local -a list
19+
list=(
20+
new:'Create new file'
21+
ls:'<pattern> List notes by path'
22+
find:'[pattern] Search notes by filename and path'
23+
grep:'<pattern> Search notes by content'
24+
search:'[pattern] Search notes by filename or content'
25+
open:'<name> Open a notes for editing by full name'
26+
rm:'[-r | --recursive] <name> Remove note, or folder if -r or --recursive is given]'
27+
--help:'Show usage'
28+
)
29+
_describe -t sub-commands 'sub commands' list && _ret=0
30+
}
31+
32+
_notes ()
33+
{
34+
local configured_dir=${NOTES_DIRECTORY%/}
35+
local note_dir="${configured_dir:-$HOME/notes}"
36+
37+
if (($CURRENT == 2)); then
38+
_alternative 'sub-commands:files:__notes_cmd' && _ret=0
39+
elif (($CURRENT == 3)); then
40+
case $words[2] in
41+
open|o|rm)
42+
_path_files -W "${note_dir}" && _ret=0;;
43+
new|n|ls)
44+
_path_files -W "${note_dir}" -/ && _ret=0;;
45+
esac
46+
elif (($CURRENT >= 3)); then
47+
case $words[2] in
48+
rm)
49+
_path_files -W "${note_dir}" && _ret=0;;
50+
esac
51+
fi
52+
}

test/test-open.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ notes="./notes"
124124

125125
assert_failure
126126
assert_output "Please set \$EDITOR to edit notes"
127-
}
127+
}

0 commit comments

Comments
 (0)