Skip to content

Instantly share code, notes, and snippets.

@notdaniel
Created February 26, 2025 04:37
Show Gist options
  • Save notdaniel/2c4a218a63eaf5ef0ffae79feab891fd to your computer and use it in GitHub Desktop.
Save notdaniel/2c4a218a63eaf5ef0ffae79feab891fd to your computer and use it in GitHub Desktop.
Script to properly execute the Cursor AppImage, which is broken on v0.46
#!/usr/bin/env bash
#
# Launches Cursor AppImage with proper path handling
#
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
LOGFILE="/tmp/cursor.log"
# Function to clean up on exit or error
cleanup() {
local exit_code=$?
if [[ $exit_code -ne 0 ]]; then
echo "❌ Error occurred at line $LINENO, exiting with status $exit_code" | tee -a "$LOGFILE" >&2
fi
exit $exit_code
}
# Redirect stdout and stderr to log file while seeing output
# exec 1> >(tee -a "$LOGFILE") 2>&1
# Redirect stdout and stderr to log file
exec &>> "$LOGFILE"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
APPIMAGE_DIR="$HOME/Applications"
# Find latest Cursor AppImage
CURSOR_APPIMAGE=$(ls -t "$APPIMAGE_DIR"/cursor-*.AppImage 2>/dev/null | head -n 1 || true)
if [[ -z "$CURSOR_APPIMAGE" ]]; then
log "❌ Error: Cursor AppImage not found in $APPIMAGE_DIR"
exit 1
fi
log "πŸ” Found Cursor AppImage: $CURSOR_APPIMAGE"
# Convert all file arguments to absolute paths
args=()
for arg in "$@"; do
if [[ -e "$arg" ]]; then
abs_path="$(realpath "$arg")"
args+=("$abs_path")
log "πŸ“ Converting path: $arg -> $abs_path"
else
args+=("$arg")
log "πŸ“Ž Keeping argument as-is: $arg"
fi
done
# Check if running under Wayland
if [[ "${XDG_SESSION_TYPE:-}" == "wayland" ]]; then
args+=("--ozone-platform=wayland")
log "🌿 Detected Wayland session, adding --ozone-platform=wayland"
fi
log "πŸš€ Launching with parameters: ${args[*]}"
"$CURSOR_APPIMAGE" --no-sandbox "${args[@]}" &
CURSOR_PID=$!
# Verify process started successfully
sleep 1
if ! kill -0 "$CURSOR_PID" 2>/dev/null; then
log "❌ Error: Cursor failed to start"
exit 1
fi
log "✨ Cursor launched successfully (PID: $CURSOR_PID)"
disown "$CURSOR_PID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment