【问题标题】:tmux: How to automatically open sessions, windows, and panestmux:如何自动打开会话、窗口和窗格
【发布时间】:2013-11-03 16:58:22
【问题描述】:

我是 tmux 的新手,想对其进行配置,以便当我运行 tmux 时,我的自定义窗口/窗格可以立即访问。

例如,这是一个基本的 ~/.tmux.conf:

new -s main -n workspace
neww

当我运行 tmux 时,我被转储到一个普通的旧会话中。当我执行list-sessions 时,我可以看到 conf 文件中指定的工作区会话,但为了使用它,我必须切换到它。

我怎样才能继续,让“工作区”会话成为我打开 tmux 时进入的会话,这样我就不必每次都切换到它?

【问题讨论】:

  • 我看到了;但是,它没有回答我的问题,因为要激活您的会话,我必须将它绑定到一个键。我希望我的自动打开并让我进入我的自定义会话。
  • 这个approach?怎么样

标签: tmux


【解决方案1】:

您在.tmux.conf 文件中创建了一个会话,但您从未附加到它。当你运行时

tmux

没有指定命令,因此默认运行new-session 并附加到生成的会话。

将您的 .tmux.conf 文件限制为各种设置,并将会话创建和管理保留到单独的脚本中会更简洁一些。

#!/bin/bash

tmux new -s main -n workspace
tmux neww  # Creates a 2nd window, in addition to the new session's first window
tmux attach -t main

【讨论】:

  • 我喜欢这个,但这是最佳实践吗?我之所以问,是因为 this comment 在一个相关问题上表达了不同的意见。
  • 实际上,如果我就像你说的那样,在我启动 tmux ala tmux attach-session main 时附加到会话,那么一切正常。我可以在我的 .bash_profile 中添加一个别名,以将其缩短为别名。
  • tmux a 将启动并附加到默认会话,即在您的.tmux.conf@doremi 中指定的会话
【解决方案2】:

不确定我是否理解了这个问题,但我使用 tmuxinator 快速启动预先填充了窗口、窗格和进程的会话。

【讨论】:

    【解决方案3】:

    您可以通过运行 tmux attach 而不仅仅是 tmux 来附加到上次使用的会话(如果适用,这将是您创建的 conf 文件)。

    如果您的配置中有多个会话设置,您可以使用会话名称目标标志来选择您登陆的一个,例如:tmux attach -t <session_name>

    【讨论】:

      【解决方案4】:

      我创建了this script。它不需要 tmuxinator、ruby 或其他。它只是一个 bash 脚本,可配置:

      名为 config 的文件应包含如下内容:

      combo=()
      combo+=('logs' 'cd /var/log; clear; pwd')
      combo+=('home' 'cd ~; clear; pwd')
      

      bash 代码应该是:

      #!/bin/bash
      
      if [ -r config ]; then
          echo ""
          echo "Loading custom file"
          . config
      else
          . config.dist
      fi
      
      tmux start-server
      
      window=0
      windownumber=-1
      
      for i in "${combo[@]}"; do
      
          if [ $((window%2)) == 0 ]; then
              name=${i}
              ((windownumber++))
          else
              command=${i}
          fi
      
          if [ ${combo[0]} == "${i}" ]; then
              tmux new-session -d -s StarTmux -n "${name}"
          else
              if [ $((window%2)) == 0 ]; then
                  tmux new-window -tStarTmux:$windownumber -n "${name}"
              fi
          fi
      
          if [ $((window%2)) == 1 ]; then
              tmux send-keys -tStarTmux:$windownumber "${command}" C-m
          fi
      
          ((window++))
      done
      
      tmux select-window -tStarTmux:0
      tmux attach-session -d -tStarTmux
      

      【讨论】:

      • 您好 sensario,虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。请看这里:Why and how are some answers deleted?
      【解决方案5】:

      使用我的脚本。 IniTmux。您可以使用简单的 YAML 文件轻松描述会话、窗口和窗格。

      ---
      name: AK-Math 
      root: /i/project/LibAK/feature/Math
      windows:
      - Matrix  : feature
      - Vector  : feature
      - Number  : feature
      - Complex : feature
      - Real    : feature
      - Integer : feature
      - Bool    : feature
      
      - Math:
          layout : tiled
          dir    : branch
          panes  :
          - 'ranger'
          - ''
      
      models:
          feature:
              layout: "40fd,113x31,0,0[113x22,0,0{22x22,0,0,0,90x22,23,0,1},113x9,0,23,2]"
              dir: <WName>
              panes:
              - loop "tree obj" 0.5
              - vim -c VWSLoadWorkSpace
              - ''
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-17
        • 1970-01-01
        • 2018-06-08
        • 2012-03-24
        • 1970-01-01
        相关资源
        最近更新 更多