Introducting PowerLine module

Added ExistingModules to packages, for module dependent package manifest
Moved PowerLine styling code to the PowerLine pacakge.
Added Package install code generation to Get-MyModules.
Fixed typo in EnsureJoinString
Fixed: Scoop operations would fail calling internal url function.
This commit is contained in:
Gal 2021-10-29 13:31:24 -04:00
parent c7ec1e8c5d
commit b0ec8e1780
9 changed files with 68 additions and 29 deletions

View file

@ -1,4 +1,4 @@
param([switch]$IgnoreSystem,[switch]$MissingOnly)
param([switch]$IgnoreSystem,[switch]$MissingOnly,[switch]$GenInstallCode)
$local:currentSys = @('Always') + ([SystemName]::_GetValidValues('',$true,$true));
@ -9,6 +9,7 @@ $local:oldPSGet = Get-Module PowerShellGet -ListAvailable -ErrorAction SilentlyC
if( $local:oldPSGet ) {
Write-Warning $(@(
"PowerShellGet is an old version ($($oldPSGet.Version)), the following code should upgrade it"
, "# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
, " [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
, " Install-PackageProvider -Name NuGet -Force"
, " Remove-Module PowerShellGet"
@ -17,6 +18,10 @@ if( $local:oldPSGet ) {
) -join "`n" )
}
if( $GenInstallCode ) {
$MissingOnly = $true
"# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
}
[MyConfig]::GetConfigPaths('mymodules',$false) |
ForEach-Object {
$local:modules = $( Get-Content $_ | ConvertFrom-Json );
@ -33,4 +38,8 @@ if( $local:oldPSGet ) {
-not (Get-Module -ListAvailable $_ -ErrorAction stop)
} catch { $true }
)
} | ForEach-Object {
if( -not $GenInstallCode ) { return $_ }
"Write-Host -ForegroundColor Cyan 'Installing $_...';"
"Install-Module $_ -AllowClobber"
}

View file

@ -1,63 +0,0 @@
Set-PowerLinePrompt -PowerLineFont
$local:MyPowerLineSetup = [ordered]@{
Title = { "PSz" }
SetCurrentDirectory = $true
RestoreVirtualTerminal = $true
PowerLineCharacters = [ordered]@{
ColorSeparator = "$(
$PromptCache.ColorFiller
)$( $PromptCache.Separator.Trim()
)$( " "
)"
ReverseColorSeparator = "$(
" "
)$( $PromptCache.ReverseSeparator.Trim()
)$( $PromptCache.ColorFiller
)"
Separator = $(
[PoshCode.Pansies.Entities]::NerdFonts['nf-fa-angle_right']
)
ReverseSeparator = $(
[PoshCode.Pansies.Entities]::NerdFonts['nf-fa-angle_left']
)
}
Colors = [PoshCode.Pansies.RgbColor]::X11Palette |
Where-Object X11ColorName -match "^Gray\d" |
Sort-Object X11ColorName -Unique |
Where-Object {
0 -eq $([int]($_.X11ColorName -replace 'Gray','') % 11)
}
#@( [rgbcolor]"Grey18", [rgbcolor]"Grey65" )
#([rgbcolor]::ConsolePalette | Where ConsoleColor -eq ((get-host).ui.rawui.BackgroundColor)),
#@( [rgbcolor]"Grey18", [rgbcolor]"Grey65" ) #, [rgbcolor]"white", [rgbcolor]"red", [rgbcolor]"blue" )
Prompt = @(
{ Write-Host "" } # A spaced line without a ColorSeparator
{ New-PromptText -EBg VioletRed4 $MyInvocation.HistoryId }
{ Get-SegmentedPath -LengthLimit 37 }
{ Write-VcsStatus }
# Right-align block
{ "`t" }
{ "$($PromptCache.Username)@$($PromptCache.Hostname)" }
{
(Get-Elapsed -Format "{0:d\:h\:m\:s\.ffff}") `
-replace '\.(\d{1,3})\d*$','s $1ms' `
-replace '\:([^:]*)$','m $1' `
-replace ':([^:]*)','d $1' `
-replace '\b0+[dms]\b ','' `
-replace '( ?)\b0+(\d+ms)$','$1$2' `
-replace ' ?0ms','' `
-replace '^ *$','0'
}
{ Get-Date -Format 'HH:mm:ss' }
{ Get-Date -Format 'ddd(dd)' }
{ "$($PromptCache.OSName) " }
{ "`n" }
{ New-PromptText { "PS" } -Bg $Prompt.Colors[1] -Ebg Red; }
)
}
Set-PowerLinePrompt @MyPowerLineSetup
Write-Host -ForegroundColor Cyan "PowerLine Theme is ready, if you want to persist it, don't forget to run Export-PowerLinePrompt`n"

View file

@ -1,6 +1,6 @@
if( -not (Get-Command -ListImported Join-String -ErrorAction SilentlyContinue) ) {
if( -not (Get-Module -ListAvailable -Name "string") ) {
Write-Warning 'Join-String Command is missing, attempting to install stirng module'
Write-Warning 'Join-String Command is missing, attempting to install string module'
$local:moduleScope = "CurrentUser"
if( Test-IsAdmin ) { $moduleScope = "AllUsers" }
Install-Module -Name "string" -Scope $moduleScope -AllowClobber -ErrorAction SilentlyContinue
@ -9,4 +9,4 @@ if( -not (Get-Command -ListImported Join-String -ErrorAction SilentlyContinue) )
Write-Error "Failed to locate/install the module 'string'"
}
Import-Module -Name "string" -Cmdlet "Join-String"
}
}

View file

@ -32,30 +32,7 @@ Get-Command -ListImported Get-GitDirectory -ErrorAction Ignore |
}
}
if( (Get-Command -ListImported Set-PowerLinePrompt -ErrorAction Ignore) ) {
$global:PromptCache = [ordered]@{
OSName = [SystemName]::_GetValidValues("",$true,$true) | Select-Object -First 1
Username = @($env:USER, $env:USERNAME -ne "")[0]
Hostname = $(hostname).Trim()
ColorFiller = $([char]0x2588)
Separator = " $(
[PoshCode.Pansies.Entities]::NerdFonts['nf-pl-left_hard_divider']
)"
ReverseSeparator = "$(
[PoshCode.Pansies.Entities]::NerdFonts['nf-pl-right_hard_divider']
) "
# Separator = "$(
# [char]::ConvertFromUtf32(0x2588)
# )$( [PoshCode.Pansies.Entities]::ExtendedCharacters.ColorSeparator.Trim()[-1]
# ) "
# ReverseSeparator = " $(
# [PoshCode.Pansies.Entities]::ExtendedCharacters.ColorSeparator.Trim()[0]
# )$( [char]::ConvertFromUtf32(0x2588))"
}
Set-PowerLinePrompt
} elseif( (Get-Command -ListImported Set-PoshPrompt -ErrorAction Ignore) -and $IsOutputANSICompatible ) {
if( (Get-Command -ListImported Set-PoshPrompt -ErrorAction Ignore) -and $IsOutputANSICompatible ) {
$local:poshPrompt = Join-Path $HOME ".oh-my-posh.omp.json"
if( -not (Test-Path $poshPrompt) ) { $poshPrompt = "slim" }
Set-PoshPrompt -Theme $poshPrompt

View file

@ -22,12 +22,13 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
if( -not $Package.Condition ) { return $true }
$local:badCnd = $Package.Condition |
Get-Member -MemberType NoteProperty |
Where-Object Name -notin ('Logic', 'custom', 'System','Hostname','Username','CmdletExists','AppExeExists')
Where-Object Name -notin ('Logic', 'custom', 'System','Hostname','Username','CmdletExists','ModuleExists','AppExeExists')
if( $badCnd ) { Write-Warning "Bad conditions for Package $($Package.name): $($badCnd.Name -join ', ')"; return $false }
$local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot)
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
$local:hostname = $(hostname)
$local:allCmdlets = Get-Command -ListImported | Select-Object -ExpandProperty Name
$local:allCmdlets = Get-Command -ListImported | Select-Object -ExpandProperty Name -Unique
$local:allModules = Get-Module -ListAvailable | Select-Object -ExpandProperty Name -Unique
$local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } )
@ -47,6 +48,9 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
if( $v -and $c.CmdletExists ) {
$v = $v -and -not $($c.CmdletExists | Where-Object { $allCmdlets -notcontains $_ })
}
if( $v -and $c.ModuleExists ) {
$v = $v -and -not $($c.ModuleExists | Where-Object { $allModules -notcontains $_ })
}
if( $v -and $c.AppExeExists ) {
$v = $v -and -not $($c.AppExeExists | Where-Object {
-not ( Get-Command -ListImported $_ -Type Application -ErrorAction SilentlyContinue )
@ -92,6 +96,7 @@ class szCondition {
[string[]]$Hostname = $null
[string[]]$Username = $null
[string[]]$CmdletExists = $null
[string[]]$ModuleExists = $null
[string[]]$AppExeExists = $null
[szLogic]$Logic = [szLogic]::and

View file

@ -2,6 +2,7 @@
"Always": [
"psreadline",
"PowerShellCookbook",
"Pansies",
"PowerLine",
"posh-git",
"z"