diff --git a/base/Setup-MyPowerLineTheme.ps1 b/PowerLine/Setup-MyPowerLineTheme.ps1 similarity index 99% rename from base/Setup-MyPowerLineTheme.ps1 rename to PowerLine/Setup-MyPowerLineTheme.ps1 index 0196273..4282486 100644 --- a/base/Setup-MyPowerLineTheme.ps1 +++ b/PowerLine/Setup-MyPowerLineTheme.ps1 @@ -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" + diff --git a/PowerLine/_.package.json b/PowerLine/_.package.json new file mode 100644 index 0000000..a2193b3 --- /dev/null +++ b/PowerLine/_.package.json @@ -0,0 +1,19 @@ +{ + "package": { + "Name": "PowerLine", + "Condition": [ + { + "custom": null, + "System": null, + "Hostname": null, + "Username": null, + "ModuleExists": [ + "Pansies", + "PowerLine" + ], + "AppExeExists": null, + "Logic": 0 + } + ] + } +} diff --git a/PowerLine/profile.d/FixScoopBug.ps1 b/PowerLine/profile.d/FixScoopBug.ps1 new file mode 100644 index 0000000..2f863da --- /dev/null +++ b/PowerLine/profile.d/FixScoopBug.ps1 @@ -0,0 +1,3 @@ +Import-Module PowerLine +Import-Module Pansies +Get-Item alias:url | Where-Object Source -eq Pansies | % { Remove-Item "alias:$($_.Name)" } diff --git a/PowerLine/profile.d/Style.ps1 b/PowerLine/profile.d/Style.ps1 new file mode 100644 index 0000000..af9419e --- /dev/null +++ b/PowerLine/profile.d/Style.ps1 @@ -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 diff --git a/base/Get-MyModules.ps1 b/base/Get-MyModules.ps1 index 3e7c7da..569fec5 100644 --- a/base/Get-MyModules.ps1 +++ b/base/Get-MyModules.ps1 @@ -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" } diff --git a/base/profile.d/EnsureJoinString.ps1 b/base/profile.d/EnsureJoinString.ps1 index 7719e4b..77ab542 100644 --- a/base/profile.d/EnsureJoinString.ps1 +++ b/base/profile.d/EnsureJoinString.ps1 @@ -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" -} \ No newline at end of file +} diff --git a/base/profile.d/Style.ps1 b/base/profile.d/Style.ps1 index ecff929..5c98396 100644 --- a/base/profile.d/Style.ps1 +++ b/base/profile.d/Style.ps1 @@ -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 diff --git a/base/src/Packagesz.class.inc.ps1 b/base/src/Packagesz.class.inc.ps1 index 3c90b9d..4b70ec5 100644 --- a/base/src/Packagesz.class.inc.ps1 +++ b/base/src/Packagesz.class.inc.ps1 @@ -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 diff --git a/base/src/modules.json b/base/src/modules.json index 67dd7f7..d538b19 100644 --- a/base/src/modules.json +++ b/base/src/modules.json @@ -2,6 +2,7 @@ "Always": [ "psreadline", "PowerShellCookbook", + "Pansies", "PowerLine", "posh-git", "z"