Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

refactor: consolidate shell escaping on shell_escape, drop shlex (#1065)

Maximilian Roos8ba5cd80023d
diff --git a/Cargo.lock b/Cargo.lock
index ed7495b70..b0306df00 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3219,7 +3219,6 @@ dependencies = [
"serde_json",
"shell-escape",
"shellexpand",
- "shlex",
"signal-hook 0.4.3",
"similar",
"skim",
diff --git a/Cargo.toml b/Cargo.toml
index e1e6fcadc..911d2afd0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -86,7 +86,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shell-escape = "0.1"
shellexpand = "3.1"
-shlex = "1.3"
strum = { version = "0.27", features = ["derive"] }
synoptic = "2"
terminal_size = "0.4"
diff --git a/src/commands/handle_switch.rs b/src/commands/handle_switch.rs
index d3a43fdfc..4d6738311 100644
--- a/src/commands/handle_switch.rs
+++ b/src/commands/handle_switch.rs
@@ -261,7 +261,7 @@ pub fn handle_switch(
.collect();
let escaped_args: Vec<_> = expanded_args?
.iter()
- .map(|arg| shlex::try_quote(arg).unwrap_or(arg.into()).into_owned())
+ .map(|arg| shell_escape::escape(arg.into()).into_owned())
.collect();
format!("{} {}", expanded_cmd, escaped_args.join(" "))
};
diff --git a/src/commands/select/mod.rs b/src/commands/select/mod.rs
index 1de3f095f..6f43119f5 100644
--- a/src/commands/select/mod.rs
+++ b/src/commands/select/mod.rs
@@ -138,9 +138,7 @@ pub fn handle_select(cli_branches: bool, cli_remotes: bool) -> anyhow::Result<()
// Get state path for key bindings (shell-escaped for safety)
let state_path_display = state.path.display().to_string();
- let state_path_str = shlex::try_quote(&state_path_display)
- .map(|s| s.into_owned())
- .unwrap_or(state_path_display);
+ let state_path_str = shell_escape::escape(state_path_display.into()).into_owned();
// Calculate half-page scroll: skim uses 90% of terminal height, half of that = 45%
let half_page = terminal_size::terminal_size()
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_in_args.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_in_args.snap
index 54fccfd60..f03de2fed 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_in_args.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_in_args.snap
@@ -35,6 +35,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -50,4 +51,4 @@ branch=args-test repo=repo
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
◎ Executing (--execute) @ _REPO_.args-test:
-  echo 'branch=args-test' 'repo=repo'
+  echo branch=args-test repo=repo