Skip to content

Commit

Permalink
fix(command): arg with no completions followed by args with completio…
Browse files Browse the repository at this point in the history
…ns breaks zsh completion (#688)
  • Loading branch information
c4spar committed Mar 25, 2024
1 parent e9a400a commit 53551ac
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions command/completions/_zsh_completions_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function _${replaceSpecialChars(path)}() {` +
}
}

if (completions) {
if (command.hasArguments() || command.hasCommands(false)) {
completions = `\n\n function _commands() {${completions}\n }`;
}

Expand Down Expand Up @@ -185,23 +185,18 @@ function _${replaceSpecialChars(path)}() {` +
argsCommand += ` \\\n ${options.join(" \\\n ")}`;
}

if (
command.hasCommands(false) || (
command.getArguments()
.filter((arg) => command.getCompletion(arg.action)).length
)
) {
if (command.hasArguments() || command.hasCommands(false)) {
argsCommand += ` \\\n '${++argIndex}:command:_commands'`;
}

if (command.hasArguments() || command.hasCommands(false)) {
const args: string[] = [];

// first argument is completed together with commands.
for (const arg of command.getArguments().slice(1)) {
const type = command.getType(arg.type);

if (type && type.handler instanceof FileType) {
const fileCompletions = this.getFileCompletions(type);

if (arg.variadic) {
argIndex++;
for (let i = 0; i < 5; i++) {
Expand Down

0 comments on commit 53551ac

Please sign in to comment.