Skip to content
Draft
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/mean-stingrays-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bomb.sh/tab": patch
---

fix: wrap dashes and arguments in single quotes
5 changes: 4 additions & 1 deletion src/powershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ export function generate(name: string, exec: string): string {
# Split the command at the first space to separate the program and arguments.
$Program, $Arguments = $Command.Split(" ", 2)

$RequestComp = "& ${exec} complete -- $Arguments"
$QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
__${name}_debug "QuotedArgs: $QuotedArgs"

$RequestComp = "& ${exec} complete '--' $QuotedArgs"
__${name}_debug "RequestComp: $RequestComp"

# we cannot use $WordToComplete because it
Expand Down
4 changes: 3 additions & 1 deletion tests/shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ describe('shell completion generators', () => {
expect(script).toContain(`[scriptblock]$__${name}CompleterBlock =`);

// Check that the script uses the provided exec path
expect(script).toContain(`$RequestComp = "& ${exec} complete --`);
expect(script).toContain(
`$RequestComp = "& ${exec} complete '--' $QuotedArgs"`
);

// Check that the script handles directives
expect(script).toContain(
Expand Down
Loading