diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-01-12 17:46:04 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-01-12 17:46:04 +0300 |
commit | 62e09984bf054e96cedb7eefaf0f59b35b270c07 (patch) | |
tree | da322fab9ad72d4e02c4c8d95bd2b9e9d8e9afe6 | |
parent | 0fbed9a95255c9a6ade511bf3c12286f4450fa90 (diff) | |
download | openrussian-cli-62e09984bf054e96cedb7eefaf0f59b35b270c07.tar.gz |
added support for Zsh autocompletions
* actually autocompletions are much more powerful than on Bash
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | openrussian-completion.zsh | 12 |
3 files changed, 30 insertions, 3 deletions
@@ -3,7 +3,8 @@ PREFIX ?= /usr/local LUA ?= lua5.2 LUAC ?= luac5.2 -COMPLETIONSDIR ?= $(shell pkg-config --variable=completionsdir bash-completion) +BASH_COMPLETIONSDIR ?= $(shell pkg-config --variable=completionsdir bash-completion) +ZSH_COMPLETIONSDIR ?= $(PREFIX)/share/zsh/site-functions all : openrussian openrussian-sqlite3.db @@ -44,7 +45,14 @@ install : openrussian openrussian-sqlite3.db \ install openrussian $(DESTDIR)$(PREFIX)/bin mkdir -p $(DESTDIR)$(PREFIX)/share/openrussian cp openrussian-sqlite3.db $(DESTDIR)$(PREFIX)/share/openrussian - cp openrussian-completion.bash $(DESTDIR)$(COMPLETIONSDIR)/openrussian +ifneq ($(BASH_COMPLETIONSDIR),) + mkdir -p $(DESTDIR)$(BASH_COMPLETIONSDIR) + cp openrussian-completion.bash $(DESTDIR)$(BASH_COMPLETIONSDIR)/openrussian +endif +ifneq ($(ZSH_COMPLETIONSDIR),) + mkdir -p $(DESTDIR)$(ZSH_COMPLETIONSDIR) + cp openrussian-completion.zsh $(DESTDIR)$(ZSH_COMPLETIONSDIR)/_openrussian +endif mkdir -p $(DESTDIR)$(PREFIX)/man/man1 cp openrussian.1 $(DESTDIR)$(PREFIX)/man/man1 mandb || true @@ -11,7 +11,7 @@ based on the database of [openrussian.org](https://en.openrussian.org/). pages ~~very easy~~ possible. * Puts very low requirements on the runtime environment: a black and white terminal display is sufficient. -* Bash auto completions supported. +* Auto completions supported for Bash and Zsh. Most of this is handled by the script's `-C` argument, so it is trivial to add support for other shells. Contributions are welcome! @@ -125,6 +125,13 @@ something like the following to your `~/.bash_completion`: alias ru='openrussian -Lde -Len' ру='openrussian -Lde -Len' complete -F _complete_alias ru ру +### Zsh Aliases + +Autocompletion will automatically work with aliases in the Zsh, so it is +sufficient to add the following to your `~/.zshrc`: + + alias ru='openrussian -Lde -Len' ру='openrussian -Lde -Len' + ## Examples A simple lookup: diff --git a/openrussian-completion.zsh b/openrussian-completion.zsh new file mode 100644 index 0000000..e3669c0 --- /dev/null +++ b/openrussian-completion.zsh @@ -0,0 +1,12 @@ +#compdef openrussian + +# FIXME: If supported by `-C`, we could even show translations in the completions' +# help strings. +_get_terms() { + compadd "${(@f)"$(openrussian -C "$words[-1]" 2>/dev/null)"}" +} + +_arguments '-Len[Generate English translations]' '-Lde[Generate German translations]' \ + '-V[Verbatim matching (no case folding and inflections)]' \ + '-p[Print Troff code to stdout]' \ + '*:term:_get_terms' |