从 .screenrc 在 GNU Screen 窗口中运行命令

发布于 2024-12-07 00:34:53 字数 532 浏览 0 评论 0原文

有没有办法从我的 .screenrc 向 GNU Screen 窗口发送一系列命令?看起来这应该很容易做到:

.screenrc:

startup_message off
screen -t "RAILS SERVER"
<send command to last created window> <my alias to cd Rails project>
<send command to last created window> rails s
screen -t "RAILS CONSOLE"
<send command to last created window> <my alias to cd to Rails project>
rails c

我已经多次浏览了 Screen 手册页,但找不到任何可以

谢谢, 最大限度

Is there a way to send a sequence of commands to GNU Screen windows from my .screenrc? It seems like this should be easy to do:

.screenrc:

startup_message off
screen -t "RAILS SERVER"
<send command to last created window> <my alias to cd Rails project>
<send command to last created window> rails s
screen -t "RAILS CONSOLE"
<send command to last created window> <my alias to cd to Rails project>
rails c

I've gone over the Screen man-page several times, but can't find anything that will <send command to last created window>.

Thanks,
Max

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

中二柚 2024-12-14 00:34:53

Keith 的答案完成了工作,但它将窗口与该进程绑定在一起,以便应用程序执行完毕后,窗口就会关闭。

这就是我最终所做的,效果非常好:

screen -t "RAILS SERVER"
stuff "cd $my_rails_directory; rails server^M"

screen -t "RAILS CONSOLE"
stuff "cd $my_rails_directory; rails console^M"

这里要注意的重要部分是 ^M 字符。这实际上不是一个 ^ 后跟一个 M。这是一个原始的换行符。在几乎所有 CLI 程序(vi、emacs、shell)中,您可以按 CTRL-V,然后按 ENTER 来生成此字符。

这是如何运作的? stuff 命令将给定的字符串直接键入控制台。最后的换行文字实际上按照您自己键入的通常方式发送命令。希望有帮助!我发现这种方法比其他方法更加稳定和可靠。

Keith's answer gets the job done but it ties the window to that process so that as soon as the application is done executing, the window closes.

Here's what I wound up doing that worked perfectly:

screen -t "RAILS SERVER"
stuff "cd $my_rails_directory; rails server^M"

screen -t "RAILS CONSOLE"
stuff "cd $my_rails_directory; rails console^M"

The important part to note here is the ^M character. This isn't actually a ^ followed by an M. This is a raw newline character. In almost any CLI program (vi, emacs, shell), you can press CTRL-V and then press ENTER to generate this character.

How does this work? The stuff command types the given string directly into the console. The newline literal at the end actually sends the command off the way you normally would if you typed it yourself. Hope that helps! I've found this approach to be far more stable and reliable than others.

鹤仙姿 2024-12-14 00:34:53

它不是一个单独的命令;您只需指定要在创建窗口的行上运行的命令。

例如(未经测试):

screen -t "RAILS SERVER" sh -c "cd ... ; rails s"

It's not a separate command; you just specify the command to run on the line that creates the window.

For example (untested):

screen -t "RAILS SERVER" sh -c "cd ... ; rails s"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文