PowerShell_Scripts/Edit-TextFile.ps1
lksz 06052cfa29 Reload-MyAliases is now Reload-MyScripts
🔖 https://blog.lksz.me/editing-with-ease/

✏️ Fixed $MyPSScriptRoot typo
 Get-ScopeDepth
🐛 Get-MyAliases didn't work correctly when sub-scoped, fixed the issue
🚚 Reload-MyAliases is now Reload-MyScripts
🐛 Reload-MyScripts loads scripts from $MyPSScriptRoot/profile.d subdir
📝 README updated to reflect change of script name and typo
2020-09-18 15:56:40 -04:00

25 linhas
550 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 = "sudo $editor"
}
$local:arguments = $Path -join "' '"
if( $Path ) { $arguments = "'$arguments'" }
if( $PSCmdlet.ShouldProcess( "Edit ($editor): $arguments" ) ) {
Invoke-Expression "$editor $arguments"
}