diff --git a/README.md b/README.md index 51c741f4..709e30a1 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/bin/completion/zsh/_tldr b/bin/completion/zsh/_tldr index ad1e9ba6..81368165 100644 --- a/bin/completion/zsh/_tldr +++ b/bin/completion/zsh/_tldr @@ -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 +# 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]' \ @@ -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