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'`)
This commit is contained in:
Michael Cho 2021-03-21 07:55:23 -07:00 committed by GitHub
commit 071680800a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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'
)