我是 tmux 的新手,想对其进行配置,以便在我运行时tmux,我的自定义窗口/窗格可以立即访问。
例如,这是一个基本的 ~/.tmux.conf:
new -s main -n workspace
neww
当我运行 tmux 时,我陷入了一个普通的旧会话。当我执行 alist-sessions时,我可以看到 conf 文件中指定的工作区会话,但为了使用它,我必须切换到它。
当我打开 tmux 时,我怎样才能继续让“工作区”会话成为我被倾倒的会话,这样我就不必每次都切换到它?
我是 tmux 的新手,想对其进行配置,以便在我运行时tmux,我的自定义窗口/窗格可以立即访问。
例如,这是一个基本的 ~/.tmux.conf:
new -s main -n workspace
neww
当我运行 tmux 时,我陷入了一个普通的旧会话。当我执行 alist-sessions时,我可以看到 conf 文件中指定的工作区会话,但为了使用它,我必须切换到它。
当我打开 tmux 时,我怎样才能继续让“工作区”会话成为我被倾倒的会话,这样我就不必每次都切换到它?
不确定我是否理解这个问题,但我使用tmuxinator快速启动预先填充有窗口、窗格和进程的会话。
您可以通过运行tmux attach而不是仅tmux.
如果您的配置中有多个会话设置,您可以使用会话名称目标标志选择您登陆的一个,例如:tmux attach -t <session_name>.
我已经创建了这个脚本。它不需要 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
您在.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
使用我的脚本。初始化多路复用器。您可以使用简单的 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
- ''