Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Dynamically render POSIX shim
Maximilian Roose7b834d850b6
diff --git a/src/shell.rs b/src/shell.rsindex a44ddf293..f04b97a30 100644--- a/src/shell.rs+++ b/src/shell.rs@@ -1,8 +1,6 @@use askama::Template;use std::path::PathBuf;-const POSIX_DIRECTIVE_SHIM: &str = include_str!("../templates/posix_directives.sh");-/// Supported shells#[derive(Debug, Clone, Copy, clap::ValueEnum, strum::Display, strum::EnumString)]#[strum(serialize_all = "lowercase", ascii_case_insensitive)]@@ -300,17 +298,25 @@ impl ShellInit {pub fn generate(&self, cli_cmd: &clap::Command) -> Result<String, askama::Error> {match self.shell {Shell::Bash | Shell::Oil => {+ let posix_shim = PosixDirectivesTemplate {+ cmd_prefix: &self.cmd_prefix,+ }+ .render()?;let template = BashTemplate {shell_name: self.shell.to_string(),cmd_prefix: &self.cmd_prefix,- posix_shim: POSIX_DIRECTIVE_SHIM,+ posix_shim: &posix_shim,};template.render()}Shell::Zsh => {+ let posix_shim = PosixDirectivesTemplate {+ cmd_prefix: &self.cmd_prefix,+ }+ .render()?;let template = ZshTemplate {cmd_prefix: &self.cmd_prefix,- posix_shim: POSIX_DIRECTIVE_SHIM,+ posix_shim: &posix_shim,};template.render()}@@ -351,6 +357,13 @@ impl ShellInit {}}+/// POSIX directive shim template (shared by bash, zsh, oil)+#[derive(Template)]+#[template(path = "posix_directives.sh", escape = "none")]+struct PosixDirectivesTemplate<'a> {+ cmd_prefix: &'a str,+}+/// Bash shell template#[derive(Template)]#[template(path = "bash.sh", escape = "none")]diff --git a/templates/posix_directives.sh b/templates/posix_directives.shindex eee87f0cc..d625bab03 100644--- a/templates/posix_directives.sh+++ b/templates/posix_directives.sh@@ -3,6 +3,8 @@# and hint messages stream immediately while keeping stderr attached to the TTY.# Note: Named without leading underscore to avoid being filtered by shell# snapshot systems (e.g., Claude Code) that exclude private functions.+# Note: Uses ${_WORKTRUNK_CMD:-{{ cmd_prefix }}} fallback because shell snapshot+# systems may capture functions but not environment variables.wt_exec() {local exec_cmd="" chunk="" exit_code=0 tmp_dir="" exit_file="" fifo_path="" runner_pid=""@@ -21,7 +23,7 @@ wt_exec() {fi(- command "$_WORKTRUNK_CMD" "$@"+ command "${_WORKTRUNK_CMD:-{{ cmd_prefix }}}" "$@"printf '%s' "$?" >"$exit_file") >"$fifo_path" &runner_pid=$!diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex 1fc81de64..a0d90c94a 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpl6vlQ1/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpxzUWIj/test-config.toml---success: trueexit_code: 0@@ -34,6 +34,8 @@ if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then# and hint messages stream immediately while keeping stderr attached to the TTY.# Note: Named without leading underscore to avoid being filtered by shell# snapshot systems (e.g., Claude Code) that exclude private functions.+# Note: Uses ${_WORKTRUNK_CMD:-wt} fallback because shell snapshot+# systems may capture functions but not environment variables.wt_exec() {local exec_cmd="" chunk="" exit_code=0 tmp_dir="" exit_file="" fifo_path="" runner_pid=""@@ -52,7 +54,7 @@ wt_exec() {fi(- command "$_WORKTRUNK_CMD" "$@"+ command "${_WORKTRUNK_CMD:-wt}" "$@"printf '%s' "$?" >"$exit_file") >"$fifo_path" &runner_pid=$!@@ -90,7 +92,6 @@ wt_exec() {return "$exit_code"}-# Override wt command to add --internal flagwt() {# Initialize _WORKTRUNK_CMD if not set (e.g., after shell snapshot restore)diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 8a127258d..8be669ea1 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpTOuQ5R/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp5Q3l96/test-config.toml---success: trueexit_code: 0@@ -34,6 +34,8 @@ if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then# and hint messages stream immediately while keeping stderr attached to the TTY.# Note: Named without leading underscore to avoid being filtered by shell# snapshot systems (e.g., Claude Code) that exclude private functions.+# Note: Uses ${_WORKTRUNK_CMD:-wt} fallback because shell snapshot+# systems may capture functions but not environment variables.wt_exec() {local exec_cmd="" chunk="" exit_code=0 tmp_dir="" exit_file="" fifo_path="" runner_pid=""@@ -52,7 +54,7 @@ wt_exec() {fi(- command "$_WORKTRUNK_CMD" "$@"+ command "${_WORKTRUNK_CMD:-wt}" "$@"printf '%s' "$?" >"$exit_file") >"$fifo_path" &runner_pid=$!@@ -90,7 +92,6 @@ wt_exec() {return "$exit_code"}-# Override wt command to add --internal flagwt() {# Initialize _WORKTRUNK_CMD if not set (e.g., after shell snapshot restore)