Skip to content

fix zsh auto complete function issue, and update the readme file about a fast way to enable zsh completion. #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,17 @@ To enable autocompletion for the tldr command, run:

It's easiest for
[oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
users, so let's start with that.
users, please run the following commands.

```zsh
mkdir -p $ZSH_CUSTOM/plugins/tldr
ln -s bin/completion/zsh/_tldr $ZSH_CUSTOM/plugins/tldr/_tldr
[ -d ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/completions ] \
|| mkdir -p ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/completions \
&& cp $(npm root -g)/tldr/bin/completion/zsh/_tldr ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/completions
```

Then add tldr to your oh-my-zsh plugins,
usually defined in `~/.zshrc`,
resulting in something looking like this:
It will add _tldr file to your $ZSH_CUSTOM/completions or ~/.oh-my-zsh/custom/completions directory,
then start a new terminal session or run: `compinit` to enable the completion.

```zsh
plugins=(git tmux tldr)
```

Fret not regular zsh user!
You can also do this:
Expand Down
14 changes: 11 additions & 3 deletions bin/completion/zsh/_tldr
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#compdef tldr

local -a pages platforms
pages=$(tldr -a1)
platforms='( android freebsd linux netbsd openbsd osx sunos windows )'

# a lot of special characters in the tldr pages names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# a lot of special characters in the tldr pages names
# there is a lot of special characters in the tldr pages names

# like ! [ ] [[ { } ( ) , and so on
# so we need to escape them one by one
for page_name in $(tldr -a | sed 's/\,//g'); do
pages+=(${(q)page_name})
done
unset page_name

platforms='(android freebsd linux netbsd openbsd osx sunos windows)'

_arguments \
'(- *)'{-h,--help}'[show help]' \
Expand All @@ -29,4 +37,4 @@ _arguments \
'--win32[override operating system with Windows]' \
'--windows[override operating system with Windows]' \
'(- *)'{-c,--clear-cache}'[clear local cache]' \
"*:page:(${(b)pages})" && return 0
"*:page:(${pages})" && return 0