【问题标题】:How to record all terminal sessions and properly exit after closed window如何记录所有终端会话并在关闭窗口后正确退出
【发布时间】:2017-03-11 09:17:21
【问题描述】:

我正在尝试设置我的环境,以便asciinema 自动记录所有打开的终端会话,以便能够轻松地重播我的历史记录。

我使用zsh shell,并在.zshrc 中运行它:

if [ "$ASCIINEMA_REC" != "1" ]; then
    local out="rec.json"
    local loc="$HOME/.asciinema"

    if [ -d "${loc}" ]; then
        out="${loc}`pwd`/rec_`date +'%Y-%b-%d_%H-%M-%S'`_pts-`basename $TTY`.json"
        mkdir -p "`dirname ${out}`"
    fi

    asciinema rec -q -w 1 ${out}; 
fi

但问题是当我关闭终端窗口时(使用 X)。输出未正确关闭并最终为空。此外,现在初始化需要更长的时间,因为它正在初始化 zsh shell 两次。

【问题讨论】:

标签: linux shell terminal zsh


【解决方案1】:

我会尝试 trap SIGHUPEXIT 以便您可以在终端关闭时处理清理命令。

trap 'command' SIGHUP EXIT

所以,在你的情况下,可能要确保你正确关闭了 asciinema 运行的伪终端。

也许:

trap 'exit 0;' SIGHUP EXIT # Should exit the current terminal session, hopefully the asciinema one!

参考:Which signals are sent when closing a terminal

【讨论】:

    猜你喜欢
    • 2019-11-11
    • 2018-11-26
    • 2011-07-30
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多