Skip to content

Commit 88bfb2a

Browse files
authored
fix: wrap dashes and arguments in single quotes (#93)
1 parent 71152e6 commit 88bfb2a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.changeset/mean-stingrays-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@bomb.sh/tab': patch
3+
---
4+
5+
fix: wrap dashes and arguments in single quotes

src/powershell.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export function generate(name: string, exec: string): string {
7171
# Split the command at the first space to separate the program and arguments.
7272
$Program, $Arguments = $Command.Split(" ", 2)
7373
74-
$RequestComp = "& ${exec} complete -- $Arguments"
74+
$QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
75+
__${name}_debug "QuotedArgs: $QuotedArgs"
76+
77+
$RequestComp = "& ${exec} complete '--' $QuotedArgs"
7578
__${name}_debug "RequestComp: $RequestComp"
7679
7780
# we cannot use $WordToComplete because it

tests/shell.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ describe('shell completion generators', () => {
162162
expect(script).toContain(`[scriptblock]$__${name}CompleterBlock =`);
163163

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

167169
// Check that the script handles directives
168170
expect(script).toContain(

0 commit comments

Comments
 (0)