Skip to content

Commit 3ef4d18

Browse files
authored
Merge pull request #83 from eshapard/master
2 parents 428946e + 7770325 commit 3ef4d18

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ curl https://raw.githubusercontent.com/pimterry/notes/latest-release/notes > /us
4343

4444
#### Installing auto completion
4545

46-
`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.
46+
`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), Zsh, or Fish-shell to be installed - it's probably available from your friendly local package manager.
4747

48-
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:
48+
To enable completion for notes, copy the completion script into your bash, zsh, or fish 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. The fish completion directory is `~/.config/fish/completions` or `/etc/fish/completions`. You may be able to find your own bash completion directory by running the following command:
4949

5050
pkg-config --variable=completionsdir bash-completion
5151

@@ -69,6 +69,11 @@ On other Unix distros:
6969
```bash
7070
curl -L https://raw.githubusercontent.com/pimterry/notes/latest-release/_notes > /usr/share/zsh/site-functions/_notes
7171
```
72+
**Fish**
73+
74+
```fish
75+
curl -L https://raw.githubusercontent.com/pimterry/notes/latest-release/notes.fish > ~/.config/fish/completions/notes.fish
76+
```
7277

7378
You'll need to open a new shell for this to take effect.
7479

notes.fish

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Notes completion file for fish shell <https://github.com/pimterry/notes>
2+
# Place in ~/.config/fish/completions/
3+
4+
# Set some useful local variables
5+
## lists of commands used by notes
6+
set -l notes_list_commands o open mv rm cat
7+
set -l notes_friendly_commands new open find ls rm cat mv grep
8+
set -l notes_commands n new ls find f grep g search s open o mv rm cat
9+
set -l notes_dir_commands n new grep ls
10+
11+
# NOTES_DIRECTORY
12+
## use NOTES_DIRECTORY variable if set else...
13+
if not set -q NOTES_DIRECTORY
14+
## if config file exists, read it
15+
if test -e $HOME/.config/notes/config
16+
set NOTES_DIRECTORY (string split = (grep "NOTES_DIRECTORY" $HOME/.config/notes/config))[2]
17+
end
18+
end
19+
## in case of failure, use default notes dir
20+
if not set -q NOTES_DIRECTORY[1]
21+
set NOTES_DIRECTORY "$HOME/notes"
22+
end
23+
24+
# FILE COMPLETIONS
25+
complete -c notes -f
26+
complete -c notes -n "not __fish_seen_subcommand_from $notes_commands" -a "$notes_friendly_commands"
27+
complete -c notes -n "__fish_seen_subcommand_from $notes_list_commands" -a "(notes find|grep -v '~\$'|sed 's/[.]md\$//')"
28+
complete -c notes -n "__fish_seen_subcommand_from $notes_dir_commands" -a "(find $NOTES_DIRECTORY -type d -printf '%P/\n')"

0 commit comments

Comments
 (0)