Skip to content

Commit

Permalink
Merge pull request exercism#759 from nywilken/tab-completion-update
Browse files Browse the repository at this point in the history
Update shell tab completion for exercism cli
  • Loading branch information
Katrina Owen authored Nov 5, 2018
2 parents 97d69cc + 517f301 commit 4ae3f85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 44 deletions.
55 changes: 17 additions & 38 deletions shell/exercism_completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ _exercism () {
COMPREPLY=() # Array variable storing the possible completions.
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts="--verbose --timeout"

commands="configure debug download fetch list open
restore skip status submit tracks unsubmit
upgrade help"
tracks="csharp cpp clojure coffeescript lisp crystal
dlang ecmascript elixir elm elisp erlang
fsharp go haskell java javascript kotlin
lfe lua mips ocaml objective-c php
plsql perl5 python racket ruby rust scala
scheme swift typescript bash c ceylon
coldfusion delphi factor groovy haxe
idris julia nim perl6 pony prolog
purescript r sml vbnet powershell"
config_opts="--dir --host --key --api"
submit_opts="--test --comment"
commands="configure download open
submit troubleshoot upgrade version workspace help"
config_opts="--show"
version_opts="--latest"

if [ "${#COMP_WORDS[@]}" -eq 2 ]; then
COMPREPLY=( $( compgen -W "${commands}" "${cur}" ) )
return 0
case "${cur}" in
-*)
COMPREPLY=( $( compgen -W "${opts}" -- "${cur}" ) )
return 0
;;
*)
COMPREPLY=( $( compgen -W "${commands}" "${cur}" ) )
return 0
;;
esac
fi

if [ "${#COMP_WORDS[@]}" -eq 3 ]; then
Expand All @@ -31,28 +30,8 @@ _exercism () {
COMPREPLY=( $( compgen -W "${config_opts}" -- "${cur}" ) )
return 0
;;
fetch)
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
return 0
;;
list)
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
return 0
;;
open)
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
return 0
;;
skip)
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
return 0
;;
status)
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
return 0
;;
submit)
COMPREPLY=( $( compgen -W "${submit_opts}" -- "${cur}" ) )
version)
COMPREPLY=( $( compgen -W "${version_opts}" -- "${cur}" ) )
return 0
;;
help)
Expand Down
15 changes: 9 additions & 6 deletions shell/exercism_completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ _exercism() {
typeset -A opt_args

local -a options
options=(debug:"Outputs useful debug information."
configure:"Writes config values to a JSON file."
submit:"Submits a new iteration to a problem on exercism.io."
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 \
{-c,--config}"[path to config file]:file:_files" \
{-d,--debug}"[turn on verbose logging]" \
{-h,--help}"[show help]" \
{-v,--version}"[print the version]" \
{-t,--timeout}"[override default HTTP timeout]" \
{-v,--verbose}"[turn on verbose logging]" \
'(-): :->command' \
'(-)*:: :->option-or-argument' \
&& return 0;
Expand Down

0 comments on commit 4ae3f85

Please sign in to comment.