-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet_default_editor.ps1
More file actions
21 lines (20 loc) · 1012 Bytes
/
Copy pathSet_default_editor.ps1
File metadata and controls
21 lines (20 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Set default editor for .bat, .cmd and .ps1 "Edit" context menu option
#>
param ( $EditorPath, $Reset )
if ( $Reset -eq $true ) {
Remove-Item -Path 'HKCU:\Software\Classes\batfile\shell\edit' -Recurse
Remove-Item -Path 'HKCU:\Software\Classes\cmdfile\shell\edit' -Recurse
Remove-Item -Path 'HKCU:\Software\Classes\SystemFileAssociations\.ps1\shell\edit' -Recurse
exit
}
if ( $null -eq $EditorPath ) {
throw 'No editor path provided, input it as an argument'
}
[Environment]::SetEnvironmentVariable('EDITOR', "$EditorPath", 'User')
New-Item -Path 'HKCU:\Software\Classes\batfile\shell\edit\command' -Value '%EDITOR% %1' -ItemType ExpandString -Force
New-Item -Path 'HKCU:\Software\Classes\cmdfile\shell\edit\command' -Value '%EDITOR% %1' -ItemType ExpandString -Force
New-Item -Path 'HKCU:\Software\Classes\SystemFileAssociations\.ps1\shell\edit\command' -Value '%EDITOR% %1' -ItemType ExpandString -Force
Write-Warning -Message 'Reboot recommended'