-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
 | ||
|
||
## bettercrt | ||
|
||
 | ||
|
||
## bloom | ||
|
||
 | ||
|
||
## crt | ||
|
||
 | ||
|
||
## cubes | ||
|
||
 | ||
|
||
## dither | ||
|
||
 | ||
|
||
## drunkard | ||
|
||
 | ||
|
||
## fireworks-rockets | ||
|
||
 | ||
|
||
## fireworks | ||
|
||
 | ||
|
||
## galaxy | ||
|
||
 | ||
|
||
## gears-and-belts | ||
|
||
 | ||
|
||
## glitchy | ||
|
||
 | ||
|
||
## glow-rgbsplit-twitchy | ||
|
||
 | ||
|
||
## gradient-background | ||
|
||
 | ||
|
||
## inside-the-matrix | ||
|
||
 | ||
|
||
## just-snow | ||
|
||
 | ||
|
||
## matrix-hallway | ||
|
||
 | ||
|
||
## negative | ||
|
||
 | ||
|
||
## retro-terminal | ||
|
||
 | ||
|
||
## smoke-and-ghost | ||
|
||
 | ||
|
||
## sparks-from-fire | ||
|
||
 | ||
|
||
## spotlight | ||
|
||
 | ||
|
||
## starfield-colors | ||
|
||
 | ||
|
||
## starfield | ||
|
||
 | ||
|
||
## tft | ||
|
||
 | ||
|
||
## underwater | ||
|
||
 | ||
|
||
## water | ||
|
||
 |
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" | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or use |
||
|
||
# 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 "" >> 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" |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that supposed to be
$XDG_CONFIG_HOME/ghostty
?