Skip to content

Commit 70ee518

Browse files
committed
Make zsh completion work on $fpath.
This allows the file to be placed, e.g., in a system-wide `site-functions` directory and just work automatically.
1 parent a86f829 commit 70ee518

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

shell/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ adding the following snippet:
1717

1818
### Zsh
1919

20+
Load up the completion by placing the `exercism_completion.zsh` somewhere on
21+
your `$fpath` as `_exercism`. For example:
22+
2023
mkdir -p ~/.config/exercism
21-
mv ../shell/exercism_completion.zsh ~/.config/exercism/exercism_completion.zsh
24+
mv ../shell/exercism_completion.zsh ~/.config/exercism/_exercism
2225

23-
Load up the completion in your `.zshrc`, `.zsh_profile` or `.profile` by adding
24-
the following snippet
26+
and then add the directory to your `$fpath` in your `.zshrc`, `.zsh_profile` or
27+
`.profile` before running `compinit`:
2528

26-
if [ -f ~/.config/exercism/exercism_completion.zsh ]; then
27-
source ~/.config/exercism/exercism_completion.zsh
28-
fi
29+
export fpath=(~/.config/exercism $fpath)
30+
autoload -U compinit && compinit
2931

3032

3133
#### Oh my Zsh

shell/exercism_completion.zsh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#compdef exercism
2+
13
_exercism() {
24
local curcontext="$curcontext" state line
35
typeset -A opt_args
@@ -33,4 +35,4 @@ _exercism() {
3335
esac
3436
}
3537

36-
compdef '_exercism' exercism
38+
_exercism "$@"

0 commit comments

Comments
 (0)