Added Edit-TextFile
Este cometimento está contido em:
ascendente
ae07e06c27
cometimento
a4bdd9c9a5
1 ficheiros modificados com 25 adições e 0 eliminações
25
Edit-TextFile.ps1
Ficheiro normal
25
Edit-TextFile.ps1
Ficheiro normal
|
@ -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"
|
||||
}
|
Carregando…
Adicionar tabela
Adicionar uma ligação
Criar uma nova questão referindo esta