tmux-python / tmux-python/tmuxp

here mode level 1: match teamocil — use set_environment + respawn-pane, keep send_keys cd only

Open
#1,031 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.6k
Forks
248
Avg merge
2h 13m
Merged PRs (30d)
1

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 session.set_environment()

tmuxp already uses session.set_environment() for session-level env vars at builder.py:557-559. Window-level env vars set on the session are inherited by all new panes.

# Before (lines 708-715): send_keys for each env var
for _ekey, _eval in environment.items():
    _here_pane.send_keys(f"export {_ekey}={shlex.quote(str(_eval))}", enter=True)

# After: use tmux session environment (inherited by panes)
if environment:
    for _ekey, _eval in environment.items():
        session.set_environment(_ekey, str(_eval))

This matches how teamocil handles it — teamocil does not inject env vars at all. The session environment is the tmux-native mechanism.

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:

  • Subsequent panes (created via split) will inherit them
  • The reused pane can pick them up if the user starts a new shell
  • This is the same limitation teamocil has (it doesn't set env vars at all in --here)
2. Shell replacement: replace send_keys(window_shell) with respawn-pane
# Before (lines 724-727): send_keys to type shell command
_here_pane.send_keys(window_shell, enter=True)

# After: use respawn-pane to restart pane with new shell
if window_shell:
    _here_pane = window.active_pane
    if _here_pane is not None:
        _here_pane.cmd("respawn-pane", "-k", window_shell)

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.

3. Directory: keep send_keys("cd ...") (same as teamocil)
# Keep as-is (lines 695-701) — matches teamocil
active_pane.send_keys(f"cd {shlex.quote(start_directory)}", enter=True)

teamocil uses the same approach: send_keys cd "/path" for the reused window's first pane.

Result
Category Before After
cd send_keys send_keys (same as teamocil)
Environment send_keys export (N calls) session.set_environment() (tmux primitive)
Shell replacement send_keys (types into pane) respawn-pane -k (tmux primitive)

send_keys surface reduced from 3 categories to 1, matching teamocil exactly.

Risk assessment
  • Low risk: session.set_environment() is already used in the same file
  • Low risk: respawn-pane is a stable tmux command (available since 1.6)
  • Caveat: env vars only visible to new shells, not the existing one — acceptable trade-off
  • Remaining: send_keys cd still assumes a shell prompt (same as teamocil)
Tests to add/update
  • Update test_here_mode_provisions_environment to verify session.show_environment() instead of pane output
  • Add test for window_shell via respawn-pane
  • Keep existing test_here_mode_start_directory_special_chars (still uses send_keys cd)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/tmuxp/workspace/builder.py around lines 678-727 and read the existing session environment setup around lines 557-559. Review test_here_mode_provisions_environment and test_here_mode_start_directory_special_chars, then add coverage for window_shell respawn behavior. Done means here mode uses the stated tmux primitives while preserving directory handling and the existing tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.