-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completion: add zsh #653
completion: add zsh #653
Changes from 10 commits
091cd75
0362834
6f2d280
6e975a1
1fcb990
ab6e1cc
7d9709b
796252a
7936c87
b43cd5a
833522b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#compdef configlet | ||
|
||
autoload -U is-at-least | ||
|
||
(( $+functions[_configlet_commands] )) || | ||
_configlet_commands() { | ||
local commands | ||
commands=( | ||
# subcommands with no options | ||
"generate:Generate concept exercise introductions" \ | ||
"lint:Check the track configuration for correctness" \ | ||
# subcommands with options | ||
"completion:Output a completion script for a given shell" \ | ||
"fmt:Format the exercise '.meta/config.json' files" \ | ||
"info:Print track information" \ | ||
"sync:Check or update Practice Exercise docs, metadata, and tests" \ | ||
"uuid:Output a version 4 UUID" \ | ||
) | ||
_describe -t commands 'configlet commands' commands "$@" | ||
} | ||
|
||
_configlet() { | ||
typeset -a _arguments_options | ||
|
||
if is-at-least 5.2; then | ||
_arguments_options=(-s -S -C) | ||
else | ||
_arguments_options=(-s -C) | ||
fi | ||
|
||
local line | ||
local curcontext="$curcontext" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From
|
||
|
||
_configlet_global_opts=( | ||
{-h,--help}'[Show help]' | ||
'--version[Show version information]' | ||
'(-t --track-dir)'{-t+,--track-dir=}'[Select a track directory]:directory:_directories' | ||
{-v,--verbosity}'[Verbosity level]: :(quiet normal detailed)' | ||
) | ||
|
||
_arguments "${_arguments_options[@]}" \ | ||
"$_configlet_global_opts[@]" \ | ||
":: :_configlet_commands" \ | ||
"*::: :->configlet" | ||
|
||
words=($line[1] "${words[@]}") | ||
(( CURRENT += 1 )) | ||
curcontext="${curcontext%:*:*}:configlet-command-$line[1]:" | ||
|
||
_configlet_complete_any_exercise_slug() { | ||
local -a cmd slugs slug_paths | ||
slug_paths=(./exercises/concept/*(/)) | ||
slugs=( ${${slug_paths#./exercises/concept/}%-*-*} ) | ||
slug_paths=(./exercises/practice/*(/)) | ||
slugs+=( ${${slug_paths#./exercises/practice/}%-*-*} ) | ||
compadd "$@" -a slugs | ||
} | ||
|
||
_configlet_complete_practice_exercise_slug() { | ||
local -a cmd slugs slug_paths | ||
slug_paths=(./exercises/practice/*(/)) | ||
slugs=( ${${slug_paths#./exercises/practice/}%-*-*} ) | ||
compadd "$@" -a slugs | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this could use a refactor. Note that this can suggest invalid slugs, because it:
Let's handle that later - we should fix it for the bash and fish completion scripts too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored somewhat in 833522b |
||
|
||
case $line[1] in | ||
# subcommands with no options | ||
(generate) | ||
_arguments "${_arguments_options[@]}" \ | ||
"$_configlet_global_opts[@]" \ | ||
;; | ||
(lint) | ||
_arguments "${_arguments_options[@]}" \ | ||
"$_configlet_global_opts[@]" \ | ||
;; | ||
# subcommands with options | ||
(completion) | ||
_arguments "${_arguments_options[@]}" \ | ||
"$_configlet_global_opts[@]" \ | ||
{-s,--shell}'[Select the shell type]: :(bash fish zsh)' \ | ||
;; | ||
(fmt) | ||
_arguments "${_arguments_options[@]}" \ | ||
"$_configlet_global_opts[@]" \ | ||
'(-e --exercise)'{-e+,--exercise=}'[exercise slug]:slug:_configlet_complete_any_exercise_slug' \ | ||
{-u,--update}'[Write changes]' \ | ||
{-y,--yes}'[Auto-confirm update]' \ | ||
;; | ||
(info) | ||
_arguments "${_arguments_options[@]}" \ | ||
"$_configlet_global_opts[@]" \ | ||
{-o,--offline}'[Do not update prob-specs cache]' \ | ||
;; | ||
(sync) | ||
_arguments "${_arguments_options[@]}" \ | ||
"$_configlet_global_opts[@]" \ | ||
'(-e --exercise)'{-e+,--exercise=}'[exercise slug]:slug:_configlet_complete_practice_exercise_slug' \ | ||
{-o,--offline}'[Do not update prob-specs cache]' \ | ||
{-u,--update}'[Write changes]' \ | ||
{-y,--yes}'[Auto-confirm update]' \ | ||
'--docs[Sync docs only]' \ | ||
'--filepaths[Populate .meta/config.json "files" entry]' \ | ||
'--metadata[Sync metadata only]' \ | ||
'--tests[For auto-confirming]: :(choose include exclude)' \ | ||
;; | ||
(uuid) | ||
_arguments "${_arguments_options[@]}" \ | ||
"$_configlet_global_opts[@]" \ | ||
'(-n --num)'{-n+,--num=}'[How many UUIDs]:' \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
;; | ||
esac | ||
} | ||
|
||
_configlet "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ type | |
sNil = "nil" | ||
sBash = "bash" | ||
sFish = "fish" | ||
sZsh = "zsh" | ||
|
||
SyncKind* = enum | ||
skDocs = "docs" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From
man zshcompsys
: