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:
parent
c7ec1e8c5d
commit
b0ec8e1780
|
@ -61,3 +61,4 @@ $local:MyPowerLineSetup = [ordered]@{
|
||||||
Set-PowerLinePrompt @MyPowerLineSetup
|
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"
|
Write-Host -ForegroundColor Cyan "PowerLine Theme is ready, if you want to persist it, don't forget to run Export-PowerLinePrompt`n"
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"package": {
|
||||||
|
"Name": "PowerLine",
|
||||||
|
"Condition": [
|
||||||
|
{
|
||||||
|
"custom": null,
|
||||||
|
"System": null,
|
||||||
|
"Hostname": null,
|
||||||
|
"Username": null,
|
||||||
|
"ModuleExists": [
|
||||||
|
"Pansies",
|
||||||
|
"PowerLine"
|
||||||
|
],
|
||||||
|
"AppExeExists": null,
|
||||||
|
"Logic": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
Import-Module PowerLine
|
||||||
|
Import-Module Pansies
|
||||||
|
Get-Item alias:url | Where-Object Source -eq Pansies | % { Remove-Item "alias:$($_.Name)" }
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
||||||
param([switch]$IgnoreSystem,[switch]$MissingOnly)
|
param([switch]$IgnoreSystem,[switch]$MissingOnly,[switch]$GenInstallCode)
|
||||||
|
|
||||||
$local:currentSys = @('Always') + ([SystemName]::_GetValidValues('',$true,$true));
|
$local:currentSys = @('Always') + ([SystemName]::_GetValidValues('',$true,$true));
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ $local:oldPSGet = Get-Module PowerShellGet -ListAvailable -ErrorAction SilentlyC
|
||||||
if( $local:oldPSGet ) {
|
if( $local:oldPSGet ) {
|
||||||
Write-Warning $(@(
|
Write-Warning $(@(
|
||||||
"PowerShellGet is an old version ($($oldPSGet.Version)), the following code should upgrade it"
|
"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"
|
, " [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
|
||||||
, " Install-PackageProvider -Name NuGet -Force"
|
, " Install-PackageProvider -Name NuGet -Force"
|
||||||
, " Remove-Module PowerShellGet"
|
, " Remove-Module PowerShellGet"
|
||||||
|
@ -17,6 +18,10 @@ if( $local:oldPSGet ) {
|
||||||
) -join "`n" )
|
) -join "`n" )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( $GenInstallCode ) {
|
||||||
|
$MissingOnly = $true
|
||||||
|
"# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
|
||||||
|
}
|
||||||
[MyConfig]::GetConfigPaths('mymodules',$false) |
|
[MyConfig]::GetConfigPaths('mymodules',$false) |
|
||||||
ForEach-Object {
|
ForEach-Object {
|
||||||
$local:modules = $( Get-Content $_ | ConvertFrom-Json );
|
$local:modules = $( Get-Content $_ | ConvertFrom-Json );
|
||||||
|
@ -33,4 +38,8 @@ if( $local:oldPSGet ) {
|
||||||
-not (Get-Module -ListAvailable $_ -ErrorAction stop)
|
-not (Get-Module -ListAvailable $_ -ErrorAction stop)
|
||||||
} catch { $true }
|
} catch { $true }
|
||||||
)
|
)
|
||||||
|
} | ForEach-Object {
|
||||||
|
if( -not $GenInstallCode ) { return $_ }
|
||||||
|
"Write-Host -ForegroundColor Cyan 'Installing $_...';"
|
||||||
|
"Install-Module $_ -AllowClobber"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
if( -not (Get-Command -ListImported Join-String -ErrorAction SilentlyContinue) ) {
|
if( -not (Get-Command -ListImported Join-String -ErrorAction SilentlyContinue) ) {
|
||||||
if( -not (Get-Module -ListAvailable -Name "string") ) {
|
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"
|
$local:moduleScope = "CurrentUser"
|
||||||
if( Test-IsAdmin ) { $moduleScope = "AllUsers" }
|
if( Test-IsAdmin ) { $moduleScope = "AllUsers" }
|
||||||
Install-Module -Name "string" -Scope $moduleScope -AllowClobber -ErrorAction SilentlyContinue
|
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'"
|
Write-Error "Failed to locate/install the module 'string'"
|
||||||
}
|
}
|
||||||
Import-Module -Name "string" -Cmdlet "Join-String"
|
Import-Module -Name "string" -Cmdlet "Join-String"
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,30 +32,7 @@ Get-Command -ListImported Get-GitDirectory -ErrorAction Ignore |
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (Get-Command -ListImported Set-PowerLinePrompt -ErrorAction Ignore) ) {
|
if( (Get-Command -ListImported Set-PoshPrompt -ErrorAction Ignore) -and $IsOutputANSICompatible ) {
|
||||||
$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 ) {
|
|
||||||
$local:poshPrompt = Join-Path $HOME ".oh-my-posh.omp.json"
|
$local:poshPrompt = Join-Path $HOME ".oh-my-posh.omp.json"
|
||||||
if( -not (Test-Path $poshPrompt) ) { $poshPrompt = "slim" }
|
if( -not (Test-Path $poshPrompt) ) { $poshPrompt = "slim" }
|
||||||
Set-PoshPrompt -Theme $poshPrompt
|
Set-PoshPrompt -Theme $poshPrompt
|
||||||
|
|
|
@ -22,12 +22,13 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||||
if( -not $Package.Condition ) { return $true }
|
if( -not $Package.Condition ) { return $true }
|
||||||
$local:badCnd = $Package.Condition |
|
$local:badCnd = $Package.Condition |
|
||||||
Get-Member -MemberType NoteProperty |
|
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 }
|
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:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot)
|
||||||
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
|
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
|
||||||
$local:hostname = $(hostname)
|
$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 } )
|
$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 ) {
|
if( $v -and $c.CmdletExists ) {
|
||||||
$v = $v -and -not $($c.CmdletExists | Where-Object { $allCmdlets -notcontains $_ })
|
$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 ) {
|
if( $v -and $c.AppExeExists ) {
|
||||||
$v = $v -and -not $($c.AppExeExists | Where-Object {
|
$v = $v -and -not $($c.AppExeExists | Where-Object {
|
||||||
-not ( Get-Command -ListImported $_ -Type Application -ErrorAction SilentlyContinue )
|
-not ( Get-Command -ListImported $_ -Type Application -ErrorAction SilentlyContinue )
|
||||||
|
@ -92,6 +96,7 @@ class szCondition {
|
||||||
[string[]]$Hostname = $null
|
[string[]]$Hostname = $null
|
||||||
[string[]]$Username = $null
|
[string[]]$Username = $null
|
||||||
[string[]]$CmdletExists = $null
|
[string[]]$CmdletExists = $null
|
||||||
|
[string[]]$ModuleExists = $null
|
||||||
[string[]]$AppExeExists = $null
|
[string[]]$AppExeExists = $null
|
||||||
[szLogic]$Logic = [szLogic]::and
|
[szLogic]$Logic = [szLogic]::and
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"Always": [
|
"Always": [
|
||||||
"psreadline",
|
"psreadline",
|
||||||
"PowerShellCookbook",
|
"PowerShellCookbook",
|
||||||
|
"Pansies",
|
||||||
"PowerLine",
|
"PowerLine",
|
||||||
"posh-git",
|
"posh-git",
|
||||||
"z"
|
"z"
|
||||||
|
|
Loading…
Reference in New Issue