Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class RootCommand extends Command {
commands = new Map<string, Command>();
completions: Completion[] = [];
directive = ShellCompDirective.ShellCompDirectiveDefault;
private isCompletingFlags = false;

constructor() {
super('', '');
Expand Down Expand Up @@ -385,7 +386,13 @@ export class RootCommand extends Command {
}

private complete(toComplete: string) {
this.directive = ShellCompDirective.ShellCompDirectiveNoFileComp;
// only disable file completion when completing flags
// allow file fallback for commands/positional args
if (this.isCompletingFlags) {
this.directive = ShellCompDirective.ShellCompDirectiveNoFileComp;
} else {
this.directive = ShellCompDirective.ShellCompDirectiveDefault;
}

const seen = new Set<string>();
this.completions
Expand Down Expand Up @@ -431,13 +438,15 @@ export class RootCommand extends Command {
const lastPrevArg = previousArgs[previousArgs.length - 1];

if (this.shouldCompleteFlags(lastPrevArg, toComplete)) {
this.isCompletingFlags = true;
this.handleFlagCompletion(
matchedCommand,
previousArgs,
toComplete,
lastPrevArg
);
} else {
this.isCompletingFlags = false;
if (lastPrevArg?.startsWith('-') && toComplete === '' && endsWithSpace) {
let option = this.findOption(this, lastPrevArg);
if (!option) {
Expand Down
Loading