getcursor / cursor

The AI-powered code editor
https://cursor.sh
20.59k stars 1.38k forks source link

Bash Script for Cursor App Desktop Integration on Linux Environments #844

Open arpagon opened 10 months ago

arpagon commented 10 months ago

Feature Request for Cursor App Desktop Integration on Linux

Is your feature request related to a problem? Please describe.

Yes, integrating the Cursor app into Linux desktop environments is a manual process. I'm always frustrated when I download a new .AppImage version and have to update the .desktop file and the icon manually.

Describe the solution you'd like

I've created a bash script that automates the entire process. It does the following:

  1. Finds the latest version of the Cursor .AppImage.
  2. Updates or creates a symlink to point to the latest .AppImage.
  3. Downloads the Cursor app icon if it doesn't already exist.
  4. Conditionally creates or updates a .desktop file for the Cursor app.
#!/bin/bash

# Step 1: Find the latest version of the .AppImage
LATEST_APPIMAGE=$(ls -t $HOME/Applications/cursor-*.AppImage | head -n 1)
echo "Latest AppImage: $LATEST_APPIMAGE"

# Step 2: Update symlink to the latest version
SYMLINK_PATH="$HOME/Applications/cursor.AppImage"
ln -sf $LATEST_APPIMAGE $SYMLINK_PATH
echo "Updated symlink to: $SYMLINK_PATH"

# Step 3: Download the Cursor logo if not exists
ICON_PATH="$HOME/.local/share/icons/cursor-icon.svg"
if [ ! -f "$ICON_PATH" ]; then
  mkdir -p $(dirname $ICON_PATH)
  curl -o $ICON_PATH "https://www.cursor.so/brand/icon.svg"
  echo "Downloaded logo to: $ICON_PATH"
fi

# Step 4: Conditionally create or update the .desktop file
DESKTOP_FILE_PATH="$HOME/.local/share/applications/cursor.desktop"
if [ ! -f "$DESKTOP_FILE_PATH" ] || [ "$LATEST_APPIMAGE" != "$(grep -oP '(?<=^Exec=).*' $DESKTOP_FILE_PATH)" ]; then
  DESKTOP_FILE_CONTENT="[Desktop Entry]
Name=Cursor
Exec=$SYMLINK_PATH
Terminal=false
Type=Application
Icon=$ICON_PATH
StartupWMClass=Cursor
X-AppImage-Version=latest
Comment=Cursor is an AI-first coding environment.
MimeType=x-scheme-handler/cursor;
Categories=Utility;Development
"
  echo "$DESKTOP_FILE_CONTENT" > $DESKTOP_FILE_PATH
  chmod +x $DESKTOP_FILE_PATH
  echo "Updated .desktop file at: $DESKTOP_FILE_PATH"
else
  echo ".desktop file is up-to-date."
fi

How to Use:

You can review the script here before executing it. To install and run the script in one command, execute the following:

curl -sSL "https://gist.githubusercontent.com/arpagon/7cb8ff6361380725c893f5535fbbb58d/raw/b9e532bc1db5912d32693337694d941fa0ff60f7/CursorDesktopIntegrator.sh" | bash

Additional context

This script aims to make the user experience more seamless by automating what is otherwise a repetitive manual task. It's particularly useful for users who frequently update their Cursor .AppImage.

eric-naguras commented 8 months ago

Thanks

arpagon commented 7 months ago

Another version by @ChiTimesChi

https://gist.github.com/ChiTimesChi/5dd73abfb5677455705857b3c532c60c https://twitter.com/ChiTimesChi/status/1723682451283755284?t=ItCMQ0Z__ODRZMHpav0Vfg&s=19

arpagon commented 2 months ago

To work in Ubuntu 24.04

file: /etc/apparmor.d/cursor-appimage

# This profile allows everything and only exists to give the
# application a name instead of having the label "unconfined"

abi <abi/4.0>,
include <tunables/global>

profile cursor /home/{USER}/Applications/cursor*.AppImage flags=(unconfined) {
  userns,

  # Site-specific additions and overrides.  See local/README for details.
  include if exists <local/cursor>
}

run the parser

sudo apparmor_parser -r /etc/apparmor.d/cursor-appimage

This led me to the solution thanks @jrjohansen

https://github.com/laurent22/joplin/issues/10332#issuecomment-2065889431

arimgibson commented 1 month ago

Great work! Would also shoutout AppImageLauncher, especially if you have multiple AppImages you want integrated

kodai-bot commented 1 month ago

Thankyou for solution!

cogtoto commented 1 month ago

thanks a lot.

Bhagvat080 commented 2 weeks ago

thanks a lot!