0

I am trying to setup my environment so that all opened terminal sessions are automatically recorded by asciinema, to be able to easily replay anything from my history.

I use zsh shell and I run this in .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

However the problem is when I close the terminal window (using X). The output is not properly closed and ends up being empty. Also the initialization takes longer now since it is initializing zsh shell two times.

TrueFurby
  • 457
  • 4
  • 19
  • This is just a short update because it's not official yet: asciinema will have a new fileformat and does save in realtime instead at the end of the session. https://github.com/asciinema/asciinema/pull/236 – SeriousM Nov 02 '17 at 23:54

1 Answers1

1

I would try to trap SIGHUP and EXIT so that you can process a cleanup command when your terminal is closed.

trap 'command' SIGHUP EXIT

So, in your case, probably making sure that you close the pseudo-terminal ran by asciinema correctly.

Maybe:

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

Reference: Which signals are sent when closing a terminal

Community
  • 1
  • 1
jraynal
  • 507
  • 3
  • 10