Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoCLI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
UI
DojoCLI
Commits
87f887d6
Commit
87f887d6
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Completion command => Add script command for zsh and bash
parent
3ef2b9e9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
NodeApp/src/commander/completion/subcommands/CompletionScriptCommand.ts
+75
-0
75 additions, 0 deletions
...mmander/completion/subcommands/CompletionScriptCommand.ts
with
75 additions
and
0 deletions
NodeApp/src/commander/completion/subcommands/CompletionScriptCommand.ts
0 → 100644
+
75
−
0
View file @
87f887d6
import
CommanderCommand
from
'
../../CommanderCommand
'
;
import
{
Argument
}
from
'
commander
'
;
class
CompletionScriptCommand
extends
CommanderCommand
{
protected
commandName
:
string
=
'
script
'
;
protected
defineCommand
()
{
this
.
command
.
description
(
'
generate script completion
'
)
.
addArgument
(
new
Argument
(
'
<shell>
'
,
'
shell completion format
'
).
choices
([
'
bash
'
,
'
zsh
'
]))
.
action
(
this
.
commandAction
.
bind
(
this
));
}
private
bashCompletionScript
()
{
console
.
log
(
`
#/usr/bin/env bash
###-begin-dojo-completions-###
#
# dojo command completion script for bash
#
# Installation: dojo completion bash
#
function _dojo_completions()
{
latest="
\$
{COMP_WORDS[$COMP_CWORD]}"
words=$(dojo completion get --shell bash
\$
{COMP_WORDS[@]})
COMPREPLY=($(compgen -W "$words" -- $latest))
return 0
}
complete -F _dojo_completions dojo
###-end-dojo-completions-###
`
);
}
private
zshCompletionScript
()
{
console
.
log
(
`
#compdef dojo
###-begin-dojo-completions-###
#
# dojo command completion script for zsh
#
# Installation: dojo completion zsh
#
_dojo_completions()
{
local reply
local si=$IFS
IFS=$'
' reply=($(dojo completion get --shell zsh
\$
{words[@]}))
IFS=$si
_describe 'values' reply
}
compdef _dojo_completions dojo
###-end-dojo-completions-###
`
);
}
protected
async
commandAction
(
shell
:
'
bash
'
|
'
zsh
'
):
Promise
<
void
>
{
switch
(
shell
)
{
case
'
bash
'
:
this
.
bashCompletionScript
();
break
;
case
'
zsh
'
:
this
.
zshCompletionScript
();
break
;
default
:
console
.
error
(
'
Unsupported shell completion format
'
);
break
;
}
}
}
export
default
new
CompletionScriptCommand
();
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment