···4242 local requestComp out directive
43434444 # Build the command to get completions
4545- # Use a more compatible approach instead of \${words[@]:1}
4646- local args=""
4747- for (( i=1; i<cword+1; i++ )); do
4848- if [[ -n "\${words[i]}" ]]; then
4949- args="$args \\"\${words[i]}\\""
5050- fi
5151- done
5252- requestComp="${exec} complete --$args"
4545+ requestComp="${exec} complete -- \${words[@]:1}"
53465447 # Add an empty parameter if the last parameter is complete
5548 if [[ -z "$cur" ]]; then
···125118126119# Register completion function
127120complete -F __${nameForVar}_complete ${name}
121121+128122`;
129123}
+19-3
tests/package-manager-integration.test.ts
···114114 // If we get here, syntax is valid
115115 expect(true).toBe(true);
116116 } catch (error) {
117117- throw new Error(`${pm} bash script has syntax errors: ${error}`);
117117+ const errorMessage =
118118+ error instanceof Error ? error.message : String(error);
119119+120120+ // Provide helpful error message about bash-completion dependency
121121+ const helpMessage = `
122122+${pm} bash script has syntax errors: ${errorMessage}
123123+124124+This might be due to missing bash-completion dependency.
125125+To fix this, install bash-completion@2:
126126+127127+ brew install bash-completion@2
128128+129129+Then source the completion in your shell profile:
130130+ echo 'source $(brew --prefix)/share/bash-completion/bash_completion' >> ~/.bashrc
131131+`;
132132+ throw new Error(helpMessage);
118133 } finally {
119134 // Clean up
120135 await unlink(scriptPath).catch(() => {});
···125140 const command = `pnpm tsx bin/cli.ts ${pm} bash`;
126141 const { stdout } = await exec(command);
127142128128- // Check for the actual problematic bash syntax in the requestComp assignment
129129- expect(stdout).not.toMatch(/requestComp="[^"]*\$\{words\[@\]:1\}/); // Should not use ${words[@]:1} in requestComp
143143+ // Check that it uses the correct ${words[@]:1} syntax (requires bash-completion@2)
144144+ expect(stdout).toContain('${words[@]:1}'); // Should use ${words[@]:1} (requires bash-completion@2)
130145 expect(stdout).toContain('complete -F'); // Should register completion properly
146146+ expect(stdout).toContain('_get_comp_words_by_ref'); // Should use bash-completion functions
131147132148 // Should contain package manager specific function
133149 expect(stdout).toMatch(
+20-4
tests/shell-integration.test.ts
···7878 // If we get here, syntax is valid
7979 expect(true).toBe(true);
8080 } catch (error) {
8181- throw new Error(`Bash script has syntax errors: ${error}`);
8181+ const errorMessage =
8282+ error instanceof Error ? error.message : String(error);
8383+8484+ // Provide helpful error message about bash-completion dependency
8585+ const helpMessage = `
8686+Bash script has syntax errors: ${errorMessage}
8787+8888+This might be due to missing bash-completion dependency.
8989+To fix this, install bash-completion@2:
9090+9191+ brew install bash-completion@2
9292+9393+Then source the completion in your shell profile:
9494+ echo 'source $(brew --prefix)/share/bash-completion/bash_completion' >> ~/.bashrc
9595+`;
9696+ throw new Error(helpMessage);
8297 } finally {
8398 // Clean up
8499 await unlink(scriptPath).catch(() => {});
···224239225240 // Test for potential bash issues (related to the user's problem)
226241 describe('bash-specific issue detection', () => {
227227- it('should generate bash script with proper escaping', async () => {
242242+ it('should generate bash script with proper syntax (requires bash-completion@2)', async () => {
228243 const command = `pnpm tsx examples/demo.${cliTool}.ts complete bash`;
229244 const { stdout } = await exec(command);
230245231231- // Check for the actual problematic bash syntax in the requestComp assignment
232232- expect(stdout).not.toMatch(/requestComp="[^"]*\$\{words\[@\]:1\}/); // Should not use ${words[@]:1} in requestComp
246246+ // Check that it uses the correct ${words[@]:1} syntax
247247+ expect(stdout).toContain('${words[@]:1}'); // Should use ${words[@]:1} (requires bash-completion@2)
233248 expect(stdout).toContain('requestComp='); // Should have proper variable assignment
234249 expect(stdout).toContain('complete -F'); // Should register completion properly
250250+ expect(stdout).toContain('_get_comp_words_by_ref'); // Should use bash-completion functions
235251 });
236252237253 it('should generate bash script that handles empty parameters correctly', async () => {