Last active
October 29, 2021 20:40
-
-
Save dwettstein/6a01af11f830b96d686e12500e7c7d0b to your computer and use it in GitHub Desktop.
With this registry command you can create a Windows Explorer context menu entry "Edit file with WSL Vim" using Vim on WSL (Windows Subsystem for Linux).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
With this registry command you can create a Windows Explorer context menu | |
entry "Edit file with WSL Vim" using Vim on WSL (Windows Subsystem for Linux). | |
.DESCRIPTION | |
With this registry command you can create a Windows Explorer context menu | |
entry "Edit file with WSL Vim" using Vim on WSL (Windows Subsystem for Linux). | |
You can execute the context-menu entry quickly with the keyboard-shortcut | |
`Shift`+`F10`, `w` (on Windows 7 also: `Alt`+`f`, `w`), after selecting | |
the file. | |
File-Name: Edit_with_Vim_WSL.ps1 | |
Author: David Wettstein | |
Version: 1.3.0 | |
Changelog: | |
1.3.0, 2021-10-29, David Wettstein: Use bash.exe and update text | |
1.2.0, 2021-07-13, David Wettstein: Use wslpath to convert path | |
1.1.0, 2020-05-26, David Wettstein: Improve and use ubuntu.exe | |
1.0.0, 2018-03-11, David Wettstein: First implementation | |
.NOTES | |
Copyright (c) 2018-2021 David Wettstein, | |
licensed under the MIT License (https://dwettstein.mit-license.org/) | |
.LINK | |
https://gist.github.com/dwettstein/6a01af11f830b96d686e12500e7c7d0b | |
#> | |
[CmdletBinding()] | |
[OutputType([String])] | |
param () | |
begin { | |
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | |
$KeyPath = "HKCR:\*\shell\Vim_WSL" | |
$CommandPath = "$KeyPath\command" | |
} | |
process { | |
if (-not (Test-Path -LiteralPath $KeyPath)) { | |
New-Item -Path $KeyPath | |
} | |
if (-not (Test-Path -LiteralPath $CommandPath)) { | |
New-Item -Path $CommandPath | |
} | |
New-ItemProperty -LiteralPath $KeyPath -Name "(Default)" -Value "Edit with Vim on &WSL" -PropertyType String -Force | |
New-ItemProperty -LiteralPath $KeyPath -Name "Icon" -Value "C:\Windows\System32\wsl.exe" -PropertyType String -Force | |
New-ItemProperty -LiteralPath $CommandPath -Name "(Default)" -Value "`"C:\Windows\System32\bash.exe`" -c `"vim \`"`$(wslpath '%1')\`"`"" -PropertyType ExpandString -Force | |
# `"vim \`"`$(echo '%1' | sed 's/\\/\//g' | sed 's/C:/\/mnt\/c/g' | sed 's/D:/\/mnt\/d/g')\`"`" | |
# vim "$(echo '%1' | sed 's/\\/\//g' | sed 's/C:/\/mnt\/c/g' | sed 's/D:/\/mnt\/d/g')" | |
} | |
end {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment