Skip to content

Instantly share code, notes, and snippets.

@pleabargain
Created February 10, 2025 18:57
Show Gist options
  • Save pleabargain/be8ee8dab1e15f63210da39f99ac1830 to your computer and use it in GitHub Desktop.
Save pleabargain/be8ee8dab1e15f63210da39f99ac1830 to your computer and use it in GitHub Desktop.
right click ps1 open with cursor IDE
# Requires administrator privileges to modify registry
#Requires -RunAsAdministrator
# Script to add "Edit with Cursor" context menu for .ps1 files
try {
# Get Cursor installation path
$cursorPath = "$env:LOCALAPPDATA\Programs\cursor\Cursor.exe"
# Verify Cursor exists
if (-not (Test-Path $cursorPath)) {
Write-Error "Cursor is not installed at the expected location: $cursorPath"
exit 1
}
# Register Cursor in the Applications key
$cursorAppKey = "Registry::HKEY_CLASSES_ROOT\Applications\Cursor.exe"
$cursorShellKey = "$cursorAppKey\shell"
$cursorOpenKey = "$cursorShellKey\open"
$cursorCommandKey = "$cursorOpenKey\command"
# Create necessary keys
New-Item -Path $cursorAppKey -Force | Out-Null
New-Item -Path $cursorShellKey -Force | Out-Null
New-Item -Path $cursorOpenKey -Force | Out-Null
New-Item -Path $cursorCommandKey -Force | Out-Null
# Set default values
Set-ItemProperty -Path $cursorOpenKey -Name "(Default)" -Value "Edit with Cursor" -Force
Set-ItemProperty -Path $cursorCommandKey -Name "(Default)" -Value "`"$cursorPath`" `"%1`"" -Force
# Add Cursor to .ps1 OpenWithProgids
$ps1Key = "Registry::HKEY_CLASSES_ROOT\.ps1"
$openWithKey = "$ps1Key\OpenWithProgids"
if (-not (Test-Path $openWithKey)) {
New-Item -Path $openWithKey -Force | Out-Null
}
# Add Cursor.exe as an OpenWithProgid
Set-ItemProperty -Path $openWithKey -Name "Cursor.exe" -Value "" -Type String -Force
Write-Host "Successfully added 'Edit with Cursor' to the context menu for PowerShell scripts."
# Restart Windows Explorer to refresh context menu
Write-Host "Refreshing Windows Shell..."
Stop-Process -Name "explorer" -Force -ErrorAction SilentlyContinue
Start-Process "explorer"
Write-Host "Context menu has been updated. Please right-click any .ps1 file to see the new option."
} catch {
Write-Error "An error occurred while modifying the registry: $_"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment