Skip to content

Instantly share code, notes, and snippets.

@dgtal
Last active April 7, 2025 17:47
Show Gist options
  • Select an option

  • Save dgtal/ad5bd14981d9ee4d8cc6e4e6a2e8e757 to your computer and use it in GitHub Desktop.

Select an option

Save dgtal/ad5bd14981d9ee4d8cc6e4e6a2e8e757 to your computer and use it in GitHub Desktop.
Install Ghostty on Fedora
#!/bin/bash
# Script to install Ghostty on Fedora with improvements for Fedora 41
command_exists() {
command -v "$1" >/dev/null 2>&1
}
error_exit() {
echo "Error: $1" >&2
exit 1
}
install_icon() {
local size=$1
local src=$2
local icons_dir="$HOME/.local/share/icons/hicolor/${size}x${size}/apps"
mkdir -p "$icons_dir"
cp "$src" "$icons_dir/com.mitchellh.ghostty.png"
}
echo "=== Starting Ghostty Installation ==="
if ! grep -qi "fedora" /etc/os-release; then
error_exit "This script is designed for Fedora"
fi
echo "=== Installing dependencies ==="
sudo dnf install -y gtk4-devel zig libadwaita-devel desktop-file-utils || error_exit "Could not install dependencies"
BUILD_DIR=$(mktemp -d)
cd "$BUILD_DIR" || error_exit "Could not create temporary directory"
echo "=== Cloning Ghostty repository ==="
git clone https://github.com/mitchellh/ghostty.git || error_exit "Could not clone repository"
cd ghostty || error_exit "Could not access ghostty directory"
echo "=== Building Ghostty ==="
zig build -p "$HOME/.local" -Doptimize=ReleaseFast || error_exit "Build failed"
echo "=== Configuring desktop entry ==="
DESKTOP_DIR="$HOME/.local/share/applications"
mkdir -p "$DESKTOP_DIR"
# Create the desktop file using absolute paths for the executable
cat > "$DESKTOP_DIR/com.mitchellh.ghostty.desktop" <<EOF
[Desktop Entry]
Version=1.0
Name=Ghostty
GenericName=Terminal
Type=Application
Comment=A terminal emulator
Exec=${HOME}/.local/bin/ghostty
TryExec=${HOME}/.local/bin/ghostty
Icon=com.mitchellh.ghostty
Categories=System;TerminalEmulator;GTK;
Keywords=terminal;tty;pty;shell;prompt;command;commandline;
StartupNotify=true
Terminal=false
Actions=new-window;
[Desktop Action new-window]
Name=New Window
Exec=${HOME}/.local/bin/ghostty
EOF
chmod +x "$DESKTOP_DIR/com.mitchellh.ghostty.desktop"
echo "=== Validating desktop entry ==="
if command_exists desktop-file-validate; then
desktop-file-validate "$DESKTOP_DIR/com.mitchellh.ghostty.desktop" || echo "Warning: desktop file validation failed"
fi
echo "=== Installing icons ==="
# Assuming the icons are located in images/icons within the cloned repository
cd images/icons || error_exit "Icons directory not found"
for icon in icon_*.png; do
if [[ $icon =~ icon_([0-9]+).png ]]; then
size="${BASH_REMATCH[1]}"
echo "Installing ${size}x${size} icon"
install_icon "$size" "$icon"
fi
done
for icon in icon_*@2x.png; do
if [[ $icon =~ icon_([0-9]+)@2x.png ]]; then
size="${BASH_REMATCH[1]}"
size_2x=$((size * 2))
echo "Installing ${size_2x}x${size_2x} icon (@2x)"
install_icon "$size_2x" "$icon"
fi
done
echo "=== Updating system caches ==="
gtk-update-icon-cache -f -t "$HOME/.local/share/icons/hicolor" 2>/dev/null || true
update-desktop-database "$HOME/.local/share/applications" 2>/dev/null || true
echo "=== Setting up XDG data dirs ==="
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
mkdir -p "$XDG_CONFIG_HOME/environment.d"
# Ensure the graphical environment includes $HOME/.local/share in XDG_DATA_DIRS
echo "XDG_DATA_DIRS=\$HOME/.local/share:/usr/local/share:/usr/share" > "$XDG_CONFIG_HOME/environment.d/ghostty.conf"
echo "=== Installation completed ==="
echo "Ghostty has been installed in $HOME/.local/bin"
echo "Desktop entry has been created in $DESKTOP_DIR"
echo "Icons have been installed in $HOME/.local/share/icons/hicolor"
echo "=== Post-installation tasks ==="
echo "1. Add the following lines to your ~/.bashrc or ~/.zshrc (if not already added):"
echo " export PATH=\$PATH:\$HOME/.local/bin"
echo " export XDG_DATA_DIRS=\$HOME/.local/share:\$XDG_DATA_DIRS"
echo ""
echo "2. Run 'source ~/.bashrc' (or 'source ~/.zshrc') to apply the changes."
echo ""
echo "3. Log out and log back in to ensure all changes take effect."
cd
rm -rf "$BUILD_DIR"
echo "=== Done! ==="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment