Created
February 26, 2025 04:37
-
-
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
This file contains 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
#!/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