From 071680800a875357aa2f798eac0b080d7188345c Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sun, 21 Mar 2021 07:55:23 -0700 Subject: [PATCH] zsh-completion: fix issue with [.md, add basic -L completion, remove extra _files args (#168) - Use array `commands=(...)` and `_describe` to deal with '[.md' & empty cache scenario. Fixes #166 - Hide `tldr --list` stderr (`2>/dev/null`) which breaks completion with empty cache - Remove `sed` since #112 changed commas to newlines - Add new `sed`-equivalent replacement (`:` -> `\:`) using native [ZSH `${name//pattern/repl}`](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion) since colon is special character in ZSH completions - Add basic support for `-L, --language` flag from #125. In future, can consider adding extra completions maybe based on caches `pages.{lang}` folders. - Remove extraneous completion of file names for positional arguments (i.e. `'*:file:_files'`) --- zsh_tealdeer | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zsh_tealdeer b/zsh_tealdeer index 2f55a389..96e40f02 100644 --- a/zsh_tealdeer +++ b/zsh_tealdeer @@ -1,7 +1,9 @@ #compdef tldr _applications() { - _values 'applications' "${(uonzf)$(tldr --list | sed -e 's/, /\n/g')}" + local -a commands + commands=(${(uonzf)"$(tldr --list 2>/dev/null)"//:/\\:}) + _describe -t commands 'command' commands } _tealdeer() { @@ -18,6 +20,7 @@ _tealdeer() { sunos windows ))' + "($I -L --language)"{-L,--language}"[Override the language settings]:lang" "($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]" @@ -31,8 +34,7 @@ _tealdeer() { never ))" '(- *)'{-h,--help}'[Display help]' - '(- *)'{-v,--version}'[Show version information]' - '*:file:_files' + '(- *)'{-v,--version}'[Show version information]' '1: :_applications' )