Skip to content
Snippets Groups Projects
Commit 87f887d6 authored by michael.minelli's avatar michael.minelli
Browse files

Completion command => Add script command for zsh and bash

parent 3ef2b9e9
Branches
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment