AntonGepting / tmux-interface-rs

Rust language library for communication with TMUX via CLI
MIT License
52 stars 6 forks source link

SplitWindow with shell_command does not work #15

Closed Ganneff closed 1 year ago

Ganneff commented 1 year ago

Hi,

as soon as I want to use SplitWindow and give it a shell_command - it does not do anything useful. Without shell_command it opens my default shell, so split_window itself works. Maybe I do something else wrong, don't know?

Testcode below. My default shell being zsh, so using shell_command bin/bash is a nice test for a simple command. NewSession works fine, with or without shell_command set (either gets me zsh or bash). But the SplitWindow ONLY ever works when I keep the shell_command commented, as soon as I uncomment, I end up with a session of ONLY t1.

Output also does not indicate any error and exit code of tmux call is 0.

use tmux_interface::{NewSession, SelectLayout, SplitWindow, Tmux};

fn main() {
    let sesname = String::from("Testsession");
    let targets = vec![
        String::from("t1"),
        String::from("t2"),
        String::from("t3"),
        String::from("t4"),
        String::from("t5"),
        String::from("t6"),
        String::from("t7"),
        String::from("t8"),
    ];

    let output = Tmux::with_command(
        NewSession::new()
            .detached()
            .session_name(&sesname)
            .window_name(&targets[0])
            .shell_command(String::from("/bin/bash")),
    )
    .output()
    .unwrap();
    println!("Output: {:#?}", output);

    let mut others = targets.clone().into_iter();
    others.next();
    for _target in others {
        let output = Tmux::with_command(
            SplitWindow::new()
                .size(&tmux_interface::commands::PaneSize::Percentage(1))
                .detached()
                .print()
                .target_window(&sesname), //.shell_command(String::from("/bin/bash")),
        )
        .output()
        .unwrap();
        println!("Output: {:#?}", output);
        // Depending on available size with tmux, this avoids "no space for pane" messages
        let _ = Tmux::with_command(
            SelectLayout::new()
                .target_pane(String::from("Testsession:1"))
                .layout_name("main-horizontal"),
        )
        .output()
        .unwrap();
    }
}
AntonGepting commented 1 year ago

Hello and thank you very much for your report!

it was a bug with the wrong order of parameters due to inattention given to tmux by builder function.

If you need this fix right now, you can choose to:

AntonGepting commented 1 year ago

thx,

merged in main, released v0.3.1, closed as solved.

Please feel free to reopen or create a new issue if you have other problems or suggestions.