Skip to content

Commit

Permalink
zsh-completion: fix issue with [.md, add basic -L completion, remove …
Browse files Browse the repository at this point in the history
…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'`)
  • Loading branch information
Michael Cho authored Mar 21, 2021
1 parent 2a6d095 commit 0716808
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions zsh_tealdeer
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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]"
Expand All @@ -31,8 +34,7 @@ _tealdeer() {
never
))"
'(- *)'{-h,--help}'[Display help]'
'(- *)'{-v,--version}'[Show version information]'
'*:file:_files'
'(- *)'{-v,--version}'[Show version information]'
'1: :_applications'
)

Expand Down

0 comments on commit 0716808

Please sign in to comment.