Skip to content

Commit

Permalink
Merge pull request exercism#806 from QuLogic/zsh-fpath
Browse files Browse the repository at this point in the history
Make zsh completion work on $fpath.
  • Loading branch information
Katrina Owen authored Feb 26, 2019
2 parents a86f829 + d431fd8 commit 4924d44
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
17 changes: 9 additions & 8 deletions shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ adding the following snippet:

### Zsh

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

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

if [ -f ~/.config/exercism/exercism_completion.zsh ]; then
source ~/.config/exercism/exercism_completion.zsh
fi
and then add the directory to your `$fpath` in your `.zshrc`, `.zsh_profile` or
`.profile` before running `compinit`:

export fpath=(~/.zsh/functions $fpath)
autoload -U compinit && compinit


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

mv ../shell/exercism.fish ~/.config/fish/exercism.fish

62 changes: 30 additions & 32 deletions shell/exercism_completion.zsh
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
_exercism() {
local curcontext="$curcontext" state line
typeset -A opt_args
#compdef exercism

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

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

case $state in
(command)
_describe 'commands' options ;;
(option-or-argument)
case $words[1] in
s*)
_files
;;
esac
esac
}
_arguments -s -S \
{-h,--help}"[show help]" \
{-t,--timeout}"[override default HTTP timeout]" \
{-v,--verbose}"[turn on verbose logging]" \
'(-): :->command' \
'(-)*:: :->option-or-argument' \
&& return 0;

compdef '_exercism' exercism
case $state in
(command)
_describe 'commands' options ;;
(option-or-argument)
case $words[1] in
s*)
_files
;;
esac
esac

0 comments on commit 4924d44

Please sign in to comment.