Categories
DailyOps

How to record terminal session in a tmux friendly way

Record terminal session in a tmux friendly way.

Use script from bsdutils package to record terminal using session name-pane name-date naming scheme.

#!/bin/bash
# https://sleeplessbeastie.eu/2021/07/26/how-to-record-terminal-session-in-a-tmux-friendly-way/

typescript_directory="${HOME}/.typescript"
typescript_log_type="io" # "io" (in/out) or "out" (only out)
typescript_name="$(tmux display-message -p '#S-#P')-$(date +%Y%m%d_%H%M)"

if [ ! -d "$typescript_directory" ]; then
  mkdir $typescript_directory
fi 

script --append \
       --log-timing \
         "${typescript_directory}/${typescript_name}.timing" \
       --log-${typescript_log_type} \
         "${typescript_directory}/${typescript_name}.${typescript_log_type}" \
       --logging-format advanced 

Execute terminal recording.

$ record           
Script started, output log file is '/home/milosz/.typescript/milosz-1-20210718_2344.io', input log file is '/home/milosz/.typescript/milosz-1-20210718_2344.io', timing file is '/home/milosz/.typescript/milosz-1-20210718_2344.timing'.

$ ....

^D
Script done.

Inspect created files.

❯ ls ~/.typescript/  
milosz-1-20210718_2344.io  milosz-1-20210718_2344.timing

Replay terminal recording.

$ scriptreplay --log-timing ~/.typescript/milosz-1-20210718_2344.timing --log-io ~/.typescript/milosz-1-20210718_2344.io 

This simple shell script is very useful at times when I need need to record a particular operation inside terminal.