Updated edit.ps1

This commit is contained in:
Markus Fleschutz 2025-03-10 08:21:02 +01:00
parent 8928a3bce4
commit 8cb81aadac

View File

@ -18,7 +18,7 @@ param([string]$path = "")
function TryEditor { param([string]$editor, [string]$path) function TryEditor { param([string]$editor, [string]$path)
try { try {
Write-Host "$editor/" -noNewline Write-Host "$editor..." -noNewline
& $editor "$path" & $editor "$path"
if ($lastExitCode -ne 0) { "⚠️ Can't execute '$editor' - make sure it's installed and available"; exit 1 } if ($lastExitCode -ne 0) { "⚠️ Can't execute '$editor' - make sure it's installed and available"; exit 1 }
exit 0 # success exit 0 # success
@ -26,7 +26,8 @@ function TryEditor { param([string]$editor, [string]$path)
} }
if ($path -eq "" ) { $path = Read-Host "Enter the path to the text file" } if ($path -eq "" ) { $path = Read-Host "Enter the path to the text file" }
Write-Host "⏳ Editing 📄$path by trying " -noNewline if (-not(Test-Path "$path" -pathType leaf)) { throw "Can't access file '$path'" }
Write-Host "⏳ Editing '$path' by executing " -noNewline
TryEditor "neovim" $path TryEditor "neovim" $path
TryEditor "vim" $path TryEditor "vim" $path
TryEditor "vi" $path TryEditor "vi" $path
@ -39,4 +40,4 @@ TryEditor "wordpad.exe" $path
Write-Host "" Write-Host ""
"⚠️ Sorry, no text editor found. Please install your favorite one (e.g. by executing 'winget install helix.helix')." "⚠️ Sorry, no text editor found. Please install your favorite one (e.g. by executing 'winget install helix.helix')."
exit 1 exit 1