Skip to content

Commit f6880d9

Browse files
committed
Add shell completion scripts directly to repo
1 parent bd566b5 commit f6880d9

File tree

4 files changed

+113
-17
lines changed

4 files changed

+113
-17
lines changed

BUILD.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Unpack the archive relevant to your machine and place in $PATH
66
### Bash
77

88
mkdir -p ~/.config/exercism
9-
mv ./exercism_completion.bash ~/.config/exercism/exercism\exercism_completion.bash
9+
mv ../shell/exercism_completion.bash ~/.config/exercism/exercism\exercism_completion.bash
1010

1111
Load the completion in your `.bashrc`, `.bash_profile` or `.profile` by
1212
adding the following snippet:
@@ -18,7 +18,7 @@ adding the following snippet:
1818
### Zsh
1919

2020
mkdir -p ~/.config/exercism
21-
mv ./exercism_completion.zsh ~/.config/exercism/exercism_completion.zsh
21+
mv ../shell/exercism_completion.zsh ~/.config/exercism/exercism_completion.zsh
2222

2323
Load up the completion in your `.zshrc`, `.zsh_profile` or `.profile` by adding
2424
the following snippet

bin/build-all

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ ARMVAR=github.com/exercism/cli/cmd.BuildARM
1313
# handle alternate binary name for pre-releases
1414
BINNAME=${NAME:-exercism}
1515

16-
get_shell_completions() {
17-
SHELLCOMP_BASEURL=http://cli.exercism.io/shell/exercism_completion
18-
curl -O $SHELLCOMP_BASEURL.bash -O $SHELLCOMP_BASEURL.zsh
19-
}
20-
21-
cleanup() {
22-
rm -f exercism_completion.bash exercism_completion.zsh
23-
}
24-
2516
createRelease() {
2617
os=$1
2718
arch=$2
@@ -75,15 +66,13 @@ createRelease() {
7566

7667
if [ "$osname" = windows ]
7768
then
78-
zip "$relname.zip" "$binname" ../exercism_completion* ../BUILD.md
69+
zip "$relname.zip" "$binname" ../shell ../BUILD.md
7970
else
80-
tar cvzf "$relname.tgz" "$binname" ../exercism_completion* ../BUILD.md
71+
tar cvzf "$relname.tgz" "$binname" ../shell ../BUILD.md
8172
fi
8273
cd ..
8374
}
8475

85-
get_shell_completions
86-
8776
# Mac Releases
8877
createRelease darwin 386
8978
createRelease darwin amd64
@@ -112,5 +101,3 @@ createRelease linux arm64
112101
# Windows Releases
113102
createRelease windows 386
114103
createRelease windows amd64
115-
116-
cleanup

shell/exercism_completion.bash

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
_exercism () {
2+
local cur prev
3+
4+
COMPREPLY=() # Array variable storing the possible completions.
5+
cur=${COMP_WORDS[COMP_CWORD]}
6+
prev=${COMP_WORDS[COMP_CWORD-1]}
7+
8+
commands="configure debug download fetch list open
9+
restore skip status submit tracks unsubmit
10+
upgrade help"
11+
tracks="csharp cpp clojure coffeescript lisp crystal
12+
dlang ecmascript elixir elm elisp erlang
13+
fsharp go haskell java javascript kotlin
14+
lfe lua mips ocaml objective-c php
15+
plsql perl5 python racket ruby rust scala
16+
scheme swift typescript bash c ceylon
17+
coldfusion delphi factor groovy haxe
18+
idris julia nim perl6 pony prolog
19+
purescript r sml vbnet powershell"
20+
config_opts="--dir --host --key --api"
21+
submit_opts="--test --comment"
22+
23+
if [ "${#COMP_WORDS[@]}" -eq 2 ]; then
24+
COMPREPLY=( $( compgen -W "${commands}" "${cur}" ) )
25+
return 0
26+
fi
27+
28+
if [ "${#COMP_WORDS[@]}" -eq 3 ]; then
29+
case "${prev}" in
30+
configure)
31+
COMPREPLY=( $( compgen -W "${config_opts}" -- "${cur}" ) )
32+
return 0
33+
;;
34+
fetch)
35+
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
36+
return 0
37+
;;
38+
list)
39+
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
40+
return 0
41+
;;
42+
open)
43+
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
44+
return 0
45+
;;
46+
skip)
47+
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
48+
return 0
49+
;;
50+
status)
51+
COMPREPLY=( $( compgen -W "${tracks}" "${cur}" ) )
52+
return 0
53+
;;
54+
submit)
55+
COMPREPLY=( $( compgen -W "${submit_opts}" -- "${cur}" ) )
56+
return 0
57+
;;
58+
help)
59+
COMPREPLY=( $( compgen -W "${commands}" "${cur}" ) )
60+
return 0
61+
;;
62+
*)
63+
return 0
64+
;;
65+
esac
66+
fi
67+
68+
return 0
69+
}
70+
71+
complete -F _exercism exercism

shell/exercism_completion.zsh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
_exercism() {
2+
local curcontext="$curcontext" state line
3+
typeset -A opt_args
4+
5+
local -a options
6+
options=(debug:"Outputs useful debug information."
7+
configure:"Writes config values to a JSON file."
8+
demo:"Fetches a demo problem for each language track on exercism.io."
9+
fetch:"Fetches your current problems on exercism.ios well as the next unstarted problem in each language."
10+
restore:"Restores completed and current problems on from exercism.iolong with your most recent iteration for each."
11+
submit:"Submits a new iteration to a problem on exercism.io."
12+
unsubmit:"Deletes the most recently submitted iteration."
13+
tracks:"List the available language tracks"
14+
download:"Downloads and saves a specified submission into the local system"
15+
help:"Shows a list of commands or help for one command")
16+
17+
_arguments -s -S \
18+
{-c,--config}"[path to config file]:file:_files" \
19+
{-d,--debug}"[turn on verbose logging]" \
20+
{-h,--help}"[show help]" \
21+
{-v,--version}"[print the version]" \
22+
'(-): :->command' \
23+
'(-)*:: :->option-or-argument' \
24+
&& return 0;
25+
26+
case $state in
27+
(command)
28+
_describe 'commands' options ;;
29+
(option-or-argument)
30+
case $words[1] in
31+
s*)
32+
_files
33+
;;
34+
esac
35+
esac
36+
}
37+
38+
compdef '_exercism' exercism

0 commit comments

Comments
 (0)