Forked from arpagon/Cursor-Desktop-AutoUpdate-Handler.sh
Last active
November 12, 2023 12:31
-
-
Save ChiTimesChi/5dd73abfb5677455705857b3c532c60c to your computer and use it in GitHub Desktop.
Cursor-Desktop-AutoUpdate-Handler.sh
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/Desktop/cursor.desktop" | |
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" | |
} | |
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 | |
} | |
check_dependencies | |
fetch_app_path | |
download_logo | |
create_desktop_file | |
make_executable | |
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