Here is a simple example to use this library.

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

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
documentation

Research direction

Start by reviewing the inline Python example, especially its libtmux window and pane commands, and compare it with the repository's existing documentation structure. The requested outcome is unclear: determine whether the project needs a documented libtmux example or guidance to use a bash script, then make the chosen example runnable and clear.

Written by the indexing model from the issue text.

Description

When I use the library to split window, I use win.cmd('split-window', '-h') which let me spend a lot of time.

At last, I suggest to use bash script instead of this library.

#!/usr/bin/env python3
# coding=utf-8
# author: thinkycx
# date: 2018-01-11
# Usage:
#    run several commands in tmux panel, every window have 4 panes
#    $ pip3 install libtmux
#    $ python tmux.py


import libtmux
import math
import os
import logging

def create_session(session_name, commands):
    '''
        create session with 2*2 panes and run commands
    :param session_name: tmux session name
    :param commands: bash commands
    :return:
    '''
    logging.info(commands)
    # pane_NUM = 3
    # WINDOW_NUM = int(math.ceil(len(commands)/4.0))  # in python3, we can use 4 also

    server = libtmux.Server()
    session = server.new_session(session_name)

    # create windows
    windows = []
    panes = []

    for i in range(len(commands)):
        # create window to store 4 panes
        if i % 4 == 0:
            win = session.new_window(attach=False, window_name="win"+str(int(i/4)))
            windows.append(win)

            # tmux_args = ('-h',)
            win.cmd('split-window', '-h')
            win.cmd('split-window', '-f')
            win.cmd('split-window', '-h')

            panes.extend(win.list_panes())

        panes[i].send_keys(commands[i])

    logging.info(panes)
    logging.info(windows)


if __name__ == '__main__':
    commands = []
    for i in range(10):
        commands.append("echo " + str(i))

    os.system("tmux kill-session -t session")
    create_session("session", commands)

image

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

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.

More from tmux-python/libtmux

All issues in tmux-python/libtmux

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.