Skip to content

fix: handle quoted arguments in shell-exec on macOS#1398

Open
LeonidasZhak wants to merge 1 commit into
glzr-io:mainfrom
LeonidasZhak:codex/fix-shell-exec-quoting-macos
Open

fix: handle quoted arguments in shell-exec on macOS#1398
LeonidasZhak wants to merge 1 commit into
glzr-io:mainfrom
LeonidasZhak:codex/fix-shell-exec-quoting-macos

Conversation

@LeonidasZhak

Copy link
Copy Markdown

Summary

Fixes shell-exec on macOS to properly handle quoted arguments (e.g. app names with spaces).

Problem

On macOS, shell-exec splits arguments on whitespace without respecting shell-style quotes. This causes commands like:

- "shell-exec open -a \"Microsoft Outlook\""

to fail because "Microsoft Outlook" gets split into "Microsoft and Outlook" as separate arguments.

Solution

Use shlex::split to parse the arguments string with proper shell quoting rules before passing them to Shell::spawn. Falls back to whitespace splitting if shlex can't parse the input (e.g. unmatched quotes).

The shlex crate is a well-established, pure-Rust implementation of POSIX shell quoting (already a transitive dependency in the lockfile).

Changes

  • packages/wm/Cargo.toml: Add shlex = "1.3" dependency
  • packages/wm/src/commands/general/shell_exec.rs:
    • Add split_shell_args() helper (macOS-only, gated with #[cfg(target_os = "macos")])
    • Replace args.split_whitespace() with split_shell_args(&args) in the macOS Shell::spawn call

Testing

  • cargo check --package wm passes
  • cargo test --package wm passes (2 existing tests)
  • Verified the fix handles: double-quoted args, single-quoted args, unquoted args, and mixed quoting

Related

Fixes #1337

Use shlex::split to properly parse shell-style quoted arguments
when spawning commands on macOS. Previously, args were split on
whitespace without respecting quotes, causing commands like
`shell-exec open -a "Microsoft Outlook"` to fail because the
quoted app name was split into separate arguments.

Fixes glzr-io#1337
@github-project-automation github-project-automation Bot moved this to 📬 Needs triage in glazewm Jun 3, 2026
@LeonidasZhak
LeonidasZhak force-pushed the codex/fix-shell-exec-quoting-macos branch from 477b5fe to 6712c4d Compare June 3, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📬 Needs triage

Development

Successfully merging this pull request may close these issues.

[Bug] macOS shell-exec does not handle quoted arguments correctly for app names with spaces

1 participant