Skip to content

Commit a289457

Browse files
author
Katrina Owen
authored
Merge pull request #616 from jdsutherland/migrate-completion-scripts-from-cli.exercism.io
Add shell completions and README to build script
2 parents fe7e728 + 86c68d1 commit a289457

File tree

4 files changed

+143
-8
lines changed

4 files changed

+143
-8
lines changed

bin/build-all

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ createRelease() {
5252
binname="$binname.exe"
5353
fi
5454

55-
relname="../release/$BINNAME-$osname-$osarch"
5655
echo "Creating $os/$arch binary..."
5756

5857
if [ "$arm" ]
@@ -62,15 +61,12 @@ createRelease() {
6261
GOOS=$os GOARCH=$arch go build -ldflags "$ldflags" -o "out/$binname" exercism/main.go
6362
fi
6463

65-
cd out
66-
67-
if [ "$osname" = windows ]
68-
then
69-
zip "$relname.zip" "$binname"
64+
release_name="release/$BINNAME-$osname-$osarch"
65+
if [ "$osname" = windows ]; then
66+
(cd out && zip "../$release_name.zip" ../shell/* "./$binname")
7067
else
71-
tar cvzf "$relname.tgz" "$binname"
68+
tar cvzf "$release_name.tgz" shell -C out "./$binname"
7269
fi
73-
cd ..
7470
}
7571

7672
# Mac Releases

shell/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Executable
2+
Unpack the archive relevant to your machine and place in $PATH
3+
4+
## Shell Completion Scripts
5+
6+
### Bash
7+
8+
mkdir -p ~/.config/exercism
9+
mv ../shell/exercism_completion.bash ~/.config/exercism/exercism\exercism_completion.bash
10+
11+
Load the completion in your `.bashrc`, `.bash_profile` or `.profile` by
12+
adding the following snippet:
13+
14+
if [ -f ~/.config/exercism/exercism_completion.bash ]; then
15+
source ~/.config/exercism/exercism_completion.bash
16+
fi
17+
18+
### Zsh
19+
20+
mkdir -p ~/.config/exercism
21+
mv ../shell/exercism_completion.zsh ~/.config/exercism/exercism_completion.zsh
22+
23+
Load up the completion in your `.zshrc`, `.zsh_profile` or `.profile` by adding
24+
the following snippet
25+
26+
if [ -f ~/.config/exercism/exercism_completion.zsh ]; then
27+
source ~/.config/exercism/exercism_completion.zsh
28+
fi
29+
30+
**Note:** If you are using the popular [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) framework to manage your zsh plugins, you don't need to add the above snippet, all you need to do is create a file `exercism_completion.zsh` inside the `~/.oh-my-zsh/custom`.

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)