chore(cursor): improve setup script

This commit is contained in:
2025-02-19 19:29:34 +00:00
parent 03eb561f1f
commit 65bee1192e
2 changed files with 106 additions and 60 deletions

View File

@@ -1,5 +1,5 @@
# Cursor Extensions # Cursor Extensions
# Generated on Wed Feb 19 19:05:55 GMT 2025 # Generated on Wed Feb 19 19:29:16 GMT 2025
alefragnani.project-manager alefragnani.project-manager
antiantisepticeye.vscode-color-picker antiantisepticeye.vscode-color-picker

View File

@@ -1,44 +1,73 @@
#! /usr/bin/env bash #! /usr/bin/env bash
# Define source directory # ==============================================================================
# Settings
# ==============================================================================
# List of config files to symlink from current directory.
CONFIG_SOURCES=(
"settings.json"
"keybindings.json"
"snippets"
)
# Detect current script directory.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
_CURSOR_CONFIG_DIR="" # ==============================================================================
# Determine OS and set config directory # Help
cursor_config_dir() { # ==============================================================================
if [[ -n "${_CURSOR_CONFIG_DIR}" ]]; then
echo "${_CURSOR_CONFIG_DIR}"
return
fi
show_help() {
cat <<EOF
Usage: $(basename "$0") COMMAND
Commands:
config, conf Create symlinks for Cursor config files
dump-extensions, dump Export installed Cursor extensions to extensions.txt
extensions, ext Install Cursor extensions from extensions.txt
Description:
This script manages Cursor editor configuration files and extensions.
It can create symlinks for settings, keybindings, and snippets,
as well as backup and restore extensions.
EOF
}
# ==============================================================================
# Functions
# ==============================================================================
# Determine Cursor config directory.
cursor_config_dir() {
case "$(uname -s)" in case "$(uname -s)" in
"Darwin") "Darwin")
_CURSOR_CONFIG_DIR="${HOME}/Library/Application Support/Cursor/User" echo "${HOME}/Library/Application Support/Cursor/User"
;; ;;
"Linux") "Linux")
_CURSOR_CONFIG_DIR="${HOME}/.config/Cursor/User" echo "${HOME}/.config/Cursor/User"
;; ;;
*) *)
echo "Error: Unsupported operating system" echo "Error: Unsupported operating system"
exit 1 exit 1
;; ;;
esac esac
echo "${_CURSOR_CONFIG_DIR}"
} }
# Function to backup and symlink # Backup and symlink
backup_and_link() { backup_and_link() {
local source="$1" local source="$1"
local target="$2" local target="$2"
local real_target
local real_source
# Check if target already exists # Check if target already exists
if [[ -e "${target}" ]]; then if [[ -e "${target}" ]]; then
# If it's a symlink, check if it points to the same location # If it's a symlink, check if it points to the same location
if [[ -L "${target}" ]]; then if [[ -L "${target}" ]]; then
local current_target real_target="$(readlink -f "${target}")"
current_target="$(readlink "${target}")" real_source="$(readlink -f "${source}")"
if [[ "${current_target}" == "${source}" ]]; then if [[ "${real_target}" == "${real_source}" ]]; then
echo "Skipping ${target} - already linked to ${source}" echo "Skipping ${target} - already linked to ${source}"
return return
fi fi
@@ -53,48 +82,62 @@ backup_and_link() {
ln -s "${source}" "${target}" ln -s "${source}" "${target}"
} }
# Function to create symlinks # Create symlinks
do_symlink() { do_symlink() {
# Create Cursor config directory if it doesn't exist # Create Cursor config directory if it doesn't exist
local config_dir local config_dir
config_dir="$(cursor_config_dir)" config_dir="$(cursor_config_dir)"
mkdir -p "${config_dir}" mkdir -p "${config_dir}"
for path in "${CONFIG_SOURCES[@]}"; do
# Backup and symlink settings.json backup_and_link "${SCRIPT_DIR}/${path}" "${config_dir}/${path}"
backup_and_link "${SCRIPT_DIR}/settings.json" "${config_dir}/settings.json" done
# Backup and symlink keybindings.json
backup_and_link "${SCRIPT_DIR}/keybindings.json" "${config_dir}/keybindings.json"
# Backup and symlink snippets directory
backup_and_link "${SCRIPT_DIR}/snippets" "${config_dir}/snippets"
echo "Symlink setup complete!" echo "Symlink setup complete!"
} }
# Replace do_dump_extensions function: # Find the cursor CLI command
do_dump_extensions() { find_cursor_cmd() {
if ! command -v cursor >/dev/null 2>&1; then local cursor_cmd=""
echo "Error: cursor command not found"
# Check for cursor CLI in multiple possible locations
for cmd in "cursor" "/Applications/Cursor.app/Contents/Resources/app/bin/cursor" "${HOME}/Applications/Cursor.app/Contents/Resources/app/bin/cursor"; do
if command -v "${cmd}" >/dev/null 2>&1; then
cursor_cmd="${cmd}"
break
fi
done
if [[ -z "${cursor_cmd}" ]]; then
echo "Error: cursor command not found" >&2
exit 1 exit 1
fi fi
echo "${cursor_cmd}"
}
# Dump installed extensions to extensions.txt
do_dump_extensions() {
local cursor_cmd
cursor_cmd="$(find_cursor_cmd)"
local extensions_file="${SCRIPT_DIR}/extensions.txt" local extensions_file="${SCRIPT_DIR}/extensions.txt"
local current_date local current_date
current_date="$(date)" current_date="$(date)"
{ {
echo "# Cursor Extensions" echo "# Cursor Extensions"
echo "# Generated on ${current_date}" echo "# Generated on ${current_date}"
echo echo
cursor --list-extensions "${cursor_cmd}" --list-extensions
} >"${extensions_file}" } >"${extensions_file}"
echo "Extensions list dumped to ${extensions_file}" echo "Extensions list dumped to ${extensions_file}"
} }
# Function to install extensions # Install extensions from extensions.txt
do_install_extensions() { do_install_extensions() {
local cursor_cmd
cursor_cmd="$(find_cursor_cmd)"
local extensions_file="${SCRIPT_DIR}/extensions.txt" local extensions_file="${SCRIPT_DIR}/extensions.txt"
if [[ ! -f "${extensions_file}" ]]; then if [[ ! -f "${extensions_file}" ]]; then
@@ -104,39 +147,42 @@ do_install_extensions() {
# Read extensions file, skip comments and empty lines # Read extensions file, skip comments and empty lines
while IFS= read -r line; do while IFS= read -r line; do
if [[ -n "${line}" && ! "${line}" =~ ^# ]]; then if [[ -n "${line}" && ! "${line}" =~ ^[[:space:]]*# ]]; then
echo "Installing extension: ${line}" echo "Installing extension: ${line}"
cursor --install-extension "${line}" "${cursor_cmd}" --install-extension "${line}"
fi fi
done <"${extensions_file}" done <"${extensions_file}"
echo "Extensions installation complete!" echo "Extensions installation complete!"
} }
# Help message function # ==============================================================================
show_help() { # Main
echo "Available commands: symlink (or link), dump-extensions, install-extensions" # ==============================================================================
main() {
case "${1:-}" in
"config" | "conf")
do_symlink
;;
"dump-extensions" | "dump")
do_dump_extensions
;;
"extensions" | "ext")
do_install_extensions
;;
"")
echo "Error: No command provided"
show_help
exit 1
;;
*)
echo "Error: Unknown command '$1'"
show_help
exit 1
;;
esac
} }
# Main command handler # Run main function.
case "${1:-}" in main "$@"
"symlink" | "link")
do_symlink
;;
"dump-extensions" | "dump")
do_dump_extensions
;;
"install-extensions" | "install")
do_install_extensions
;;
"")
echo "Error: No command provided"
show_help
exit 1
;;
*)
echo "Error: Unknown command '$1'"
show_help
exit 1
;;
esac