Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Fixes the regression introduced in PR #162 where complex multi-line bash scripts with conditionals would fail with exit code 2.

Problem

The original implementation wrapped commands using JSON.stringify, which converted newlines to literal \n strings:

nice -n 19 bash -c "if [ \0 -ne 0 ]; then\n  echo \"test\"\nfi"

This broke bash syntax, causing scripts with conditionals and multi-line logic to fail.

Solution

Spawn nice directly with proper arguments array instead of string wrapping:

spawn("nice", ["-n", "19", "bash", "-c", script], ...)

This avoids all escaping issues while maintaining the same niceness functionality.

Testing

Added comprehensive test coverage:

  • ✅ Complex multi-line scripts with conditionals (reproduces the git status regression)
  • ✅ Exit code handling with niceness
  • ✅ Simple commands with niceness

All 36 tests pass including the new niceness test suite.

Generated with cmux

The previous implementation used JSON.stringify to wrap the command,
which converted newlines to literal \n strings, breaking multi-line
bash scripts.

Now spawn 'nice' directly with proper arguments: nice -n N bash -c "script"
This avoids all escaping issues while maintaining the same functionality.

Added comprehensive test coverage for:
- Complex multi-line scripts with conditionals
- Exit code handling with niceness
- Simple commands with niceness
@ammar-agent ammar-agent force-pushed the fix-bash-nice-regression branch from 979ee50 to 83b620c Compare October 10, 2025 19:38
@ammario ammario enabled auto-merge October 10, 2025 19:39
@ammario ammario added this pull request to the merge queue Oct 10, 2025
Merged via the queue into main with commit 87fbdb0 Oct 10, 2025
7 checks passed
@ammario ammario deleted the fix-bash-nice-regression branch October 10, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants