Skip to content

Commit bbe9464

Browse files
committed
Add new zsh completion and update README.md
1 parent d7ff4f3 commit bbe9464

File tree

2 files changed

+89
-4
lines changed

2 files changed

+89
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,26 @@ 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.
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+
```bash
49+
curl https://cdn.rawgit.com/pimterry/notes/v0.2.0/notes._notes > /usr/share/zsh/functions/Completion/
50+
```
51+
4652
You'll need to open a new shell for this to take effect.
4753

4854
## How do I configure this?
@@ -94,7 +100,6 @@ All the above works. Here's what's coming next:
94100
- [ ] Combining find and grep, to match either one (https://github.com/pimterry/notes/issues/16)
95101
- [ ] More interesting and nicer looking file/grep search result formatting, perhaps only when not piping? (https://github.com/pimterry/notes/issues/27)
96102
- [ ] Make the file extension optional (https://github.com/pimterry/notes/issues/24)
97-
- [ ] zsh command and note name autocompletion (https://github.com/pimterry/notes/issues/25)
98103
- [ ] 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)
99104
- [ ] Tree view (https://github.com/pimterry/notes/issues/26)
100105
- [ ] 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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#compdef notes
2+
# ------------------------------------------------------------------------------
3+
# Copyright (c) 2016 Github zsh-users - http://github.com/zsh-users
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
# * Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the zsh-users nor the
14+
# names of its contributors may be used to endorse or promote products
15+
# derived from this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
21+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
# ------------------------------------------------------------------------------
28+
# Description
29+
# -----------
30+
#
31+
# Simple delightful note taking, with more unix and less lock-in. (https://github.com/pimterry/notes)
32+
#
33+
# ------------------------------------------------------------------------------
34+
# Authors
35+
# -------
36+
#
37+
# * Tim Perry (https://github.com/pimterry)
38+
# * Stefen Ramirez (https://github.com/RODNOTGOD)
39+
#
40+
# ------------------------------------------------------------------------------
41+
42+
__notes_cmd ()
43+
{
44+
local -a list
45+
list=(
46+
new:'Create new file'
47+
ls:'<pattern> List notes by path'
48+
find:'[pattern] Search notes by filename and path'
49+
grep:'<pattern> Search notes by content'
50+
open:'<name> Open a notes for editing by full name'
51+
rm:'[-r | --recursive] <name> Remove note, or folder if -r or --recursive is given]'
52+
--help:'Show usage'
53+
)
54+
_describe -t sub-commands 'sub commands' list && _ret=0
55+
}
56+
57+
_notes ()
58+
{
59+
local configured_dir=${NOTES_DIRECTORY%/}
60+
local note_dir="${configured_dir:-$HOME/notes}"
61+
62+
if (($CURRENT == 2)); then
63+
_alternative 'sub-commands:files:__notes_cmd' && _ret=0
64+
elif (($CURRENT == 3)); then
65+
case $words[2] in
66+
open|rm|new)
67+
_path_files -W "${note_dir}" && _ret=0;;
68+
ls)
69+
_path_files -W "${note_dir}" -/ && _ret=0;;
70+
esac
71+
fi
72+
}
73+
74+
# Local Variables:
75+
# mode: Shell-Script
76+
# sh-indentation: 2
77+
# indent-tabs-mode: nil
78+
# sh-basic-offset: 2
79+
# End:
80+
# vim: ft=zsh sw=2 ts=2 et

0 commit comments

Comments
 (0)