【问题标题】:Using a bash script to launch screen, then split and resize a screen使用 bash 脚本启动屏幕,然后拆分和调整屏幕大小
【发布时间】:2014-02-05 22:07:08
【问题描述】:

我正在尝试构建一个 bash 脚本来启动屏幕会话、拆分屏幕然后调整其中一个屏幕的大小。下面是我从终端手动运行的。

$screen
$ cd /some/directory

Controla then ShiftS //将屏幕一分为二

Controlatab //导航到“新”屏幕

Controlc //创建另一个终端

Controla :resize -15 //调整屏幕大小

$cd /another/dictionary

Controlatab //导航到第一个屏幕

$clear

我已经编写了一些 bash 脚本,但没有使用击键。我一直在尝试在 bash 脚本中找到要发送 controla 的内容,但我不确定是否可以,或者在启动屏幕后是否可以与之交互屏幕那样。我还没有在我的谷歌搜索中找到任何东西。非常感谢任何帮助或指导。

【问题讨论】:

  • 恕我直言,它不可能交互式脚本屏幕。你看过 tmux 吗? -> tmux scripting

标签: bash scripting terminal


【解决方案1】:

使用expect

#!/usr/bin/expect -f
set prompt {\$ }   ;# this is a regular expression to match your shell prompt
set dir1 /tmp
set dir2 /var/log

spawn screen
expect -re $prompt
send -- "\001S"
expect -re $prompt
send -- "cd $dir1\r"
expect -re $prompt
send -- "\001\t"
send -- "\001c"
expect -re $prompt
send -- "\001:resize -15\r"
send -- "cd $dir2\r"
expect -re $prompt
send -- "\001\t"
send -- "clear\r"

interact

【讨论】:

    【解决方案2】:

    我知道这是旧的,但我也需要这个,但找不到答案。我终于这样解决了:

    • 制作一个配置文件,比如.splitscreenrc

      chdir /etc
      screen 0
      stuff "ls -1\n"
      split
      focus down
      resize 3
      chdir /tmp
      screen 1
      stuff "ls\n"
      focus up
      
    • 运行screen -c .splitscreenrc

    希望这对某人有所帮助;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多