使用 bash 脚本设置 tmux windows
Use bash script to setup tmux windows
我正在尝试编写一个脚本来为 rails 开发设置 tmux windows,到目前为止我有这个:
#!/bin/bash
tmux new-window -n vim
tmux new-window -n guard
tmux new-window -n console/server
tmux select-window -t 3
tmux send-keys -t 3 'rails server' C-z
我想要的,在那个特定的window上,是运行rails server
然后发送到后台。问题是,我得到的只是 ^Z
和几秒钟后的通常提示。
我怎样才能做到这一点?
我认为你可以很好地利用 IniTmux。这是我创建的 python 脚本。
您可以组合这些 tmux 命令,以便它们都被同一个会话接收。用 \;
分隔(转义以一直到 tmux):
#!/bin/bash
tmux new -stest \; \
new-window -n vim \; \
new-window -n guard \; \
new-window -n console/server
select-window -t 3 \; \
send-keys -t 3 'rails s &' Enter
我没有看到 C-z
工作,但你可以通过 &
后台实现同样的效果。
您需要定义一个会话来附加所有内容。例如:
tmux new-session -s c64 -n vim -d
tmux new-window -t c64 -d -n guard
tmux new-window -t c64 -d -n console
tmux send-keys -t c64:console 'rails server &' Enter
tmux select-window -t c64:console
tmux attach -t c64
与 3 windows 创建一个名为 c64
的会话。然后它将命令发送到第 3 个 window,使其成为当前 window 并附加到会话。
我正在尝试编写一个脚本来为 rails 开发设置 tmux windows,到目前为止我有这个:
#!/bin/bash
tmux new-window -n vim
tmux new-window -n guard
tmux new-window -n console/server
tmux select-window -t 3
tmux send-keys -t 3 'rails server' C-z
我想要的,在那个特定的window上,是运行rails server
然后发送到后台。问题是,我得到的只是 ^Z
和几秒钟后的通常提示。
我怎样才能做到这一点?
我认为你可以很好地利用 IniTmux。这是我创建的 python 脚本。
您可以组合这些 tmux 命令,以便它们都被同一个会话接收。用 \;
分隔(转义以一直到 tmux):
#!/bin/bash
tmux new -stest \; \
new-window -n vim \; \
new-window -n guard \; \
new-window -n console/server
select-window -t 3 \; \
send-keys -t 3 'rails s &' Enter
我没有看到 C-z
工作,但你可以通过 &
后台实现同样的效果。
您需要定义一个会话来附加所有内容。例如:
tmux new-session -s c64 -n vim -d
tmux new-window -t c64 -d -n guard
tmux new-window -t c64 -d -n console
tmux send-keys -t c64:console 'rails server &' Enter
tmux select-window -t c64:console
tmux attach -t c64
与 3 windows 创建一个名为 c64
的会话。然后它将命令发送到第 3 个 window,使其成为当前 window 并附加到会话。