tmux-python/tmuxp

Dynamically drop some windows - plugin

xeor opened this issue · 1 comments

xeor commented

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
tony commented

@joseph-flinn This may be of interest to you! (Plugin related)