Skip to content

feat: add script to generate preview gifs and add them to the README #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Ghostty Shader Previews

A collection of shader previews for Ghostty terminal.

## animated-gradient-shader

![animated-gradient-shader](shader_previews/animated-gradient-shader.gif)

## bettercrt

![bettercrt](shader_previews/bettercrt.gif)

## bloom

![bloom](shader_previews/bloom.gif)

## crt

![crt](shader_previews/crt.gif)

## cubes

![cubes](shader_previews/cubes.gif)

## dither

![dither](shader_previews/dither.gif)

## drunkard

![drunkard](shader_previews/drunkard.gif)

## fireworks-rockets

![fireworks-rockets](shader_previews/fireworks-rockets.gif)

## fireworks

![fireworks](shader_previews/fireworks.gif)

## galaxy

![galaxy](shader_previews/galaxy.gif)

## gears-and-belts

![gears-and-belts](shader_previews/gears-and-belts.gif)

## glitchy

![glitchy](shader_previews/glitchy.gif)

## glow-rgbsplit-twitchy

![glow-rgbsplit-twitchy](shader_previews/glow-rgbsplit-twitchy.gif)

## gradient-background

![gradient-background](shader_previews/gradient-background.gif)

## inside-the-matrix

![inside-the-matrix](shader_previews/inside-the-matrix.gif)

## just-snow

![just-snow](shader_previews/just-snow.gif)

## matrix-hallway

![matrix-hallway](shader_previews/matrix-hallway.gif)

## negative

![negative](shader_previews/negative.gif)

## retro-terminal

![retro-terminal](shader_previews/retro-terminal.gif)

## smoke-and-ghost

![smoke-and-ghost](shader_previews/smoke-and-ghost.gif)

## sparks-from-fire

![sparks-from-fire](shader_previews/sparks-from-fire.gif)

## spotlight

![spotlight](shader_previews/spotlight.gif)

## starfield-colors

![starfield-colors](shader_previews/starfield-colors.gif)

## starfield

![starfield](shader_previews/starfield.gif)

## tft

![tft](shader_previews/tft.gif)

## underwater

![underwater](shader_previews/underwater.gif)

## water

![water](shader_previews/water.gif)
94 changes: 94 additions & 0 deletions generate-previews.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

CONFIG_FILE="$HOME/Library/Application Support/com.mitchellh.ghostty/config"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CONFIG_FILE can also live in $XDG_CONFIG/ghostty and $HOME/.config/ghostty so we should check to see where the ghostty config exists before continuing.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could probably do something along the lines of checking where the file exists first and then setting CONFIG_FILE to the matched path.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$XDG_CONFIG/ghostty

Isn't that supposed to be $XDG_CONFIG_HOME/ghostty?

BACKUP_FILE="$CONFIG_FILE.backup"

# Check if ffmpeg is installed
if ! command -v ffmpeg &> /dev/null; then
echo "ffmpeg is required but not installed. Please install it with 'brew install ffmpeg'"
exit 1
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also have a check to make sure one of the files exist and if it doesn't, instead of moving config to config.backup, we'd simply create a config and then delete it following the process. (this way users who have a no-config setup for ghostty don't have a ton of errors popping up)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use open -na Ghostty.app --args --config-default-files=false --custom-shader=/some/path.


# Create videos directory if it doesn't exist and clean existing recordings
rm -rf shader_previews
mkdir -p shader_previews

# Start README.md with a header
echo "# Ghostty Shader Previews" > README.md
echo "" >> README.md
echo "A collection of shader previews for Ghostty terminal." >> README.md
echo "" >> README.md

# Capture original shader setting
ORIGINAL_SHADER=$(grep "^custom-shader=" "$CONFIG_FILE" || echo "")

# Create backup of original config
cp "$CONFIG_FILE" "$BACKUP_FILE"

# Loop through all .glsl files in the current directory
for file in *.glsl; do
if [ -f "$file" ]; then
echo "Applying shader: $file"

# Remove existing custom-shader line if it exists
sed -i '' '/^custom-shader = /d' "$CONFIG_FILE"

# Add new shader config on a new line, ensuring there's a blank line before it
echo "" >> "$CONFIG_FILE"
echo "custom-shader = $(pwd)/$file" >> "$CONFIG_FILE"

# Get filename without extension for the video name
filename=$(basename "$file" .glsl)

# Open Ghostty
open -a Ghostty

# Give it a moment to open
sleep 2

# Type commands using AppleScript
osascript -e 'tell application "System Events"
keystroke "cd '"$(pwd)"' && ls -la"
key code 36 # Return key
end tell'

# First capture video at reduced size
ffmpeg -f avfoundation -capture_cursor 1 -i "0:none" -t 10 \
-vf "scale=iw/2:ih/2" \
-c:v libx264 -preset fast \
-y "shader_previews/${filename}_temp.mp4"

# Convert to optimized GIF
ffmpeg -i "shader_previews/${filename}_temp.mp4" \
-vf "fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-loop 0 \
"shader_previews/${filename}.gif"

# Remove temporary video
rm "shader_previews/${filename}_temp.mp4"

# Close Ghostty (force kill if necessary)
pkill -9 -x "ghostty"

# Give it a moment to close
sleep 1

# Add shader section to README.md
echo "## ${filename}" >> README.md
echo "" >> README.md
echo "![${filename}](shader_previews/${filename}.gif)" >> README.md
echo "" >> README.md
fi
done

# Restore original config
cp "$BACKUP_FILE" "$CONFIG_FILE"

# If there was an original shader, restore it properly
if [ -n "$ORIGINAL_SHADER" ]; then
sed -i '' '/^custom-shader=/d' "$CONFIG_FILE"
echo "" >> "$CONFIG_FILE"
echo "$ORIGINAL_SHADER" >> "$CONFIG_FILE"
fi

rm "$BACKUP_FILE"
Binary file added shader_previews/animated-gradient-shader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/bettercrt.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/bloom.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/crt.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/cubes.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/dither.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/drunkard.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/fireworks-rockets.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/fireworks.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/galaxy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/gears-and-belts.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/glitchy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/glow-rgbsplit-twitchy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/gradient-background.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/inside-the-matrix.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/just-snow.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/matrix-hallway.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/negative.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/retro-terminal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/smoke-and-ghost.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/sparks-from-fire.gif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the fact that it shows your code for a second probably isn't intended haha - feel free to update it

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/spotlight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/starfield-colors.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/starfield.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/tft.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shader_previews/underwater.gif
Binary file added shader_previews/water.gif