Forked from msanjeevkumar/cursor_setup_and_update.sh
Last active
September 15, 2024 03:18
-
-
Save itz4blitz/372582dfc1d2fe9cd047a5f3fc5648c8 to your computer and use it in GitHub Desktop.
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 -euo pipefail | |
| # Directory setup | |
| APP_DIR="${HOME}/Applications" | |
| ICON_DIR="${HOME}/.local/share/icons" | |
| DESKTOP_DIR="${HOME}/.local/share/applications" | |
| BIN_DIR="${HOME}/.local/bin" | |
| # File paths | |
| DOWNLOAD_URL="https://downloader.cursor.sh/linux/appImage/x64" | |
| ICON_DOWNLOAD_URL="https://cursor.sh/brand/icon.svg" | |
| APPIMAGE_NAME="cursor.AppImage" | |
| APPIMAGE_PATH="${APP_DIR}/${APPIMAGE_NAME}" | |
| ICON_PATH="${ICON_DIR}/cursor-icon.png" | |
| DESKTOP_FILE_PATH="${DESKTOP_DIR}/cursor.desktop" | |
| LAUNCHER_SCRIPT="${BIN_DIR}/cursor" | |
| ZSHRC="${HOME}/.zshrc" | |
| # Utility functions | |
| log() { printf '%s\n' "$*"; } | |
| error() { printf 'Error: %s\n' "$*" >&2; exit 1; } | |
| # Create necessary directories | |
| mkdir -p "${APP_DIR}" "${ICON_DIR}" "${DESKTOP_DIR}" "${BIN_DIR}" | |
| # Download the latest Cursor AppImage | |
| log "Downloading the latest Cursor AppImage..." | |
| curl -L "${DOWNLOAD_URL}" -o "${APPIMAGE_PATH}" || error "Failed to download Cursor AppImage" | |
| chmod +x "${APPIMAGE_PATH}" | |
| log "Downloaded and made executable: ${APPIMAGE_PATH}" | |
| # Download the Cursor icon (the correct one) if it doesn't exist | |
| if [ ! -f "${ICON_PATH}" ]; then | |
| curl -L "${ICON_DOWNLOAD_URL}" -o "${ICON_PATH}" || error "Failed to download icon" | |
| log "Downloaded logo to: ${ICON_PATH}" | |
| fi | |
| # Create or update the .desktop file for Cursor | |
| cat > "${DESKTOP_FILE_PATH}" << EOF | |
| [Desktop Entry] | |
| Name=Cursor | |
| Exec=${LAUNCHER_SCRIPT} %F | |
| 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 | |
| EOF | |
| chmod +x "${DESKTOP_FILE_PATH}" | |
| log "Updated .desktop file at: ${DESKTOP_FILE_PATH}" | |
| # Create the launcher script for Cursor with support for directories | |
| cat > "${LAUNCHER_SCRIPT}" << EOF | |
| #!/bin/bash | |
| # Default to current directory if no argument is provided | |
| if [ "\$#" -eq 0 ] || [ "\$1" == "." ]; then | |
| directory="\$PWD" | |
| else | |
| directory="\$1" | |
| fi | |
| # Run the cursor app in the given or current directory | |
| nohup ${APPIMAGE_PATH} "\$directory" > ~/.cursor_log 2>&1 & | |
| EOF | |
| chmod +x "${LAUNCHER_SCRIPT}" | |
| log "Created launcher script: ${LAUNCHER_SCRIPT}" | |
| # Ensure ~/.local/bin is in the PATH | |
| if ! grep -q 'export PATH="$HOME/.local/bin:$PATH"' "${ZSHRC}"; then | |
| echo 'export PATH="$HOME/.local/bin:$PATH"' >> "${ZSHRC}" | |
| log "Added ~/.local/bin to PATH in ${ZSHRC}" | |
| else | |
| log "~/.local/bin is already in PATH in ${ZSHRC}" | |
| fi | |
| # Check if the alias for `cursor` exists, otherwise add it | |
| if ! grep -q 'alias cursor="cursor ."' "${ZSHRC}"; then | |
| echo 'alias cursor="cursor ."' >> "${ZSHRC}" | |
| log "Added cursor alias for Cursor in ${ZSHRC}" | |
| else | |
| log "Alias for cursor . already exists in ${ZSHRC}" | |
| fi | |
| # Fix for potential XDG_CACHE_HOME issues in ~/.zshrc | |
| log "Ensuring compatibility with Zsh and fixing potential XDG_CACHE_HOME issues..." | |
| if grep -q 'p10k-instant-prompt' "${ZSHRC}"; then | |
| sed -i '/p10k-instant-prompt/ s/\${(%):-%n}/$USER/' "${ZSHRC}" | |
| log "Fixed p10k-instant-prompt line in ${ZSHRC}" | |
| fi | |
| # Fix for unbound ZSH_VERSION variable | |
| if ! grep -q 'ZSH_VERSION=' "${ZSHRC}"; then | |
| echo 'ZSH_VERSION="${ZSH_VERSION:-$(zsh --version | cut -d " " -f 2)}"' >> "${ZSHRC}" | |
| log "Added ZSH_VERSION initialization in ${ZSHRC}" | |
| fi | |
| # Safe reload of .zshrc | |
| log "Applying changes safely by running a subshell to avoid unbound variable errors..." | |
| zsh -c 'source ~/.zshrc' || log "Zshrc reload failed. Please manually check ~/.zshrc or restart your terminal session." | |
| log "Cursor has been successfully installed and configured." | |
| log "You can run 'cursor .' from the terminal to open it in the current directory." | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to support
.zshrc