Title: here mode level 1: match teamocil — use set_environment + respawn-pane, keep send_keys cd only · Issue #1031 · tmux-python/tmuxp · GitHub
Open Graph Title: here mode level 1: match teamocil — use set_environment + respawn-pane, keep send_keys cd only · Issue #1031 · tmux-python/tmuxp
X Title: here mode level 1: match teamocil — use set_environment + respawn-pane, keep send_keys cd only · Issue #1031 · tmux-python/tmuxp
Description: Parent: #1030 Approach Match teamocil's --here strategy: minimize send_keys to only the unavoidable cd command. Use tmux primitives for everything else. Changes to builder.py:678-727 1. Environment: replace send_keys("export ...") with s...
Open Graph Description: Parent: #1030 Approach Match teamocil's --here strategy: minimize send_keys to only the unavoidable cd command. Use tmux primitives for everything else. Changes to builder.py:678-727 1. Environment...
X Description: Parent: #1030 Approach Match teamocil's --here strategy: minimize send_keys to only the unavoidable cd command. Use tmux primitives for everything else. Changes to builder.py:678-727 1. Environ...
Opengraph URL: https://github.com/tmux-python/tmuxp/issues/1031
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"here mode level 1: match teamocil — use set_environment + respawn-pane, keep send_keys cd only","articleBody":"Parent: #1030\n\n## Approach\n\nMatch teamocil's `--here` strategy: minimize `send_keys` to only the unavoidable `cd` command. Use tmux primitives for everything else.\n\n### Changes to [`builder.py:678-727`](https://github.com/tmux-python/tmuxp/blob/886e63d37dbfeeefab1e645f168178b13ff03b7f/src/tmuxp/workspace/builder.py#L678-L727)\n\n#### 1. Environment: replace `send_keys(\"export ...\")` with `session.set_environment()`\n\ntmuxp already uses `session.set_environment()` for session-level env vars at [`builder.py:557-559`](https://github.com/tmux-python/tmuxp/blob/886e63d37dbfeeefab1e645f168178b13ff03b7f/src/tmuxp/workspace/builder.py#L557-L559). Window-level env vars set on the session are inherited by all new panes.\n\n```python\n# Before (lines 708-715): send_keys for each env var\nfor _ekey, _eval in environment.items():\n _here_pane.send_keys(f\"export {_ekey}={shlex.quote(str(_eval))}\", enter=True)\n\n# After: use tmux session environment (inherited by panes)\nif environment:\n for _ekey, _eval in environment.items():\n session.set_environment(_ekey, str(_eval))\n```\n\nThis matches how teamocil handles it — teamocil [does not inject env vars at all](https://github.com/remi/teamocil/blob/9ceecf5/lib/teamocil/tmux/window.rb#L67-L95). The session environment is the tmux-native mechanism.\n\n**Caveat**: `set_environment` only affects *new* shells spawned in the session. The already-running shell in the reused pane won't see them. This is acceptable because:\n- Subsequent panes (created via `split`) will inherit them\n- The reused pane can pick them up if the user starts a new shell\n- This is the same limitation teamocil has (it doesn't set env vars at all in `--here`)\n\n#### 2. Shell replacement: replace `send_keys(window_shell)` with `respawn-pane`\n\n```python\n# Before (lines 724-727): send_keys to type shell command\n_here_pane.send_keys(window_shell, enter=True)\n\n# After: use respawn-pane to restart pane with new shell\nif window_shell:\n _here_pane = window.active_pane\n if _here_pane is not None:\n _here_pane.cmd(\"respawn-pane\", \"-k\", window_shell)\n```\n\n`respawn-pane -k` kills the current process and starts a new one in the same pane. Available since tmux 1.6, well within tmuxp's 3.2+ minimum. This also picks up the session environment set above.\n\n#### 3. Directory: keep `send_keys(\"cd ...\")` (same as teamocil)\n\n```python\n# Keep as-is (lines 695-701) — matches teamocil\nactive_pane.send_keys(f\"cd {shlex.quote(start_directory)}\", enter=True)\n```\n\nteamocil uses the [same approach](https://github.com/remi/teamocil/blob/9ceecf5/lib/teamocil/tmux/window.rb#L88-L95): `send_keys cd \"/path\"` for the reused window's first pane.\n\n### Result\n\n| Category | Before | After |\n|----------|--------|-------|\n| `cd` | `send_keys` | `send_keys` (same as teamocil) |\n| Environment | `send_keys export` (N calls) | `session.set_environment()` (tmux primitive) |\n| Shell replacement | `send_keys` (types into pane) | `respawn-pane -k` (tmux primitive) |\n\n`send_keys` surface reduced from 3 categories to 1, matching teamocil exactly.\n\n### Risk assessment\n\n- **Low risk**: `session.set_environment()` is already used in the same file\n- **Low risk**: `respawn-pane` is a stable tmux command (available since 1.6)\n- **Caveat**: env vars only visible to new shells, not the existing one — acceptable trade-off\n- **Remaining**: `send_keys cd` still assumes a shell prompt (same as teamocil)\n\n### Tests to add/update\n\n- Update `test_here_mode_provisions_environment` to verify `session.show_environment()` instead of pane output\n- Add test for `window_shell` via `respawn-pane`\n- Keep existing `test_here_mode_start_directory_special_chars` (still uses `send_keys cd`)","author":{"url":"https://github.com/tony","@type":"Person","name":"tony"},"datePublished":"2026-03-29T09:32:47Z","url":"https://github.com/tmux-python/tmuxp/issues/1031"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:aea60c2c-62b8-ec89-6d4f-8f05363f8e8f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DDA2:74B5:26F1AA:363E2A:6B0088AA |
| html-safe-nonce | 3edf42c603e33c6b12e001b5e7a2ebd7ade8a2e1bf693f5dd75af690ea656270 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREEyOjc0QjU6MjZGMUFBOjM2M0UyQTo2QjAwODhBQSIsInZpc2l0b3JfaWQiOiI4MDgxOTM1ODkwNzcyOTUzMjU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3988ba75ffa9eb46d58ecccee668aadd832b6f8974fad4bbf2250afbbd04ea92 |
| hovercard-subject-tag | issue:4163550619 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/tmux-python/tmuxp/1031/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5ec452544e8b1b4e6d3bc3ff7205ed3c4d800f8511564f7c6a8c557ac331051a/tmux-python/tmuxp/issues/1031 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5ec452544e8b1b4e6d3bc3ff7205ed3c4d800f8511564f7c6a8c557ac331051a/tmux-python/tmuxp/issues/1031 |
| og:image:alt | Parent: #1030 Approach Match teamocil's --here strategy: minimize send_keys to only the unavoidable cd command. Use tmux primitives for everything else. Changes to builder.py:678-727 1. Environment... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tony |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61 |
| turbo-cache-control | no-preview |
| go-import | github.com/tmux-python/tmuxp git https://github.com/tmux-python/tmuxp.git |
| octolytics-dimension-user_id | 37234308 |
| octolytics-dimension-user_login | tmux-python |
| octolytics-dimension-repository_id | 12398170 |
| octolytics-dimension-repository_nwo | tmux-python/tmuxp |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 12398170 |
| octolytics-dimension-repository_network_root_nwo | tmux-python/tmuxp |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | db758f8e02b8257935fb03edf81a3e76eb3abd11 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width