feat(cursor): improve setup script and fix issue with installing extensions

This commit is contained in:
Jim Myhrberg
2025-02-21 19:01:34 +00:00
parent 65bee1192e
commit 06f91b1d79
4 changed files with 149 additions and 57 deletions

View File

@@ -14,6 +14,9 @@ CONFIG_SOURCES=(
# Detect current script directory.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Extensions lockfile path
EXTENSIONS_LOCK="${SCRIPT_DIR}/extensions.lock"
# ==============================================================================
# Help
# ==============================================================================
@@ -116,11 +119,10 @@ find_cursor_cmd() {
echo "${cursor_cmd}"
}
# Dump installed extensions to extensions.txt
# Dump installed extensions to extensions.lock
do_dump_extensions() {
local cursor_cmd
cursor_cmd="$(find_cursor_cmd)"
local extensions_file="${SCRIPT_DIR}/extensions.txt"
local current_date
current_date="$(date)"
@@ -128,31 +130,102 @@ do_dump_extensions() {
echo "# Cursor Extensions"
echo "# Generated on ${current_date}"
echo
"${cursor_cmd}" --list-extensions
} >"${extensions_file}"
"${cursor_cmd}" --list-extensions --show-versions
} >"${EXTENSIONS_LOCK}"
echo "Extensions list dumped to ${extensions_file}"
echo "Extensions list dumped to ${EXTENSIONS_LOCK}"
}
# Install extensions from extensions.txt
# Global variable to cache installed extensions
_INSTALLED_EXTENSIONS=""
# Check if extension is already installed with exact version
is_extension_installed() {
local cursor_cmd="$1"
local extension="$2"
local version="$3"
# Build cache if not already built
if [[ -z "${_INSTALLED_EXTENSIONS}" ]]; then
_INSTALLED_EXTENSIONS="$("${cursor_cmd}" --list-extensions --show-versions)"
fi
# Check if extension@version exists in cached list
echo "${_INSTALLED_EXTENSIONS}" | grep -q "^${extension}@${version}$"
}
# Download and install a single extension.
#
# This is needed for cursor right now as installing an extension based on its
# ID yields a signature error. But installing from a .vsix file works fine.
download_and_install_extension() {
local cursor_cmd="$1"
local extension="$2"
local version="$3"
local extensions_dir="$4"
# Check if already installed with correct version
if is_extension_installed "${cursor_cmd}" "${extension}" "${version}"; then
echo "Extension ${extension}@${version} is already installed, skipping"
return 0
fi
local vsix_path="${extensions_dir}/${extension}@${version}.vsix"
# Create extensions directory if it doesn't exist
mkdir -p "${extensions_dir}"
# If .vsix doesn't exist, download it
if [[ ! -f "${vsix_path}" ]]; then
local publisher_id="${extension%%.*}"
local extension_id="${extension#*.}"
local vsix_url="https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher_id}/vsextensions/${extension_id}/${version}/vspackage"
echo "Downloading ${extension}@${version}.vsix..."
echo " - URL: ${vsix_url}"
if ! curl --compressed -L -o "${vsix_path}" "${vsix_url}"; then
echo "Failed to download ${extension}@${version}.vsix"
return 1
fi
fi
# Install the extension from .vsix file
echo "Installing extension from ${vsix_path}"
if ! "${cursor_cmd}" --install-extension "${vsix_path}"; then
echo "Failed to install ${extension}@${version}"
return 1
fi
# Clean up the .vsix file after successful installation
rm "${vsix_path}"
return 0
}
# Install extensions from extensions.lock
do_install_extensions() {
local cursor_cmd
cursor_cmd="$(find_cursor_cmd)"
local extensions_file="${SCRIPT_DIR}/extensions.txt"
local extensions_dir="${SCRIPT_DIR}/cache/extensions"
if [[ ! -f "${extensions_file}" ]]; then
echo "Error: ${extensions_file} not found"
if [[ ! -f "${EXTENSIONS_LOCK}" ]]; then
echo "Error: ${EXTENSIONS_LOCK} not found"
exit 1
fi
# Read extensions file, skip comments and empty lines
# Process each extension
while IFS= read -r line; do
if [[ -n "${line}" && ! "${line}" =~ ^[[:space:]]*# ]]; then
echo "Installing extension: ${line}"
"${cursor_cmd}" --install-extension "${line}"
fi
done <"${extensions_file}"
extension="${line%@*}"
version="${line#*@}"
if ! download_and_install_extension "${cursor_cmd}" "${extension}" "${version}" "${extensions_dir}"; then
echo "Warning: Failed to install ${extension}@${version}"
fi
fi
done <"${EXTENSIONS_LOCK}"
# Clean up extensions directory if empty
rmdir "${extensions_dir}" 2>/dev/null || true
echo "Extensions installation complete!"
}