-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathasciinema-gh
executable file
·47 lines (38 loc) · 1.5 KB
/
asciinema-gh
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
#!/usr/bin/env bash
# Dependencies
# * [gh](https://github.com/cli/cli)
# * [jq](https://stedolan.github.io/jq)
#
# Example Usages:
# * `asciinema-gh zechris/asciinema-rec_script`
# * `asciinema-gh spectreconsole/spectre.console docs/input/assets/casts`
# * `echo 26 | screencast_dir=docs/input/assets/casts asciinema-gh spectreconsole/spectre.console`
set -eou pipefail
ASCIINEMA_PLAY_OPTS=${ASCIINEMA_PLAY_OPTS:---idle-time=0.1}
SCREENCAST_EXT=${SCREENCAST_EXT:-.cast}
repo() {
repo_name=${repo_name:-$(basename "$(pwd)")}
org_name=${org_name:-$(basename "$(cd ..; pwd)")}
echo "${org_name}/${repo_name}"
}
repo=${repo:-${1:-$(repo)}}
screencast_dir=${screencast_dir:-${2:-screencasts}}
PS3='Enter screencast number: '
>&2 echo "Searching for screencasts (*${SCREENCAST_EXT} files) in https://github.com/${repo}/tree/${REF:-master}/${screencast_dir} ..."
gh_cmd="gh api repos/${repo}/contents/${screencast_dir}"
[[ -n ${REF:-} ]] && gh_cmd="${gh_cmd}?ref=${REF}"
json=$(
>&2 echo "[1m${gh_cmd}[0m"
if ! eval "$gh_cmd"; then
>&2 echo "ERROR: No screencasts found"
exit 1
fi
)
# echo "$json" | jq ".[] | select(.name | endswith(\"${SCREENCAST_EXT}\"))" | cols="name size" resource=screencast json2table
select name in $(echo $json | jq --raw-output ".[] | select(.name | endswith(\"${SCREENCAST_EXT}\")) | .name"); do
download_url=$(
echo $json |
jq --raw-output --arg name $name '.[] | select(.name == $name) | .download_url'
)
asciinema play $ASCIINEMA_PLAY_OPTS $download_url
done