Last active
April 4, 2023 05:59
-
-
Save hypnoJerk/781d9c33bd64d059bc467ed9e2e54fb2 to your computer and use it in GitHub Desktop.
Convert asciinema public share URL to iframe embed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://gist.github.com/hypnoJerk/781d9c33bd64d059bc467ed9e2e54fb2 | |
# | |
# Example usage: | |
# ./generate_iframe.sh https://asciinema.org/a/335480 -r 20 -c 90 -h 480px | |
# You may need to adjust the height, rows, or columns | |
# Extract the Asciicast ID from the URL | |
url=$1 | |
asciicast_id=$(echo "$url" | sed -n 's|.*\/a\/\([0-9]*\)\/.*|\1|p') | |
# Extract the optional arguments | |
shift | |
while getopts ":r:c:h:" opt; do | |
case ${opt} in | |
r ) rows="$OPTARG";; | |
c ) cols="$OPTARG";; | |
h ) height="$OPTARG";; | |
\? ) echo "Invalid option: -$OPTARG" 1>&2; exit 1;; | |
: ) echo "Option -$OPTARG requires an argument." 1>&2; exit 1;; | |
esac | |
done | |
# Set default values for rows, columns, and height | |
rows=${rows:-24} | |
cols=${cols:-80} | |
height=${height:-480px} | |
# Generate the iframe code | |
iframe="<iframe src=\"$url/iframe?size=normal&speed=1&autoplay=false&loop=false&theme=asciinema&t=0&startAt=0&preload=true&cols=$cols&rows=$rows&i=true&idleTimeLimit=2\" id=\"asciicast-iframe-$asciicast_id\" name=\"asciicast-iframe-$asciicast_id\" scrolling=\"no\" allowfullscreen=\"true\" style=\"overflow: hidden; margin: 0px; border: 0px; display: inline-block; width: 100%; float: none; visibility: visible; height: $height;\"></iframe>" | |
echo "$iframe" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment