Last active
January 30, 2024 02:52
-
-
Save IliaMManolov/a2ef1c28d5539d061776e64d18540d1b to your computer and use it in GitHub Desktop.
This script can download and update the Cursor.sh text editor in Linux on x64 systems. You might need to have an `Applications` folder inside your `$HOME` to work. This is very unstable and can break at any time if the Cursor devs change the download links of some stuff.
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
#!/bin/bash | |
readonly RED_COLOR="\e[31m" | |
readonly GREEN_COLOR="\e[32m" | |
readonly YELLOW_COLOR="\e[33m" | |
readonly RESET_COLOR="\e[0m" | |
readonly APP_DIR="$HOME/Applications" | |
readonly ICON_DIR="$HOME/.local/share/icons" | |
readonly ICON_URL="https://cursor.sh/brand/icon.svg" | |
readonly DESKTOP_FILE_PATH="$HOME/.local/share/applications/cursor.desktop" | |
readonly DOWNLOAD_LINK="https://download.cursor.sh/linux/appImage/x64" | |
readonly SYMLINK_PATH="$HOME/Applications/cursor.AppImage" | |
cursor_appimage_path="" | |
cursor_icon_path="" | |
print_step() { | |
echo -e "${YELLOW_COLOR}$1${RESET_COLOR}" | |
} | |
print_success() { | |
echo -e " ✅ $1" | |
} | |
error_exit() { | |
echo -e " ❌ ${RED_COLOR}$1${RESET_COLOR}" >&2 | |
exit 1 | |
} | |
check_dependencies() { | |
print_step "Checking the dependencies" | |
for cmd in curl chmod find mkdir; do | |
if ! command -v "$cmd" >/dev/null 2>&1; then | |
error_exit "This script requires $cmd, but it's not installed. Aborting." | |
fi | |
done | |
print_success | |
} | |
fetch_app_path() { | |
print_step "Fetching the latest cursor.sh AppImage path" | |
local appimage_files=($(find "$APP_DIR" -name "cursor-*.AppImage")) | |
local appimage_file_count=${#appimage_files[@]} | |
if [ "$appimage_file_count" -eq 0 ]; then | |
error_exit "No cursor.sh AppImage files found in $APP_DIR" | |
fi | |
cursor_appimage_path=${appimage_files[0]} | |
print_success "$cursor_appimage_path" | |
} | |
fetch_newest_appimage() { | |
print_step "Fetching the latest cursor.sh x64 AppImage" | |
wget --content-disposition "$DOWNLOAD_LINK" | |
cursor_appimage_path=$(find . -maxdepth 1 -name 'cursor*.AppImage' | head -n 1) | |
if [ -z "$cursor_appimage_path" ]; then | |
error_exit "The downloaded cursor AppImage file could not be found." | |
mv "$cursor_appimage_path" "$APP_DIR" | |
local bname=($(basename "$cursor_appimage_path")) | |
cursor_appimage_path="$APP_DIR/$bname" | |
ln -sf "$cursor_appimage_path" "$SYMLINK_PATH" | |
} | |
download_logo() { | |
print_step "Downloading the logo" | |
cursor_icon_path="$ICON_DIR/cursor-icon.svg" | |
mkdir -p "$ICON_DIR" | |
if ! curl -s -o "$cursor_icon_path" "$ICON_URL"; then | |
error_exit "Failed to download the logo from $ICON_URL" | |
fi | |
print_success "$cursor_icon_path" | |
} | |
create_desktop_file() { | |
print_step "Creating the .desktop file" | |
cat <<-EOF >"$DESKTOP_FILE_PATH" | |
[Desktop Entry] | |
Type=Application | |
Name=Cursor | |
Exec=$cursor_appimage_path | |
Icon=$cursor_icon_path | |
Categories=Utility;Development | |
EOF | |
if [ $? -ne 0 ]; then | |
error_exit "Failed to create the .desktop file" | |
fi | |
print_success "$DESKTOP_FILE_PATH" | |
} | |
make_executable() { | |
print_step "Making the .desktop file executable" | |
if ! chmod +x "$DESKTOP_FILE_PATH"; then | |
error_exit "Failed to make the .desktop file executable" | |
fi | |
print_success | |
} | |
mkdir -p $APP_DIR | |
check_dependencies | |
fetch_newest_appimage | |
# fetch_app_path | |
download_logo | |
create_desktop_file | |
make_executable | |
update-desktop-database ~/.local/share/applications | |
echo -e "${GREEN_COLOR}All set, Cursor should now be available in your app launcher with a fancy icon.${RESET_COLOR}" | |
echo "Press any key to exit..." | |
read -n 1 -s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment