Skip to content

Instantly share code, notes, and snippets.

@gsusI
Created August 31, 2023 08:39
Show Gist options
  • Save gsusI/e6a263cca78a1fd300f27112bb198147 to your computer and use it in GitHub Desktop.
Save gsusI/e6a263cca78a1fd300f27112bb198147 to your computer and use it in GitHub Desktop.
Integrate the Cursor application into the context menu. Adds "Open folder with Cursor" and "Open with Cursor"
# Function to backup registry
Function BackupRegistry($backupPath) {
try {
reg export HKCU\Software\Classes $backupPath /y
Add-Content -Path $logPath -Value "Registry backup created at $backupPath."
}
catch {
Add-Content -Path $logPath -Value "Failed to backup registry. Error: $_"
throw
}
}
Function CreateRegistryKey($path, $iconPath, $cmdPath, $cmdName) {
try {
if (Test-Path $path) {
Add-Content -Path $logPath -Value "$path already exists."
return
}
New-Item -Path $path -Force
Set-ItemProperty -Path $path -Name "Icon" -Value $iconPath
New-Item -Path "$path\command" -Force
Set-ItemProperty -Path "$path\command" -Name "(Default)" -Value $cmdPath
Add-Content -Path $logPath -Value "Created $path with $cmdName."
}
catch {
Add-Content -Path $logPath -Value "Failed to create $path. Error: $_"
throw
}
}
# Initialize
$basePath = "HKCU:\Software\Classes"
$iconPath = "$env:USERPROFILE\AppData\Local\Programs\cursor\cursor.ico"
$cursorExe = "$env:USERPROFILE\AppData\Local\Programs\cursor\cursor.exe"
$logPath = "$env:USERPROFILE\AppData\Local\Programs\cursor\log.txt"
$backupPath = "$env:USERPROFILE\AppData\Local\Programs\cursor\backup.reg"
# Error Handling for log path
if (-Not (Test-Path $logPath)) {
New-Item -Path $logPath -Force
}
# Backup registry
BackupRegistry $backupPath
# Create keys
CreateRegistryKey "$basePath\*\shell\Open with Cursor" $iconPath "$cursorExe `"%1`"" "File Command"
CreateRegistryKey "$basePath\Directory\shell\Open Folder with Cursor" $iconPath "$cursorExe `"%V`"" "Folder Command"
CreateRegistryKey "$basePath\Directory\Background\shell\Open Folder with Cursor" $iconPath "$cursorExe `"%V`"" "Folder Background Command"
# Final log
Add-Content -Path $logPath -Value "Script execution completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment