-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcast-terminal
executable file
·78 lines (66 loc) · 1.87 KB
/
cast-terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
#
# wrapper arround asciinema and asciinema-player
#
# This let you maintain a directory/repository with a bunch of *.cast files
# and easily synchronize them somewhere to be served as static html
#
# cast-terminal build
# create a html and resources from *.cast in the current directory
set -e
PLAYER_VERSION="v2.6.1"
DESTDIR=${DESTDIR:-.}
cmd_build() {
mkdir -p ${DESTDIR}/res
[ ! -f ${DESTDIR}/res/asciinema-player.css ] && \
curl -L https://github.com/asciinema/asciinema-player/releases/download/${PLAYER_VERSION}/asciinema-player.css > ${DESTDIR}/res/asciinema-player.css
[ ! -f ${DESTDIR}/res/asciinema-player.js ] && \
curl -L https://github.com/asciinema/asciinema-player/releases/download/${PLAYER_VERSION}/asciinema-player.js > ${DESTDIR}/res/asciinema-player.js
for f in *.cast; do
html=${f//.cast/.html}
cat - <<EOF > ${DESTDIR}/$html
<html>
<head>
<link rel="stylesheet" type="text/css" href="res/asciinema-player.css" />
</head>
<style>
.links {
text-align: center;
}
</style>
<body>
<script src="res/asciinema-player.js"></script>
<asciinema-player src="$f" speed="2" idle-time-limit="1"></asciinema-player>
<div class="links">Replay in your terminal with "asciinema play": <a href="$f">$f</a></div>
</body>
</html>
EOF
done
[ $DESTDIR != "." ] && cp *.cast ${DESTDIR}/
}
cmd_record() {
asciinema rec -i 2 "$1"
}
cmd_play() {
asciinema play -s 2 -i 1 "$1"
}
cmd_upload() {
cmd_build
rsync -avz --ignore-times ${DESTDIR}/ $1
}
cmd_help() {
echo "Available commands:"
declare -F | grep -o " cmd_[a-zA-Z_]*" | sed 's/^ cmd_/\t/;s/_/-/g'
}
if [ $# -lt 1 ]; then
cmd_help
exit 0
fi
cmd=cmd_${1//-/_}
shift
if [ -z "$cmd" ] || ! declare -f $cmd >/dev/null; then
echo "Unkonwn commands. Available commands:" > /dev/stderr
cmd_help > /dev/stderr
exit 1
fi
$cmd "$@"