Skip to content

Commit

Permalink
fix: fix zsh completion bugs (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredLunde authored Feb 22, 2023
1 parent 23cee30 commit c7036ac
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions completions/zsh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,11 @@ function* completeArgsAndFlags(

if (args.length > 0 || flags.length > 0) {
yield `_arguments -s \\`;
const argsAndFlags = [...args, ...flags];

for (let i = 0; i < args.length; i++) {
const arg = args[i];
yield ` ${arg}` + (i === args.length - 1 ? "" : " \\");
}

for (let i = 0; i < flags.length; i++) {
const flag = flags[i];
yield ` ${flag}` + (i === flags.length - 1 ? "" : " \\");
for (let i = 0; i < argsAndFlags.length; i++) {
const arg = argsAndFlags[i];
yield ` ${arg}` + (i === argsAndFlags.length - 1 ? "" : " \\");
}
}
}
Expand All @@ -167,7 +163,6 @@ function completeArgs(
.replace(":", " ");
let action = ``;
// A zsh variadic argument
const variadicPrefix = variadic ? "*" : " ";
const type = innerType(arg);

if (type instanceof z.ZodEnum || type instanceof z.ZodNativeEnum) {
Expand All @@ -179,14 +174,9 @@ function completeArgs(
}

args.push(
`"${variadicPrefix ? "*" : ""}${
variadicPrefix ||
hasOptionalArgs ||
arg instanceof z.ZodOptional ||
arg instanceof z.ZodDefault
? ":"
: position + 1
}:${message}:${action}" \\`,
`"${variadic ? "*" : ""}${
variadic ? ":" : `${position + 1}:`
}:${message}:${action}"`,
);
});

Expand Down

0 comments on commit c7036ac

Please sign in to comment.