From 86c118921124199a91087435cf5eee9df266216b Mon Sep 17 00:00:00 2001 From: Gal Szkolnik Date: Mon, 11 Oct 2021 20:56:10 -0400 Subject: [PATCH] Switching to PowerLine + Additional minor changes Styling will be based on PowerLine module. Placed _ll command/alias correctly based on platform --- base.linux/_ll.ps1 | 1 + base.win/Aliases/_ll.ps1 | 1 + base/Get-MyScript.ps1 | 3 +-- base/Setup-MyPowerLineTheme.ps1 | 35 +++++++++++++++++++++++++++++++ base/_ll.ps1 | 1 - base/profile.d/MyScript.class.ps1 | 2 +- base/profile.d/Style.ps1 | 9 +++++++- base/src/modules.json | 2 +- 8 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 base.linux/_ll.ps1 create mode 100644 base.win/Aliases/_ll.ps1 create mode 100644 base/Setup-MyPowerLineTheme.ps1 delete mode 100644 base/_ll.ps1 diff --git a/base.linux/_ll.ps1 b/base.linux/_ll.ps1 new file mode 100644 index 0000000..8e986e3 --- /dev/null +++ b/base.linux/_ll.ps1 @@ -0,0 +1 @@ +_ls -la --color=auto $args \ No newline at end of file diff --git a/base.win/Aliases/_ll.ps1 b/base.win/Aliases/_ll.ps1 new file mode 100644 index 0000000..7b0a0b8 --- /dev/null +++ b/base.win/Aliases/_ll.ps1 @@ -0,0 +1 @@ +Get-ChildItem \ No newline at end of file diff --git a/base/Get-MyScript.ps1 b/base/Get-MyScript.ps1 index e780a33..6e0350e 100644 --- a/base/Get-MyScript.ps1 +++ b/base/Get-MyScript.ps1 @@ -40,5 +40,4 @@ if( $Package ) { } if( $NamesOnly ) { return $rVal } -return $rVal | ForEach-Object { Join-Path $MyPSScriptRoot "$_`.ps1" } - +return $rVal | ForEach-Object { Join-Path $MyPSScriptRoot "$_`.ps1" } \ No newline at end of file diff --git a/base/Setup-MyPowerLineTheme.ps1 b/base/Setup-MyPowerLineTheme.ps1 new file mode 100644 index 0000000..d082788 --- /dev/null +++ b/base/Setup-MyPowerLineTheme.ps1 @@ -0,0 +1,35 @@ +$local:MyPowerLineSetup = [ordered]@{ + Title = { "Sz PS" } + SetCurrentDirectory = $true + PowerLineFont = $true + RestoreVirtualTerminal = $true + PowerLineCharacters = [ordered]@{ + ColorSeparator = "$([char]::ConvertFromUtf32(0x2588) + )$([PoshCode.Pansies.Entities]::ExtendedCharacters.ColorSeparator.Trim()[-1]) " + ReverseColorSeparator = " $( + [PoshCode.Pansies.Entities]::ExtendedCharacters.ReverseColorSeparator.Trim()[0] + )$([char]::ConvertFromUtf32(0x2588))" + Separator = " $([PoshCode.Pansies.Entities]::ExtendedCharacters.Separator.Trim()[-1]) " + ReverseSeparator = " $( + [PoshCode.Pansies.Entities]::ExtendedCharacters.ReverseSeparator.Trim()[0]) " + } + Colors = @( [rgbcolor]"Grey18", [rgbcolor]"Grey65" ) #, [rgbcolor]"white", [rgbcolor]"red", [rgbcolor]"blue" ) + Prompt = @( + { "`n" } # A spaced line + { New-PromptText -EBg VioletRed4 $MyInvocation.HistoryId } + { Get-Elapsed -Trim } + { Get-SegmentedPath -LengthLimit 30 } + { $local:_git_prompt = Write-VcsStatus; if( $_git_prompt ) { "$([PoshCode.Pansies.Entities]::ExtendedCharacters.Branch)$_git_prompt" } } + + # Right-align block + { "`t" } + { "$env:USERNAME @ $env:COMPUTERNAME" } + { Get-Date -Format 'HH:mm:ss' } + { Get-Date -Format 'MM/dd ddd' } + { "$PSOSName " } + + { "`n" } + { New-PromptText { "PS" } -Ebg Red } + ) +} +Set-PowerLineTheme @MyPowerLineSetup \ No newline at end of file diff --git a/base/_ll.ps1 b/base/_ll.ps1 deleted file mode 100644 index f4c0061..0000000 --- a/base/_ll.ps1 +++ /dev/null @@ -1 +0,0 @@ -_ls -la --color=auto $args diff --git a/base/profile.d/MyScript.class.ps1 b/base/profile.d/MyScript.class.ps1 index d137685..7d4635a 100644 --- a/base/profile.d/MyScript.class.ps1 +++ b/base/profile.d/MyScript.class.ps1 @@ -3,7 +3,7 @@ class MyScript { #: System.Management.Automation.IValidateSetValuesGenerator { $local:possibleValues = $( Get-MyPackages -ReturnFullPath -IncludeRoot -Force:$(-not $CurrentOnly) | Get-ChildItem -Recurse -Filter '*.ps1' | - Select-Object -ExpandProperty FullName | ForEach-Object { + Select-Object -Unique -ExpandProperty FullName | ForEach-Object { $_ -replace '\.ps1$','' -replace "$($MyPSScriptRoot -replace '\\',"\\")[/\\]",'' } ) diff --git a/base/profile.d/Style.ps1 b/base/profile.d/Style.ps1 index 09a3eb5..0110e18 100644 --- a/base/profile.d/Style.ps1 +++ b/base/profile.d/Style.ps1 @@ -7,7 +7,14 @@ $global:IsOutputANSICompatible = ( ) Get-Command -ListImported Set-PSReadLineKeyHandler -ErrorAction SilentlyContinue | ForEach-Object { Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete } -if( (Get-Command -ListImported Set-PoshPrompt -ErrorAction SilentlyContinue) -and $IsOutputANSICompatible ) { +if( (Get-Command -ListImported Set-PowerLinePrompt -ErrorAction Ignore) ) { + $global:PSOSName = [SystemName]::_GetValidValues("",$true,$true) | Select-Object -First 1 + + if( Test-Path variable:global:GitPromptSettings ) { + $global:GitPromptSettings.TruncatedBranchSuffix = [char]0x2026 + } + Set-PowerLinePrompt +} elseif( (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/modules.json b/base/src/modules.json index c3241c8..67dd7f7 100644 --- a/base/src/modules.json +++ b/base/src/modules.json @@ -2,7 +2,7 @@ "Always": [ "psreadline", "PowerShellCookbook", - "oh-my-posh", + "PowerLine", "posh-git", "z" ]}