diff --git a/README.md b/README.md index 5d24951..7f6cf9d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ | [fzf](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/fzf) | `fzf` — general-purpose command-line fuzzy finder | gh release | 1.0.0 | | [github.com-cli](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/github.com-cli) | `gh` — GitHub CLI | curl | 1.0.0 | | [helix-editor.com](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/helix-editor.com) | `hx` — modal text editor with built-in LSP | gh release | 1.0.0 | +| [icholy/ttygif](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/icholy-ttygif) | `ttygif` — convert ttyrec recordings to animated GIFs | gh release | 1.0.0 | | [jj-vcs.dev](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/jj-vcs.dev) | `jj` — Git-compatible distributed VCS | gh release | 1.0.1 | | [jnsahaj/lumen](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/jnsahaj-lumen) | `lumen` — AI-powered commit message generator | cargo | 1.0.0 | | [joelhooks-agent-secrets](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/joelhooks-agent-secrets) | `secrets` — manage secrets for AI agents | gh release | 1.0.0 | diff --git a/src/icholy-ttygif/NOTES.md b/src/icholy-ttygif/NOTES.md new file mode 100644 index 0000000..6c83439 --- /dev/null +++ b/src/icholy-ttygif/NOTES.md @@ -0,0 +1,17 @@ +# icholy/ttygif + +## Project + +- [icholy/ttygif](https://github.com/icholy/ttygif) + +## Description + +`ttygif` converts a ttyrec terminal recording file into animated GIF files. It captures every frame of a terminal session recorded with `ttyrec` and assembles them into a GIF using ImageMagick. + +## Installation Method + +Built from source using the [GitHub release tarball](https://github.com/icholy/ttygif/releases) and installed to `/usr/local/bin` via `make install`. Build dependencies (`gcc`, `make`) and runtime dependencies (`imagemagick`, `ttyrec`, `x11-apps`) are installed via APT. + +## Other Notes + +Because `ttygif` uses `xwd` to capture X11 window screenshots at runtime, it requires a running X server (or virtual framebuffer such as `Xvfb`) when actually recording GIFs. The binary can be installed in a headless container but will need an X11 environment to function fully. diff --git a/src/icholy-ttygif/devcontainer-feature.json b/src/icholy-ttygif/devcontainer-feature.json new file mode 100644 index 0000000..bd87270 --- /dev/null +++ b/src/icholy-ttygif/devcontainer-feature.json @@ -0,0 +1,17 @@ +{ + "name": "icholy/ttygif", + "id": "icholy-ttygif", + "version": "1.0.0", + "description": "Install \"ttygif\" binary", + "documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/icholy-ttygif", + "options": { + "version": { + "type": "string", + "default": "latest", + "proposals": [ + "latest" + ], + "description": "Version of \"ttygif\" to install." + } + } +} diff --git a/src/icholy-ttygif/install.sh b/src/icholy-ttygif/install.sh new file mode 100755 index 0000000..2378ff0 --- /dev/null +++ b/src/icholy-ttygif/install.sh @@ -0,0 +1,130 @@ +#!/bin/bash +set -o errexit +set -o pipefail +set -o noclobber +set -o nounset +set -o allexport +readonly githubRepository='icholy/ttygif' +readonly binaryName='ttygif' +readonly binaryTargetFolder='/usr/local/bin' +readonly name="${githubRepository##*/}" +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} +apt_get_checkinstall() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + apt_get_update + DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@" + fi +} +apt_get_cleanup() { + apt-get clean + rm -rf /var/lib/apt/lists/* +} +check_curl_tar_installed() { + declare -a requiredAptPackagesMissing=() + if ! [ -r '/etc/ssl/certs/ca-certificates.crt' ]; then + requiredAptPackagesMissing+=('ca-certificates') + fi + if ! command -v curl >/dev/null 2>&1; then + requiredAptPackagesMissing+=('curl') + fi + if ! command -v tar >/dev/null 2>&1; then + requiredAptPackagesMissing+=('tar') + fi + declare -i requiredAptPackagesMissingCount=${#requiredAptPackagesMissing[@]} + if [ $requiredAptPackagesMissingCount -gt 0 ]; then + apt_get_update + apt_get_checkinstall "${requiredAptPackagesMissing[@]}" + apt_get_cleanup + fi +} +curl_check_url() { + local url=$1 + local status_code + status_code=$(curl -s -o /dev/null -w '%{http_code}' "$url") + if [ "$status_code" -ne 200 ] && [ "$status_code" -ne 302 ]; then + echo "Failed to download '$url'. Status code: $status_code." + return 1 + fi +} +curl_download_stdout() { + local url=$1 + curl \ + --silent \ + --location \ + --output '-' \ + --connect-timeout 5 \ + "$url" +} +echo_banner() { + local text="$1" + echo -e "\e[1m\e[97m\e[41m$text\e[0m" +} +github_list_releases() { + if [ -z "$1" ]; then + echo "Usage: list_github_releases " + return 1 + fi + local repo="$1" + local url="https://api.github.com/repos/$repo/releases" + curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' +} +github_get_latest_release() { + if [ -z "$1" ]; then + echo "Usage: get_latest_github_release " + return 1 + fi + github_list_releases "$1" | head -n 1 +} +github_get_tag_for_version() { + if [ -z "$1" ] || [ -z "$2" ]; then + echo "Usage: github_get_tag_for_version " + return 1 + fi + local repo="$1" + local version="$2" + local url="https://api.github.com/repos/$repo/releases" + local escaped_version + escaped_version="$(printf '%s' "$version" | sed 's/\./\\./g')" + curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E "^v?${escaped_version}$" | head -n 1 +} +utils_check_version() { + local version=$1 + if ! [[ "${version:-}" =~ ^(latest|[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + printf >&2 '=== [ERROR] Option "version" (value: "%s") is not "latest" or valid semantic version format "X.Y.Z" !\n' \ + "$version" + exit 1 + fi +} +install() { + utils_check_version "$VERSION" + check_curl_tar_installed + apt_get_checkinstall build-essential imagemagick ttyrec x11-apps + if [ "$VERSION" == 'latest' ] || [ -z "$VERSION" ]; then + VERSION=$(github_get_latest_release "$githubRepository") + fi + readonly version="${VERSION:?}" + readonly releaseTag="$(github_get_tag_for_version "$githubRepository" "$version")" + if [ -z "$releaseTag" ]; then + printf >&2 '=== [ERROR] Could not find release tag for version "%s" in "%s"!\n' "$version" "$githubRepository" + exit 1 + fi + readonly downloadUrl="https://github.com/${githubRepository}/archive/refs/tags/${releaseTag}.tar.gz" + curl_check_url "$downloadUrl" + local tmpDir + tmpDir=$(mktemp -d) + curl_download_stdout "$downloadUrl" | tar -xz -f '-' -C "$tmpDir" + local srcDir + srcDir=$(find "$tmpDir" -maxdepth 1 -type d -name "${name}-*" | head -1) + (cd "$srcDir" && make && make install PREFIX=/usr/local) + rm -rf "$tmpDir" + apt_get_cleanup +} +echo_banner "devcontainer.community" +echo "Installing $name..." +install "$@" +echo "(*) Done!" diff --git a/test/icholy-ttygif/test.sh b/test/icholy-ttygif/test.sh new file mode 100755 index 0000000..cb21ae2 --- /dev/null +++ b/test/icholy-ttygif/test.sh @@ -0,0 +1,20 @@ +#!/bin/bash + + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check