Here’s a nice trick:
If it’s not clear, I am creating new tabs in my ghostty terminal, and each tab spawns with a different background image.
Now, having a background image at all may be shunned by some, but I decided that since I spend most of my time looking at a terminal window it would be fun to have some variety sprinkled in.
How does it work?
Setting a custom image as background
First off, Ghostty lets me set a background image via the background-image parameter, which is a path to the background of my choosing.
That lets me choose the image, but since I still need to use the terminal to do stuff with, I still need to tweak its opacity so that the text doesn’t get drowned out. That can be dealt with by lowering the value of background-image-opacity, so that it is lower than 1.
background-image=~/ghostty-bg.png
background-image-opacity=0.5
You can find the full configuration here.
Unfortunately, it is not (yet) possible to set a gallery of images to go through, which is where the second part of the setup comes into play.
Choosing a random image from a folder
The solution is in two parts: firstly, ghostty-bg.png is not an actual image: it’s a soft link, specifically a soft link to an image in my backgrounds folder.
This link is re-generated automatically by this shell script:
#!/bin/zsh
# Configuration
IMAGE_DIR="~/bg-images"
LINK_PATH="~/ghostty-bg.png"
# Ensure the image directory exists
if [ ! -d "$IMAGE_DIR" ]; then
echo "Error: Directory $IMAGE_DIR does not exist."
exit 1
fi
# Get a list of image files (adjust extensions as needed)
# We use find to be safer than ls with spaces in filenames
FILES=$(find "$IMAGE_DIR" -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.png" \))
if [ -z "$FILES" ]; then
echo "Error: No image files found in $IMAGE_DIR"
exit 1
fi
# Select a random file from the list
# 'shuf' reads lines and outputs a random subset
RANDOM_FILE=$(echo "$FILES" | sort -R | head -n 1)
# Remove the old symlink if it exists
rm -f "$LINK_PATH"
# Create the new symlink
ln -s "$RANDOM_FILE" "$LINK_PATH"
echo "Updated $LINK_PATH to point to $(basename "$RANDOM_FILE")"In short, the script takes a path to the folder that contains the pictures, finds all the png or jpg files and puts them in a list, then selects a random file out among those and creates a link to it.
Then, I added it to .zshrc:
...
source ~/bin/update_bg.sh &>/dev/nullThe configuration is reloaded every time a new terminal is created, updating the link so that it points at a different image.
Pretty cool, huh?
Unfortunately, this does not work with tmux (yet), as there isn’t a way of altering the configuration directly from the terminal. However, It’s acknowledged as a planned feature so maybe it’ll be added at some point in the future.
All backgrounds are screencaps from these MVs:
- プリマドンナ / 星街すいせい(official) (Hoshimachi Suisei - Prima Donna)
- [Original Anime MV] Chatter Chatter [Hoshimachi Suisei×Houshou Marine / hololive]
- 【meiyo】なにやってもうまくいかない(feat.asmi)【MV】 (Nothing’s working out - Meiyo ft Asmi)