diff --git a/src/index.ts b/src/index.ts index 35d9b47..5e0286a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -337,14 +337,16 @@ export class Completion { previousArgs: string[], toComplete: string ) { - const commandParts = [...previousArgs]; + const commandParts = [...previousArgs].filter(Boolean); for (const [k, command] of this.commands) { if (k === '') continue; + const parts = k.split(' '); - let match = true; + let match = true; let i = 0; + while (i < commandParts.length) { if (parts[i] !== commandParts[i]) { match = false; @@ -352,6 +354,7 @@ export class Completion { } i++; } + if (match && parts[i]?.startsWith(toComplete)) { this.completions.push({ value: parts[i],