Skip to main content

keep_shell_after

Function keep_shell_after 

Source
pub fn keep_shell_after(command: &str) -> String
Expand description

Wrap a command line so that, after it exits, the pane/window/tab keeps a fresh interactive login shell instead of closing.

The tmux and zellij launchers (session, window/tab, panes) run the command as the pane’s program (bash -lc <cmd>), so when the AI tool exits the pane/tab/session closes with it — you lose the worktree context and can’t run follow-up commands. WezTerm and iTerm don’t have this problem because they type the command into an already-running shell; tmux’s own session launcher sidesteps it by send-keys-ing into a pre-spawned shell.

Appending ; exec "${SHELL:-bash}" -l makes the affected launchers behave the same way: the command runs, then — regardless of its exit code (;, not &&) — control drops to a fresh login shell in the same cwd. A non-zero exit leaves the user at a prompt with the context intact rather than closing the pane.

${SHELL:-bash} honors the user’s login shell when the env var is present (the common case when gw is run from an interactive session) and falls back to bash otherwise. The result is still meant to be passed to bash -lc, so <cmd> keeps whatever quoting it already carries.