Skip to content

Commit 4924d44

Browse files
author
Katrina Owen
authored
Merge pull request #806 from QuLogic/zsh-fpath
Make zsh completion work on $fpath.
2 parents a86f829 + d431fd8 commit 4924d44

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

shell/README.md

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

1818
### Zsh
1919

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

23-
Load up the completion in your `.zshrc`, `.zsh_profile` or `.profile` by adding
24-
the following snippet
23+
mkdir -p ~/.zsh/functions
24+
mv ../shell/exercism_completion.zsh ~/.zsh/functions/_exercism
2525

26-
if [ -f ~/.config/exercism/exercism_completion.zsh ]; then
27-
source ~/.config/exercism/exercism_completion.zsh
28-
fi
26+
and then add the directory to your `$fpath` in your `.zshrc`, `.zsh_profile` or
27+
`.profile` before running `compinit`:
28+
29+
export fpath=(~/.zsh/functions $fpath)
30+
autoload -U compinit && compinit
2931

3032

3133
#### Oh my Zsh
@@ -37,4 +39,3 @@ If you are using the popular [oh-my-zsh](https://github.com/robbyrussell/oh-my-z
3739
Completions must go in the user defined `$fish_complete_path`. By default, this is `~/.config/fish/completions`
3840

3941
mv ../shell/exercism.fish ~/.config/fish/exercism.fish
40-

shell/exercism_completion.zsh

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
_exercism() {
2-
local curcontext="$curcontext" state line
3-
typeset -A opt_args
1+
#compdef exercism
42

5-
local -a options
6-
options=(configure:"Writes config values to a JSON file."
7-
download:"Downloads and saves a specified submission into the local system"
8-
open:"Opens a browser to exercism.io for the specified submission."
9-
submit:"Submits a new iteration to a problem on exercism.io."
10-
troubleshoot:"Outputs useful debug information."
11-
upgrade:"Upgrades to the latest available version."
12-
version:"Outputs version information."
13-
workspace:"Outputs the root directory for Exercism exercises."
14-
help:"Shows a list of commands or help for one command")
3+
local curcontext="$curcontext" state line
4+
typeset -A opt_args
155

16-
_arguments -s -S \
17-
{-h,--help}"[show help]" \
18-
{-t,--timeout}"[override default HTTP timeout]" \
19-
{-v,--verbose}"[turn on verbose logging]" \
20-
'(-): :->command' \
21-
'(-)*:: :->option-or-argument' \
22-
&& return 0;
6+
local -a options
7+
options=(configure:"Writes config values to a JSON file."
8+
download:"Downloads and saves a specified submission into the local system"
9+
open:"Opens a browser to exercism.io for the specified submission."
10+
submit:"Submits a new iteration to a problem on exercism.io."
11+
troubleshoot:"Outputs useful debug information."
12+
upgrade:"Upgrades to the latest available version."
13+
version:"Outputs version information."
14+
workspace:"Outputs the root directory for Exercism exercises."
15+
help:"Shows a list of commands or help for one command")
2316

24-
case $state in
25-
(command)
26-
_describe 'commands' options ;;
27-
(option-or-argument)
28-
case $words[1] in
29-
s*)
30-
_files
31-
;;
32-
esac
33-
esac
34-
}
17+
_arguments -s -S \
18+
{-h,--help}"[show help]" \
19+
{-t,--timeout}"[override default HTTP timeout]" \
20+
{-v,--verbose}"[turn on verbose logging]" \
21+
'(-): :->command' \
22+
'(-)*:: :->option-or-argument' \
23+
&& return 0;
3524

36-
compdef '_exercism' exercism
25+
case $state in
26+
(command)
27+
_describe 'commands' options ;;
28+
(option-or-argument)
29+
case $words[1] in
30+
s*)
31+
_files
32+
;;
33+
esac
34+
esac

0 commit comments

Comments
 (0)