2017-12-02 18:39:25 +01:00
|
|
|
#!/usr/bin/env bash
|
2016-06-07 21:02:11 +02:00
|
|
|
|
2021-10-30 13:02:21 -04:00
|
|
|
set -eExuo pipefail
|
2016-06-07 21:02:11 +02:00
|
|
|
|
2021-10-29 23:04:09 -04:00
|
|
|
if ! command -v "pkill" >/dev/null 2>&1; then
|
|
|
|
|
printf "error: pkill not installed\n"
|
2017-12-02 18:39:25 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2017-12-02 19:07:12 +01:00
|
|
|
python3 -V
|
|
|
|
|
|
2021-10-29 23:04:09 -04:00
|
|
|
ASCIINEMA_CONFIG_HOME="$(
|
|
|
|
|
mktemp -d 2>/dev/null || mktemp -d -t asciinema-config-home
|
|
|
|
|
)"
|
2016-07-11 20:20:51 +02:00
|
|
|
|
2021-10-29 23:04:09 -04:00
|
|
|
export ASCIINEMA_CONFIG_HOME
|
|
|
|
|
|
|
|
|
|
TMP_DATA_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t asciinema-data-dir)"
|
|
|
|
|
|
|
|
|
|
trap 'rm -rf ${ASCIINEMA_CONFIG_HOME} ${TMP_DATA_DIR}' EXIT
|
|
|
|
|
|
|
|
|
|
asciinema() {
|
|
|
|
|
python3 -m asciinema "${@}"
|
2016-07-11 20:33:56 +02:00
|
|
|
}
|
2016-07-05 16:52:08 +02:00
|
|
|
|
2023-04-26 16:00:18 +02:00
|
|
|
## disable notifications
|
|
|
|
|
|
|
|
|
|
printf "[notifications]\nenabled = no\n" >> "${ASCIINEMA_CONFIG_HOME}/config"
|
|
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
## test help message
|
2017-10-27 10:38:04 +02:00
|
|
|
|
2016-07-11 20:33:56 +02:00
|
|
|
asciinema -h
|
2016-07-05 16:52:08 +02:00
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
## test version command
|
2017-10-27 10:38:04 +02:00
|
|
|
|
2016-07-11 20:33:56 +02:00
|
|
|
asciinema --version
|
2016-07-05 16:52:08 +02:00
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
## test auth command
|
2017-10-27 10:38:04 +02:00
|
|
|
|
2016-07-11 20:33:56 +02:00
|
|
|
asciinema auth
|
2016-07-05 16:52:08 +02:00
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
## test play command
|
2017-10-27 10:38:04 +02:00
|
|
|
|
|
|
|
|
# asciicast v1
|
|
|
|
|
asciinema play -s 5 tests/demo.json
|
|
|
|
|
asciinema play -s 5 -i 0.2 tests/demo.json
|
2021-10-29 23:04:09 -04:00
|
|
|
# shellcheck disable=SC2002
|
2017-11-12 12:58:35 +01:00
|
|
|
cat tests/demo.json | asciinema play -s 5 -
|
2017-10-27 10:38:04 +02:00
|
|
|
|
|
|
|
|
# asciicast v2
|
|
|
|
|
asciinema play -s 5 tests/demo.cast
|
|
|
|
|
asciinema play -s 5 -i 0.2 tests/demo.cast
|
2021-10-29 23:04:09 -04:00
|
|
|
# shellcheck disable=SC2002
|
2017-11-12 12:58:35 +01:00
|
|
|
cat tests/demo.cast | asciinema play -s 5 -
|
2017-03-25 13:25:18 +01:00
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
## test cat command
|
2017-11-18 16:57:13 +01:00
|
|
|
|
|
|
|
|
# asciicast v1
|
|
|
|
|
asciinema cat tests/demo.json
|
2021-10-29 23:04:09 -04:00
|
|
|
# shellcheck disable=SC2002
|
2017-11-18 16:57:13 +01:00
|
|
|
cat tests/demo.json | asciinema cat -
|
|
|
|
|
|
|
|
|
|
# asciicast v2
|
|
|
|
|
asciinema cat tests/demo.cast
|
2021-10-29 23:04:09 -04:00
|
|
|
# shellcheck disable=SC2002
|
2017-11-18 16:57:13 +01:00
|
|
|
cat tests/demo.cast | asciinema cat -
|
|
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
## test rec command
|
2017-04-11 17:26:03 +02:00
|
|
|
|
2017-12-02 19:07:12 +01:00
|
|
|
# normal program
|
2021-10-29 23:04:09 -04:00
|
|
|
asciinema rec -c 'bash -c "echo t3st; sleep 2; echo ok"' "${TMP_DATA_DIR}/1a.cast"
|
|
|
|
|
grep '"o",' "${TMP_DATA_DIR}/1a.cast"
|
2017-12-02 19:07:12 +01:00
|
|
|
|
|
|
|
|
# very quickly exiting program
|
2022-05-07 16:26:21 +02:00
|
|
|
asciinema rec -c whoami "${TMP_DATA_DIR}/1b.cast"
|
2022-05-07 15:58:04 +02:00
|
|
|
grep '"o",' "${TMP_DATA_DIR}/1b.cast"
|
2016-07-05 16:52:08 +02:00
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
# signal handling
|
2016-07-11 20:33:56 +02:00
|
|
|
bash -c "sleep 1; pkill -28 -n -f 'm asciinema'" &
|
2021-10-29 23:04:09 -04:00
|
|
|
asciinema rec -c 'bash -c "echo t3st; sleep 2; echo ok"' "${TMP_DATA_DIR}/2.cast"
|
2016-07-05 16:52:08 +02:00
|
|
|
|
2016-07-11 20:33:56 +02:00
|
|
|
bash -c "sleep 1; pkill -n -f 'bash -c echo t3st'" &
|
2021-10-29 23:04:09 -04:00
|
|
|
asciinema rec -c 'bash -c "echo t3st; sleep 2; echo ok"' "${TMP_DATA_DIR}/3.cast"
|
2016-07-11 20:33:56 +02:00
|
|
|
|
|
|
|
|
bash -c "sleep 1; pkill -9 -n -f 'bash -c echo t3st'" &
|
2021-10-29 23:04:09 -04:00
|
|
|
asciinema rec -c 'bash -c "echo t3st; sleep 2; echo ok"' "${TMP_DATA_DIR}/4.cast"
|
2017-09-22 22:21:35 +02:00
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
# with stdin recording
|
2022-05-07 16:16:53 +02:00
|
|
|
echo "ls" | asciinema rec --stdin -c 'bash -c "sleep 1"' "${TMP_DATA_DIR}/5.cast"
|
|
|
|
|
cat "${TMP_DATA_DIR}/5.cast"
|
|
|
|
|
grep '"i", "ls\\n"' "${TMP_DATA_DIR}/5.cast"
|
|
|
|
|
grep '"o",' "${TMP_DATA_DIR}/5.cast"
|
2017-11-18 16:21:35 +01:00
|
|
|
|
2017-12-02 17:57:32 +01:00
|
|
|
# raw output recording
|
2021-10-29 23:04:09 -04:00
|
|
|
asciinema rec --raw -c 'bash -c "echo t3st; sleep 1; echo ok"' "${TMP_DATA_DIR}/6.raw"
|
2017-12-02 17:57:32 +01:00
|
|
|
|
|
|
|
|
# appending to existing recording
|
2021-10-29 23:04:09 -04:00
|
|
|
asciinema rec -c 'echo allright!; sleep 0.1' "${TMP_DATA_DIR}/7.cast"
|
|
|
|
|
asciinema rec --append -c uptime "${TMP_DATA_DIR}/7.cast"
|
2023-04-26 16:00:18 +02:00
|
|
|
|
|
|
|
|
# adding a breakpoint
|
|
|
|
|
printf "[record]\nadd_breakpoint_key = C-b\n" >> "${ASCIINEMA_CONFIG_HOME}/config"
|
|
|
|
|
(sh -c "sleep 1; printf '.'; sleep 0.5; printf '\x08'; sleep 0.5; printf '\x02'; sleep 0.5; printf '\x04'") | asciinema rec -c /bin/sh "${TMP_DATA_DIR}/8.cast"
|
|
|
|
|
grep '"b",' "${TMP_DATA_DIR}/8.cast"
|