Last active
April 21, 2025 13:23
-
-
Save Bishwas-py/cceb4caecdd072edc3fafdce3d5c12ae to your computer and use it in GitHub Desktop.
Cursor installer / uninstaller for linux, Fedora, Ubuntu, Arch or distros
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 | |
# Set default paths and URLs | |
DOWNLOADS_DIR="$HOME/Downloads" | |
APPLICATIONS_DIR="$HOME/.local/bin" # More appropriate location for AppImages | |
ICON_URL="https://www.cursor.com/apple-touch-icon.png" | |
APPIMAGE_URL="https://downloads.cursor.com/production/61e99179e4080fecf9d8b92c6e2e3e00fbfb53f4/linux/x64/Cursor-0.48.9-x86_64.AppImage" | |
ICON_FILENAME="cursor-icon.png" | |
APPIMAGE_FILENAME="Cursor-0.48.9-x86_64.AppImage" | |
DESKTOP_FILE="$HOME/.local/share/applications/cursor-editor.desktop" | |
ICON_DEST="$HOME/.local/share/icons/$ICON_FILENAME" | |
APPIMAGE_DEST="$APPLICATIONS_DIR/$APPIMAGE_FILENAME" | |
# Colors for output | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
# Function to print status messages | |
print_status() { | |
echo -e "${GREEN}[INFO]${NC} $1" | |
} | |
print_warning() { | |
echo -e "${YELLOW}[WARNING]${NC} $1" | |
} | |
print_error() { | |
echo -e "${RED}[ERROR]${NC} $1" | |
} | |
# Function to check if a command exists | |
command_exists() { | |
command -v "$1" >/dev/null 2>&1 | |
} | |
# Function to download a file if it doesn't exist | |
download_file() { | |
local url="$1" | |
local output_path="$2" | |
if [ -f "$output_path" ]; then | |
print_status "File already exists: $output_path" | |
else | |
print_status "Downloading: $url" | |
if command_exists wget; then | |
wget -q --show-progress "$url" -O "$output_path" | |
elif command_exists curl; then | |
curl -L --progress-bar "$url" -o "$output_path" | |
else | |
print_error "Neither wget nor curl is installed. Please install one of them and try again." | |
exit 1 | |
fi | |
if [ $? -ne 0 ]; then | |
print_error "Failed to download: $url" | |
exit 1 | |
else | |
print_status "Successfully downloaded to: $output_path" | |
fi | |
fi | |
} | |
# Function to find files | |
find_file() { | |
local filename="$1" | |
local search_dir="$2" | |
# Try to find the file in the specified directory or user's home | |
find "$search_dir" -name "$filename" -type f -print -quit 2>/dev/null | |
} | |
# Function to install the desktop entry | |
install_cursor() { | |
print_status "Starting Cursor installation process..." | |
# Create necessary directories | |
mkdir -p "$HOME/.local/share/icons" "$HOME/.local/share/applications" "$APPLICATIONS_DIR" | |
# Find or download the icon | |
local icon_path=$(find_file "$ICON_FILENAME" "$DOWNLOADS_DIR") | |
if [ -z "$icon_path" ]; then | |
icon_path=$(find_file "apple-touch-icon.png" "$DOWNLOADS_DIR") | |
fi | |
if [ -z "$icon_path" ]; then | |
print_status "Icon not found locally, downloading from $ICON_URL" | |
icon_path="$DOWNLOADS_DIR/$ICON_FILENAME" | |
download_file "$ICON_URL" "$icon_path" | |
else | |
print_status "Found icon at: $icon_path" | |
fi | |
# Find or download the AppImage | |
local appimage_path=$(find_file "$APPIMAGE_FILENAME" "$APPLICATIONS_DIR") | |
if [ -z "$appimage_path" ]; then | |
appimage_path=$(find_file "$APPIMAGE_FILENAME" "$DOWNLOADS_DIR") | |
if [ -z "$appimage_path" ]; then | |
print_status "AppImage not found locally, downloading from $APPIMAGE_URL" | |
appimage_path="$DOWNLOADS_DIR/$APPIMAGE_FILENAME" | |
download_file "$APPIMAGE_URL" "$appimage_path" | |
else | |
print_status "Found AppImage in Downloads: $appimage_path" | |
fi | |
# Move AppImage to applications directory | |
print_status "Moving AppImage to applications directory: $APPLICATIONS_DIR" | |
mv "$appimage_path" "$APPIMAGE_DEST" | |
appimage_path="$APPIMAGE_DEST" | |
else | |
print_status "Found AppImage in applications directory: $appimage_path" | |
fi | |
# Copy the icon to the icons directory | |
cp "$icon_path" "$ICON_DEST" | |
print_status "Copied icon to: $ICON_DEST" | |
# Make the AppImage executable | |
chmod +x "$appimage_path" | |
print_status "Made AppImage executable" | |
# Create the desktop entry file | |
cat > "$DESKTOP_FILE" << EOF | |
[Desktop Entry] | |
Name=Cursor Code Editor | |
Comment=AI-first code editor | |
Exec="$appimage_path" | |
Icon=$ICON_DEST | |
Terminal=false | |
Type=Application | |
Categories=Development;TextEditor; | |
StartupWMClass=Cursor | |
EOF | |
print_status "Created desktop entry at: $DESKTOP_FILE" | |
# Update desktop database if command exists | |
if command_exists update-desktop-database; then | |
update-desktop-database "$HOME/.local/share/applications" | |
print_status "Updated desktop database" | |
fi | |
print_status "${GREEN}Cursor installation complete!${NC}" | |
print_status "You should now be able to find it in your applications menu." | |
} | |
# Function to uninstall Cursor | |
uninstall_cursor() { | |
print_status "Uninstalling Cursor desktop entry..." | |
# Check if desktop file exists | |
if [ -f "$DESKTOP_FILE" ]; then | |
rm -f "$DESKTOP_FILE" | |
print_status "Removed desktop file: $DESKTOP_FILE" | |
else | |
print_warning "Desktop file not found: $DESKTOP_FILE" | |
fi | |
# Check if icon exists | |
if [ -f "$ICON_DEST" ]; then | |
rm -f "$ICON_DEST" | |
print_status "Removed icon: $ICON_DEST" | |
else | |
print_warning "Icon not found: $ICON_DEST" | |
fi | |
# Check if AppImage exists in applications directory | |
if [ -f "$APPIMAGE_DEST" ]; then | |
rm -f "$APPIMAGE_DEST" | |
print_status "Removed AppImage: $APPIMAGE_DEST" | |
else | |
print_warning "AppImage not found in applications directory: $APPIMAGE_DEST" | |
fi | |
# Update desktop database if command exists | |
if command_exists update-desktop-database; then | |
update-desktop-database "$HOME/.local/share/applications" | |
print_status "Updated desktop database" | |
fi | |
print_status "${GREEN}Cursor uninstallation complete!${NC}" | |
# Ask if user wants to remove downloaded files that might still be in Downloads | |
read -p "Do you want to check for and remove any Cursor files in Downloads? (y/n): " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
# Find and remove AppImage from Downloads | |
local appimage_path=$(find_file "$APPIMAGE_FILENAME" "$DOWNLOADS_DIR") | |
if [ -n "$appimage_path" ]; then | |
rm -f "$appimage_path" | |
print_status "Removed AppImage from Downloads: $appimage_path" | |
fi | |
# Find and remove icon | |
local icon_path=$(find_file "$ICON_FILENAME" "$DOWNLOADS_DIR") | |
if [ -n "$icon_path" ]; then | |
rm -f "$icon_path" | |
print_status "Removed icon from Downloads: $icon_path" | |
fi | |
local alt_icon_path=$(find_file "apple-touch-icon.png" "$DOWNLOADS_DIR") | |
if [ -n "$alt_icon_path" ]; then | |
rm -f "$alt_icon_path" | |
print_status "Removed icon from Downloads: $alt_icon_path" | |
fi | |
fi | |
} | |
# Main script logic | |
case "$1" in | |
"install") | |
install_cursor | |
;; | |
"uninstall") | |
uninstall_cursor | |
;; | |
*) | |
echo "Cursor Desktop Setup Utility" | |
echo "----------------------------" | |
echo "Usage: $0 {install|uninstall}" | |
echo | |
echo " install - Create desktop entry for Cursor (will download files if needed)" | |
echo " uninstall - Remove desktop entry for Cursor" | |
echo | |
echo "This script will automatically find or download the necessary files," | |
echo "move the AppImage to $APPLICATIONS_DIR, and create a desktop entry for the Cursor code editor." | |
;; | |
esac |
Author
Bishwas-py
commented
Apr 21, 2025
To install:
curl -sSL https://gist.githubusercontent.com/Bishwas-py/cceb4caecdd072edc3fafdce3d5c12ae/raw/a8f7aba472cdee3cbdaaadbd85b539e27dcbf2b6/cursor.sh | bash -s install
To uninstall:
curl -sSL https://gist.githubusercontent.com/Bishwas-py/cceb4caecdd072edc3fafdce3d5c12ae/raw/a8f7aba472cdee3cbdaaadbd85b539e27dcbf2b6/cursor.sh | bash -s uninstall
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment