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

@ -61,3 +61,4 @@ $local:MyPowerLineSetup = [ordered]@{
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"

19
PowerLine/_.package.json Normal file
View File

@ -0,0 +1,19 @@
{
"package": {
"Name": "PowerLine",
"Condition": [
{
"custom": null,
"System": null,
"Hostname": null,
"Username": null,
"ModuleExists": [
"Pansies",
"PowerLine"
],
"AppExeExists": null,
"Logic": 0
}
]
}
}

View File

@ -0,0 +1,3 @@
Import-Module PowerLine
Import-Module Pansies
Get-Item alias:url | Where-Object Source -eq Pansies | % { Remove-Item "alias:$($_.Name)" }

View File

@ -0,0 +1,24 @@
if( -not (Get-Command -ListImported Set-PowerLinePrompt -ErrorAction Ignore) ) { return }
$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

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,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"