Bash 带有拆分终端的脚本 window:一侧用于 progress/prompts,另一侧用于详细输出

Bash script with a split terminal window: one side for progress/prompts, other side for verbose output

是否可以让 bash 脚本在一点水平拆分终端 window,以便左侧详细说明任务的总体进度,右侧包含来自的详细输出当前任务是 运行?

我发现有些人在拆分终端 window 的上下文中引用 nohupscreen,但我不知道如何在 bash 脚本意义,或者它是否符合我的需要。

目前,我有很多长输出的长任务,所以我将每个任务的输出发送到累积日志文件,而不是转储到屏幕上。然后,作为过渡,手动打开一个新终端 window 以使用 watch tail LogFile* 来关注正在发生的事情。

如果我能使该过程自动化,那就太好了。

更新

一些线索。

This post 及其评论非常有帮助,确定您可以在一个 window 中启动命令并根据其 pts[=41 将其输出发送到另一个=]值。

例如,ls > /dev/pts/7 将在 window 的终端 window 中显示 ls 的输出。

仍然对如何以编程方式自动分割屏幕并使用它而不是新的window感到困惑。

我得到了一个与 Terminator 一起工作的示例。

在新的终结者中启动下面的 bash 脚本 window:

terminator --command="bash /path/to/script"

一旦我们进入 运行,这有点像 hack 解决方案,但要在 bash 脚本中按 command-line 分割屏幕,我最终使用了xdotool 将键绑定发送到终结者。像这样:

#!/bin/bash

    # send keybinding that splits screen vertically
    xdotool key Ctrl+Shift+E
    # Terminator now sets focus to the right side (the new split) by default, so send keybinding that returns the focus to our left side
    # sleep a tiny little bit first
    sleep 0.01
    xdotool key Alt+Left

    # now to send output to the right side, let's work out "where" the ride side is
        # use who to find the pts ids of all currently spanwed terminal windows
        # use tail to find the last line from who (which we assume is the terminal window we just split)
        # then grep to find just the number after pts/
        ## windowID=$(who | tail -n1 | grep -oP 'pts/\K[0-9]*')
        # updated this to fix bug where who does not return pts values
        # https://askubuntu.com/questions/1110203
        windowID=$(ps -u $USER -o tty | awk 'NR>1 &&  != "?" {a[[=10=]]++};END{for(val in a) print val}' | tail -n1 | grep -oP 'pts/\K[0-9]*')

    # now we can send output from commands to the right side split window by using its pseudo device id. for example:
    ls -lah >> /dev/pts/$windowID

exit