Last active
February 22, 2026 17:33
-
-
Save ykessler/517a5c28618e1aaa21307559d6064902 to your computer and use it in GitHub Desktop.
Apply a Ghostty theme to a single surface (split/tab) without affecting others
This file contains hidden or 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 | |
| # | |
| # ghostty-surface-theme.sh | |
| # Apply a Ghostty theme to the current surface only, without affecting other | |
| # splits, tabs, or windows. Works by reading Ghostty's built-in theme files | |
| # and sending the equivalent OSC escape sequences to the current terminal. | |
| # | |
| # INSTALL | |
| # Copy this script somewhere on your PATH and make it executable: | |
| # | |
| # curl -o ~/.local/bin/ghostty-surface-theme.sh \ | |
| # https://gist.githubusercontent.com/ykessler/517a5c28618e1aaa21307559d6064902/raw/ghostty-surface-theme.sh | |
| # chmod +x ~/.local/bin/ghostty-surface-theme.sh | |
| # | |
| # Make sure ~/.local/bin is in your PATH. Add this to your ~/.zshrc or | |
| # ~/.bashrc if it isn't already: | |
| # | |
| # export PATH="$HOME/.local/bin:$PATH" | |
| # | |
| # USAGE | |
| # Apply a theme to the current surface: | |
| # ghostty-surface-theme.sh "Catppuccin Frappe" | |
| # | |
| # Reset the current surface back to your config defaults: | |
| # ghostty-surface-theme.sh --reset | |
| # | |
| # List available theme names: | |
| # ghostty +list-themes | |
| # | |
| # SHORTCUT | |
| # Add an alias to your ~/.zshrc or ~/.bashrc: | |
| # | |
| # alias gtheme="ghostty-surface-theme.sh" | |
| # | |
| # Then just: | |
| # gtheme "Tokyo Night" | |
| # gtheme --reset | |
| # | |
| # THEME FILE LOCATIONS | |
| # The script checks for themes in this order: | |
| # 1. macOS app bundle: /Applications/Ghostty.app/Contents/Resources/ghostty/themes/ | |
| # 2. Linux system: /usr/share/ghostty/themes/ | |
| # 3. User custom: ~/.config/ghostty/themes/ | |
| # | |
| THEME="$1" | |
| if [[ -z "$THEME" ]]; then | |
| echo "Usage: ghostty-surface-theme.sh <theme-name>" | |
| echo " ghostty-surface-theme.sh --reset" | |
| echo "" | |
| echo "Run 'ghostty +list-themes' to see available themes." | |
| exit 1 | |
| fi | |
| # Reset to config defaults | |
| if [[ "$THEME" == "--reset" ]]; then | |
| printf '\e]110\a' # reset foreground | |
| printf '\e]111\a' # reset background | |
| printf '\e]112\a' # reset cursor color | |
| printf '\e]117\a' # reset selection background | |
| printf '\e]119\a' # reset selection foreground | |
| printf '\e]104\a' # reset all palette colors | |
| exit 0 | |
| fi | |
| # Find the theme file | |
| THEME_FILE="" | |
| for dir in \ | |
| "/Applications/Ghostty.app/Contents/Resources/ghostty/themes" \ | |
| "/usr/share/ghostty/themes" \ | |
| "$HOME/.config/ghostty/themes"; do | |
| if [[ -f "$dir/$THEME" ]]; then | |
| THEME_FILE="$dir/$THEME" | |
| break | |
| fi | |
| done | |
| if [[ -z "$THEME_FILE" ]]; then | |
| echo "Theme '$THEME' not found" | |
| exit 1 | |
| fi | |
| # Parse theme file and send OSC escape sequences | |
| while IFS='= ' read -r key value; do | |
| case "$key" in | |
| foreground) printf '\e]10;%s\a' "$value" ;; | |
| background) printf '\e]11;%s\a' "$value" ;; | |
| cursor-color) printf '\e]12;%s\a' "$value" ;; | |
| selection-background) printf '\e]17;%s\a' "$value" ;; | |
| selection-foreground) printf '\e]19;%s\a' "$value" ;; | |
| palette) | |
| IFS='=' read -r idx color <<< "$value" | |
| printf '\e]4;%s;%s\a' "$idx" "$color" | |
| ;; | |
| esac | |
| done < "$THEME_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment