Added Edit-TextFile

This commit is contained in:
lksz 2020-09-29 16:50:19 -04:00
parent ae07e06c27
commit a4bdd9c9a5
1 changed files with 25 additions and 0 deletions

25
Edit-TextFile.ps1 Normal file
View File

@ -0,0 +1,25 @@
[CmdletBinding(SupportsShouldProcess)]param(
[switch]$sudo,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$Path
)
$local:editor = '/bin/nvim'
if( (Test-Path env:EDITOR) -and (Test-Path $env:EDITOR) ) {
$editor = $env:EDITOR;
}
if( $editor -match 'vim?$' ) {
$editor += ' -p'
}
if( $sudo ) {
$editor = "/usr/bin/env sudo $editor"
}
$local:arguments = $Path -join "' '"
if( $Path ) { $arguments = "'$arguments'" }
if( $PSCmdlet.ShouldProcess( "Edit ($editor): $arguments" ) ) {
Invoke-Expression "$editor $arguments"
}