Skip to content

Commit 7c0ad27

Browse files
committed
update
1 parent dae6ae7 commit 7c0ad27

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

src/bash.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ __${nameForVar}_complete() {
4242
local requestComp out directive
4343
4444
# Build the command to get completions
45-
# Use a more compatible approach instead of \${words[@]:1}
46-
local args=""
47-
for (( i=1; i<cword+1; i++ )); do
48-
if [[ -n "\${words[i]}" ]]; then
49-
args="$args \\"\${words[i]}\\""
50-
fi
51-
done
52-
requestComp="${exec} complete --$args"
45+
requestComp="${exec} complete -- \${words[@]:1}"
5346
5447
# Add an empty parameter if the last parameter is complete
5548
if [[ -z "$cur" ]]; then
@@ -125,5 +118,6 @@ __${nameForVar}_complete() {
125118
126119
# Register completion function
127120
complete -F __${nameForVar}_complete ${name}
121+
128122
`;
129123
}

tests/package-manager-integration.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,22 @@ describe('package manager integration tests', () => {
114114
// If we get here, syntax is valid
115115
expect(true).toBe(true);
116116
} catch (error) {
117-
throw new Error(`${pm} bash script has syntax errors: ${error}`);
117+
const errorMessage =
118+
error instanceof Error ? error.message : String(error);
119+
120+
// Provide helpful error message about bash-completion dependency
121+
const helpMessage = `
122+
${pm} bash script has syntax errors: ${errorMessage}
123+
124+
This might be due to missing bash-completion dependency.
125+
To fix this, install bash-completion@2:
126+
127+
brew install bash-completion@2
128+
129+
Then source the completion in your shell profile:
130+
echo 'source $(brew --prefix)/share/bash-completion/bash_completion' >> ~/.bashrc
131+
`;
132+
throw new Error(helpMessage);
118133
} finally {
119134
// Clean up
120135
await unlink(scriptPath).catch(() => {});
@@ -125,9 +140,10 @@ describe('package manager integration tests', () => {
125140
const command = `pnpm tsx bin/cli.ts ${pm} bash`;
126141
const { stdout } = await exec(command);
127142

128-
// Check for the actual problematic bash syntax in the requestComp assignment
129-
expect(stdout).not.toMatch(/requestComp="[^"]*\$\{words\[@\]:1\}/); // Should not use ${words[@]:1} in requestComp
143+
// Check that it uses the correct ${words[@]:1} syntax (requires bash-completion@2)
144+
expect(stdout).toContain('${words[@]:1}'); // Should use ${words[@]:1} (requires bash-completion@2)
130145
expect(stdout).toContain('complete -F'); // Should register completion properly
146+
expect(stdout).toContain('_get_comp_words_by_ref'); // Should use bash-completion functions
131147

132148
// Should contain package manager specific function
133149
expect(stdout).toMatch(

tests/shell-integration.test.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,22 @@ describe('shell integration tests', () => {
7878
// If we get here, syntax is valid
7979
expect(true).toBe(true);
8080
} catch (error) {
81-
throw new Error(`Bash script has syntax errors: ${error}`);
81+
const errorMessage =
82+
error instanceof Error ? error.message : String(error);
83+
84+
// Provide helpful error message about bash-completion dependency
85+
const helpMessage = `
86+
Bash script has syntax errors: ${errorMessage}
87+
88+
This might be due to missing bash-completion dependency.
89+
To fix this, install bash-completion@2:
90+
91+
brew install bash-completion@2
92+
93+
Then source the completion in your shell profile:
94+
echo 'source $(brew --prefix)/share/bash-completion/bash_completion' >> ~/.bashrc
95+
`;
96+
throw new Error(helpMessage);
8297
} finally {
8398
// Clean up
8499
await unlink(scriptPath).catch(() => {});
@@ -224,14 +239,15 @@ describe('shell integration tests', () => {
224239

225240
// Test for potential bash issues (related to the user's problem)
226241
describe('bash-specific issue detection', () => {
227-
it('should generate bash script with proper escaping', async () => {
242+
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);
230245

231-
// Check for the actual problematic bash syntax in the requestComp assignment
232-
expect(stdout).not.toMatch(/requestComp="[^"]*\$\{words\[@\]:1\}/); // Should not use ${words[@]:1} in requestComp
246+
// Check that it uses the correct ${words[@]:1} syntax
247+
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
250+
expect(stdout).toContain('_get_comp_words_by_ref'); // Should use bash-completion functions
235251
});
236252

237253
it('should generate bash script that handles empty parameters correctly', async () => {

0 commit comments

Comments
 (0)