tmux-python / tmux-python/tmuxp

Dynamically drop some windows - plugin

Open
#799 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Step 1: Provide a summary of your problem

I am trying to create a plugin that

  • Gets a list of windows from existing running tmux
  • Compare that list with the one in the tmuxp yaml file I am trying to load
  • Only creates windows that are missing
Step 2: Provide tmuxp details
  • Include output of tmuxp debug-info
-------------------------         
environment:                          
        dist: macOS-12.5-arm64-arm-64bit
        arch: arm64                     
        uname: Darwin; fry.lan; 21.6.0   
        version: Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:22 PDT 2022; root:xnu-8020.140.41~1/RELEASE_ARM64_T6000
-------------------------                  
python version: 3.10.6 (main, Aug 11 2022, 13:36:31) [Clang 13.1.6 (clang-1316.0.21.2.5)]
tmux version: 3.3         
libtmux version: 0.14.2                                    
tmuxp version: 1.13.0
tmux path: /opt/homebrew/bin/tmux
shell: /bin/zsh    
  • Include any other pertinant system info not captured
Step 3: Describe the problem:

How can I drop some windows on the last step mentioned above? Using before_workspace_builder and modifying session.children doesnt seam to do the trick. How can I remove windows that will be created?

Steps to reproduce:
  1. create a simple plugin
from tmuxp.plugin import TmuxpPlugin

class PluginNoCreateExisting(TmuxpPlugin):
    def __init__(self):
        config = {'tmuxp_min_version': '1.6.2'}

        TmuxpPlugin.__init__(
            self,
            plugin_name='tmuxp-plugin-no-create-existing',
            **config
        )

    def before_workspace_builder(self, session):
        session.rename_session('my-new-session-name')

        for child in session.children:
            if child['window_name'] == 'a':
                print('keeping')
            else:
                session.children.remove(child)
  1. create a simple yaml to load
session_name: main
plugins:
- 'tmuxp_plugin_no_create_existing.plugin.PluginNoCreateExisting'

windows:
  - window_name: a
    layout: tiled
    shell_command_before:
      - cd ~/
    panes:
      - shell_command:
          - cd /var/log
          - ls -al | grep \.log

  - window_name: b
    layout: tiled
    shell_command_before:
      - cd ~/
    panes:
      - shell_command:
          - uptime

  - window_name: c
    layout: tiled
    shell_command_before:
      - cd ~/
    panes:
      - shell_command:
          - ls -l
  1. Load it, and load it again inside (tmuxp load -a main.yml), and see a, b and c are created.
Observed Results:
  • Windows I expected not to be created are created
Expected Results:
  • Only a is created

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 by reading the TmuxpPlugin entry point and the before_workspace_builder hook, then reproduce the behavior with the provided plugin, YAML, and tmuxp load -a main.yml command. Determine how workspace children are consumed after the hook; done means loading the configuration creates only window a while preserving the requested plugin behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.