使用 Command & 启动 Tmux指定配置文件 [英] Start Tmux with Command & Specify Configuration File

查看:39
本文介绍了使用 Command & 启动 Tmux指定配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写交互式的小脚本.我正在尝试启动 tmux,同时指定命令(以便在进程退出时退出 tmux 会话)并使用配置文件 - 但似乎这不可能.

I'm working on small script that is interactive. I'm trying to start tmux both specifying the command (so that when the process exits the tmux session exits) and using a configuration file - but it doesn't appear that this is possible.

tmux new-session -d -s myapp 'python myapp.py' -f 'myapp-tmux.conf'

有什么想法吗?

推荐答案

您需要将 -f ... 移到 new-session 之前.它是 tmux 本身的一个论据;new-session(子)命令不理解或接受 -f.

You need to move the -f … to before new-session. It is an argument for tmux itself; the new-session (sub)command does not understand or accept -f.

此外,配置文件(~/.tmux.conf,或用 -f 指定的文件)仅在最初启动服务器时使用.如果您在默认服务器下运行其他(可能分离的)会话,则命令的 -f ... 部分将不使用.使用 tmux ls 检查其他会话.

Also, the configuration file (~/.tmux.conf, or the one specified with -f) is only used when initially starting a server. If you have other (possibly detached) sessions running under the default server, then the -f … portion of your command will go unused. Check for other sessions with tmux ls.

您可能想要使用 -L(或 -S)来指定备用服务器(即,您可以确保您的会话始终是唯一的):

You might want to use -L (or -S) to specify an alternate server (i.e. one where you can make sure your session is always the only one):

tmux -L myapp -f myapp-tmux.conf new-session -d -s myapp 'python myapp.py' 

稍后,附加到该会话:

tmux -L myapp attach -t myapp

(如果服务器只有一个会话,您可以省略 -t myapp.)

(You may leave off -t myapp if the sever only has that one session.)

如果您确实想使用现有服务器(以便通过配置文件所做的更改可以影响您的其他会话),那么您可能需要使用 source 代替:

If you do want to use you existing server (so that changes made via the configuration file can affect your other sessions), then you might want to use source instead:

tmux source myapp-tmux.conf \; new-session -d -s myapp 'python myapp.py'

这篇关于使用 Command & 启动 Tmux指定配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆