Skip to content

Commit

Permalink
completions: support completion subcommand (#649)
Browse files Browse the repository at this point in the history
Make the completion scripts support the new `configlet completion`
subcommand from commit d10dcd6, so that tab completion works for
things like:

    $ configlet comp[Tab]

and

    $ configlet completion -s [Tab]

Closes: #648
  • Loading branch information
ee7 authored Aug 9, 2022
1 parent 77f7fbf commit 4447bd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions completions/configlet.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ _configlet_completion_() {

local i
for ((i = 1; i < COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} == @(lint|generate|info|uuid|fmt|sync) ]]; then
if [[ ${COMP_WORDS[i]} == @(completion|lint|generate|info|uuid|fmt|sync) ]]; then
"_configlet_complete_${COMP_WORDS[i]}_"
return
fi
done

_configlet_complete_options_ "fmt generate info lint sync uuid $global_opts"
_configlet_complete_options_ "completion fmt generate info lint sync uuid $global_opts"
}

_configlet_complete_global_option_() {
Expand All @@ -45,6 +45,17 @@ _configlet_complete_global_option_() {
return 1
}

_configlet_complete_completion_() {
case $prev in
'-s' | '--shell')
_configlet_complete_options_ "bash fish"
;;
*)
_configlet_complete_options_ "-s --shell $global_opts"
;;
esac
}

_configlet_complete_lint_() {
_configlet_complete_options_ "$global_opts"
}
Expand Down
5 changes: 5 additions & 0 deletions completions/configlet.fish
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ complete -c configlet -s v -l verbosity -x -a "quiet normal detailed" -d "Verbos
complete -c configlet -n "__fish_use_subcommand" -a lint -f -d "Check the track configuration for correctness"
complete -c configlet -n "__fish_use_subcommand" -a generate -f -d "Generate concept exercise introductions"

# completion subcommand
complete -c configlet -n "__fish_use_subcommand" -a completion -f -d "Output a completion script for a given shell"
complete -c configlet -n "__fish_seen_subcommand_from completion" -s s -l shell -d "Shell type" \
-x -a "bash fish"

# info subcommand
complete -c configlet -n "__fish_use_subcommand" -a info -f -d "Track info"
complete -c configlet -n "__fish_seen_subcommand_from info" -s o -l offline -f -d "Do not update prob-specs cache"
Expand Down

0 comments on commit 4447bd2

Please sign in to comment.