diff --git a/shell/README.md b/shell/README.md index 35b1e623c..b4c1509ce 100644 --- a/shell/README.md +++ b/shell/README.md @@ -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 @@ -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 - diff --git a/shell/exercism_completion.zsh b/shell/exercism_completion.zsh index f21553064..424b24e67 100644 --- a/shell/exercism_completion.zsh +++ b/shell/exercism_completion.zsh @@ -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