A lot of changes
+ PowerLine prompt now shows degraded systemctl state (When Apllicable) + Get-PlexInfo notifies if PLEX creds are needed and are missing + XDG env are setup if missing on linux + vi/vim command will launch editor, but prefer vi/vim/nvim if exists + new chezmoi package: auto loading completion + new flatpak package: List and Kill commands added + new zfs package: zls command added
This commit is contained in:
parent
cdabbc7858
commit
4bf2ff19f4
15 changed files with 188 additions and 42 deletions
|
@ -1 +1 @@
|
|||
Edit-TextFile
|
||||
prefervi
|
|
@ -1 +1 @@
|
|||
Edit-TextFile
|
||||
prefervi
|
||||
|
|
|
@ -1,53 +1,56 @@
|
|||
[CmdletBinding(SupportsShouldProcess)]param(
|
||||
[switch]$sudo,
|
||||
[Parameter(Position = 0, ValueFromPipelineByPropertyName, ValueFromPipeline, ValueFromRemainingArguments = $true)]
|
||||
[string[]]$Path
|
||||
[switch]$sudo,
|
||||
[Parameter(Position = 0, ValueFromPipelineByPropertyName, ValueFromPipeline, ValueFromRemainingArguments = $true)]
|
||||
[string[]]$Path,
|
||||
[string[]]$PreferredEditors
|
||||
)
|
||||
|
||||
begin {
|
||||
$global:WaitForEditor = (($WaitForEditor, -1 -ne $null)[0], 5 -ne -1)[0]
|
||||
$PathForEditor = @()
|
||||
$global:WaitForEditor = (($WaitForEditor, -1 -ne $null)[0], 5 -ne -1)[0]
|
||||
$PathForEditor = @()
|
||||
}
|
||||
process {
|
||||
foreach( $local:P in $Path ) {
|
||||
$PathForEditor += $P | Get-Path -Expand
|
||||
}
|
||||
foreach ( $local:P in $Path ) {
|
||||
$PathForEditor += $P | Get-Path -Expand
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
$local:editors = $env:EDITOR,'nvim','codium','code'
|
||||
$local:editor = $null
|
||||
foreach( $local:testEditor in $editors ) {
|
||||
if( $(try{Get-Command -ListImported -Type Application $testEditor -ErrorAction SilentlyContinue}catch{}) ) {
|
||||
$editor = "`"$testEditor`""
|
||||
break;
|
||||
$local:editors = $PreferredEditors + @(
|
||||
$env:EDITOR, 'nvim', 'vim', 'vi', 'codium', 'code', 'notepad'
|
||||
) | Where-Object { $_ }
|
||||
$local:editor = $null
|
||||
foreach ( $local:testEditor in $editors ) {
|
||||
if ( $(try { Get-Command -ListImported -Type Application $testEditor -ErrorAction SilentlyContinue }catch {}) ) {
|
||||
$editor = "`"$testEditor`""
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( $editor -match 'vim?"$' ) {
|
||||
$editor += ' -p'
|
||||
}
|
||||
|
||||
if( $EditorProcessName ) {
|
||||
if( -not (Get-Process -Name $EditorProcessName -ErrorAction SilentlyContinue) ) {
|
||||
Invoke-ExpressionEx -sudo:$sudo "& $editor"
|
||||
while( -not (Get-Process -Name $EditorProcessName -ErrorAction SilentlyContinue) ) {
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
Write-Host -ForegroundColor DarkCyan "Please wait, initializing editor..."
|
||||
Start-Sleep -Seconds $WaitForEditor
|
||||
if( Test-Path variable:EditorWaitStopWatch ) {
|
||||
$EditorWaitStopWatch.Restart()
|
||||
}
|
||||
if ( $editor -match 'vim"$' ) {
|
||||
$editor += ' -p'
|
||||
}
|
||||
}
|
||||
|
||||
Write-Verbose $($Path | Out-String)
|
||||
if ( $EditorProcessName ) {
|
||||
if ( -not (Get-Process -Name $EditorProcessName -ErrorAction SilentlyContinue) ) {
|
||||
Invoke-ExpressionEx -sudo:$sudo "& $editor"
|
||||
while ( -not (Get-Process -Name $EditorProcessName -ErrorAction SilentlyContinue) ) {
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
Write-Host -ForegroundColor DarkCyan "Please wait, initializing editor..."
|
||||
Start-Sleep -Seconds $WaitForEditor
|
||||
if ( Test-Path variable:EditorWaitStopWatch ) {
|
||||
$EditorWaitStopWatch.Restart()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$local:arguments = $PathForEditor | Foreach-Object { "'$_'" }
|
||||
if( $Path ) { $arguments = "$arguments" }
|
||||
Write-Verbose $($Path | Out-String)
|
||||
|
||||
if( $PSCmdlet.ShouldProcess( "Edit ($editor): $arguments" ) ) {
|
||||
Invoke-ExpressionEx -sudo:$sudo "& $editor $arguments"
|
||||
}
|
||||
$local:arguments = $PathForEditor | Foreach-Object { "'$_'" }
|
||||
if ( $Path ) { $arguments = "$arguments" }
|
||||
|
||||
if ( $PSCmdlet.ShouldProcess( "Edit ($editor): $arguments" ) ) {
|
||||
Invoke-ExpressionEx -sudo:$sudo "& $editor $arguments"
|
||||
}
|
||||
}
|
||||
|
|
6
base/prefervi.ps1
Normal file
6
base/prefervi.ps1
Normal file
|
@ -0,0 +1,6 @@
|
|||
[CmdletBinding(SupportsShouldProcess)]param(
|
||||
[switch]$sudo,
|
||||
[Parameter(Position = 0, ValueFromPipelineByPropertyName, ValueFromPipeline, ValueFromRemainingArguments = $true)]
|
||||
[string[]]$Path
|
||||
)
|
||||
Edit-TextFile -sudo:$sudo -PreferredEditors "nvim","vim","vi" -Path $Path
|
Loading…
Add table
Add a link
Reference in a new issue