26 lines
563 B
PowerShell
26 lines
563 B
PowerShell
[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"
|
|
}
|