-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.ps1
40 lines (31 loc) · 1.13 KB
/
run.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$VimPath = "neovide.exe"
function Get-ContentWithoutTrailingNewline {
param (
[string]$Path
)
$content = Get-Content -Path $Path -Raw
$trimmedContent = $content.TrimEnd("`r", "`n")
return $trimmedContent
}
# Step 1: Copy selected content to clipboard
# Assuming the content is already in the clipboard
# If not, you might need to use a tool or method to copy it
# Step 2: Write clipboard content to a temporary file
$TempFile = "$env:LOCALAPPDATA\vim-anywhere"
$ClipboardContent = Get-Clipboard
Set-Content -Path $TempFile -Value $ClipboardContent
# Step 3: Find Neovim executable path
if (-not $VimPath) {
Write-Error "Neovim executable not found."
exit 1
}
# Step 4: Start Neovim with the temporary file
Start-Process -Wait -FilePath "$VimPath" -ArgumentList "$TempFile"
# Step 5: After Neovim closes, copy edited content back to clipboard
if (Test-Path -Path "$TempFile") {
$EditedContent = Get-ContentWithoutTrailingNewline -Path "$TempFile" -Raw
Set-Clipboard -Value $EditedContent
Remove-Item -Force -Path "$TempFile"
} else {
Write-Error "Temporary file not found or failed to create."
}