diff --git a/.changeset/mean-stingrays-begin.md b/.changeset/mean-stingrays-begin.md new file mode 100644 index 0000000..63bf43d --- /dev/null +++ b/.changeset/mean-stingrays-begin.md @@ -0,0 +1,5 @@ +--- +'@bomb.sh/tab': patch +--- + +fix: wrap dashes and arguments in single quotes diff --git a/src/powershell.ts b/src/powershell.ts index 002d314..1a555a5 100644 --- a/src/powershell.ts +++ b/src/powershell.ts @@ -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 diff --git a/tests/shell.test.ts b/tests/shell.test.ts index b65c4ec..807fde9 100644 --- a/tests/shell.test.ts +++ b/tests/shell.test.ts @@ -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(