【问题标题】:How to create tmux window without attaching to the session?如何在不附加到会话的情况下创建 tmux 窗口?
【发布时间】:2021-04-17 06:44:48
【问题描述】:

我希望能够在名为“scratch”的会话中创建一个新的 tmux 窗口(选项卡),运行自定义命令(即“ping www.google.com”)而不附加到会话。如果“scratch”不存在,我也想创建它。

如何编写 shell 脚本?

【问题讨论】:

    标签: tmux


    【解决方案1】:

    another of my answers进行了抄袭和改动,下面是一个例子:

    TMUX_SESSION_NAME='scratch'
    tmux new-session -d -s $TMUX_SESSION_NAME >/dev/null
    tmux new-window -t $TMUX_SESSION_NAME
    tmux send-keys -t $TMUX_SESSION_NAME:1.0 'ping www.google.com' Enter
    

    更多信息(我的配置):

    这是我用来启动 tmux 会话的内容。该函数的参数将是您要创建的会话的名称。

    如果这不能回答您的问题,请评论并编辑您的问题,让我更清楚。

    tmuxstart() {
        tmux new-session -d -s $1 >/dev/null
        tmux rename-window -t $1:0 'main'
        tmux splitw -v -p 10 -t $1:0.0
        tmux splitw -h -p 80 -t $1:0.1
        #required; otherwise pane numbering is bs
        tmux select-pane -t $1:0.0
        tmux splitw -h -p 5 -t $1:0.0
        tmux send-keys -t $1:0.2 'sudo htop' Enter
        tmux send-keys -t $1:0.1 'tmux clock -t $1:0.1' Enter
        tmux select-pane -t $1:0.0
        tmux new-window -t $1
        tmux rename-window -t $1:1 'second'
        tmux splitw -v -p 10 -t $1:1.0
        tmux splitw -h -p 80 -t $1:1.1
        tmux select-pane -t $1:1.0
        tmux splitw -h -p 5 -t $1:1.0
        tmux clock -t $1:1.1
        tmux new-window -t $1
        tmux rename-window -t $1:2 'scratch'
        tmux splitw -v -p 10 -t $1:2.0
        tmux select-pane -t $1:2.0
        tmux splitw -h -p 5 -t $1:2.0
        tmux clock -t $1:2.1
        tmux select-window -t $1:0.0
        tmux a -t $1
    }
    

    【讨论】:

      猜你喜欢
      • 2014-07-28
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      • 2015-03-19
      • 2017-11-26
      • 2020-01-24
      • 2012-05-01
      • 2013-01-25
      相关资源
      最近更新 更多