From ece174e1fc9c59859b044aedd11af31dfdd722c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Renaud?= Date: Tue, 27 Aug 2019 03:11:06 -0400 Subject: [PATCH] Add zsh autocompletion (#86) --- README.md | 1 + zsh_tealdeer | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 zsh_tealdeer diff --git a/README.md b/README.md index 637288b..b0e7a42 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ set the `PAGER` environment variable. - *Bash*: copy `bash_tealdeer` to `/usr/share/bash-completion/completions/tldr` - *Fish*: copy `fish_tealdeer` to `~/.config/fish/completions/tldr.fish` +- *Zsh*: copy `zsh_tealdeer` to `/usr/share/zsh/site-functions/_tldr` ## Development diff --git a/zsh_tealdeer b/zsh_tealdeer new file mode 100644 index 0000000..93528a0 --- /dev/null +++ b/zsh_tealdeer @@ -0,0 +1,37 @@ +#compdef tldr + +_applications() { + _values 'applications' "${(uonzf)$(tldr --list | sed -e 's/, /\n/g')}" +} + +_tealdeer() { + local I="-h --help -v --version" + integer ret=1 + local -a args + + args+=( + "($I -l --list)"{-l,--list}"[List all commands in the cache]" + "($I -f --render)"{-f,--render}"[Render a specific markdown file]:file:_files" + "($I -o --os)"{-o,--os}'[Override the operating system]:os:(( + linux + osx + sunos + windows + ))' + "($I -u --update)"{-u,--update}"[Update the local cache]" + "($I -c --clear-cache)"{-c,--clear-cache}"[Clear the local cache]" + "($I -p --pager)"{-p,--pager}"[Use a pager to page output]" + "($I -q --quiet)"{-q,--quiet}"[Suppress informational messages]" + "($I)--config-path[Show config file path]" + "($I)--seed-config[Create a basic config]" + '(- *)'{-h,--help}'[Display help]' + '(- *)'{-v,--version}'[Show version information]' + '*:file:_files' + '1: :_applications' + ) + + _arguments $args[@] && ret=0 + return ret +} + +_tealdeer