From 70ee5185a065aaf943eeca4accff02464ebd5589 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 10 Feb 2019 03:28:56 -0500 Subject: [PATCH 1/3] 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. --- shell/README.md | 14 ++++++++------ shell/exercism_completion.zsh | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/shell/README.md b/shell/README.md index 35b1e623c..a1a2161f4 100644 --- a/shell/README.md +++ b/shell/README.md @@ -17,15 +17,17 @@ adding the following snippet: ### Zsh +Load up the completion by placing the `exercism_completion.zsh` somewhere on +your `$fpath` as `_exercism`. For example: + mkdir -p ~/.config/exercism - mv ../shell/exercism_completion.zsh ~/.config/exercism/exercism_completion.zsh + mv ../shell/exercism_completion.zsh ~/.config/exercism/_exercism -Load up the completion in your `.zshrc`, `.zsh_profile` or `.profile` by adding -the following snippet +and then add the directory to your `$fpath` in your `.zshrc`, `.zsh_profile` or +`.profile` before running `compinit`: - if [ -f ~/.config/exercism/exercism_completion.zsh ]; then - source ~/.config/exercism/exercism_completion.zsh - fi + export fpath=(~/.config/exercism $fpath) + autoload -U compinit && compinit #### Oh my Zsh diff --git a/shell/exercism_completion.zsh b/shell/exercism_completion.zsh index f21553064..2c1311240 100644 --- a/shell/exercism_completion.zsh +++ b/shell/exercism_completion.zsh @@ -1,3 +1,5 @@ +#compdef exercism + _exercism() { local curcontext="$curcontext" state line typeset -A opt_args @@ -33,4 +35,4 @@ _exercism() { esac } -compdef '_exercism' exercism +_exercism "$@" From 890edd978f560fdfcdb3a27f911fa77512f2f948 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 24 Feb 2019 19:48:45 -0500 Subject: [PATCH 2/3] Remove extra function around zsh completion script. --- shell/exercism_completion.zsh | 62 ++++++++++++++++------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/shell/exercism_completion.zsh b/shell/exercism_completion.zsh index 2c1311240..424b24e67 100644 --- a/shell/exercism_completion.zsh +++ b/shell/exercism_completion.zsh @@ -1,38 +1,34 @@ #compdef exercism -_exercism() { - local curcontext="$curcontext" state line - typeset -A opt_args +local curcontext="$curcontext" state line +typeset -A opt_args - 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 -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") - _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; +_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; - case $state in - (command) - _describe 'commands' options ;; - (option-or-argument) - case $words[1] in - s*) - _files - ;; - esac - esac -} - -_exercism "$@" +case $state in + (command) + _describe 'commands' options ;; + (option-or-argument) + case $words[1] in + s*) + _files + ;; + esac +esac From d431fd86dcb31bb84c31987917e7c0c0f0df11f4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 24 Feb 2019 19:57:12 -0500 Subject: [PATCH 3/3] doc: Use more idiomatic zsh fpath. --- shell/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/shell/README.md b/shell/README.md index a1a2161f4..b4c1509ce 100644 --- a/shell/README.md +++ b/shell/README.md @@ -20,13 +20,13 @@ adding the following snippet: Load up the completion by placing the `exercism_completion.zsh` somewhere on your `$fpath` as `_exercism`. For example: - mkdir -p ~/.config/exercism - mv ../shell/exercism_completion.zsh ~/.config/exercism/_exercism + mkdir -p ~/.zsh/functions + mv ../shell/exercism_completion.zsh ~/.zsh/functions/_exercism and then add the directory to your `$fpath` in your `.zshrc`, `.zsh_profile` or `.profile` before running `compinit`: - export fpath=(~/.config/exercism $fpath) + export fpath=(~/.zsh/functions $fpath) autoload -U compinit && compinit @@ -39,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 -