TerminalBlocks.psm1
#Region '.\private\GetOperatingSystem.ps1' -1 function GetOperatingSystem { <# .SYNOPSIS Gets the Operating System information of the current system. #> [CmdletBinding()] param()End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { if ($script:OperatingSystem) { return $script:OperatingSystem } if ($IsLinux -and (Test-Path /etc/*-release)) { # We may need some help here, because I'm not sure this is enough _everywhere_ $Data = @{} Get-Content /etc/*-release | ConvertFrom-StringData | ForEach-Object { $Data += $_ } $script:OperatingSystem = [PSCustomObject]@{ Name = @($Data["DISTRIB_ID", "NAME", "ID"].Trim(" `t`r`n`"'"))[0] System = @($Data["PRETTY_NAME", "DISTRIB_DESCRIPTION", "NAME"].Trim(" `t`r`n`"'"))[0] Release = @($Data["VERSION_ID", "DISTRIB_RELEASE", "VERSION"].Trim(" `t`r`n`"'"))[0] BuildNumber = @($Data["VERSION_ID", "DISTRIB_RELEASE", "VERSION"].Trim(" `t`r`n`"'"))[0] KernelVersion = [Environment]::OSVersion.Version.ToString() } } elseif ($IsMacOS) { $script:OperatingSystem = [PSCustomObject]@{ Name = "macOS" # Should this be "Darwin" (i.e. uname -s)? System = "macOS $(uname -s) $(sw_vers -productVersion)" Release = sw_vers -productVersion BuildNumber = sw_vers -buildVersion KernelVersion = [Environment]::OSVersion.Version.ToString() } } elseif (Get-Command Get-CimInstance -ErrorAction Ignore) { $OS = Get-CimInstance Win32_OperatingSystem -Property Caption, BuildNumber -ErrorAction Ignore $script:OperatingSystem = [PSCustomObject]@{ Name = "Windows" System = $OS.Caption -replace "Microsoft " Release = ($OS.Caption -replace "Microsoft Windows " -split " ")[0] BuildNumber = $OS.BuildNumber KernelVersion = [Environment]::OSVersion.Version.ToString() } } elseif (Get-Command uname -ErrorAction Ignore) { Write-Verbose "No /etc/*-release but 'uname' command found, using it to get OS information." # In case there's a posix system without etc/*-release $script:OperatingSystem = [PSCustomObject]@{ Name = uname -s System = uname -sr Release = uname -r BuildNumber = uname -r KernelVersion = [Environment]::OSVersion.Version.ToString() } } $script:OperatingSystem } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\private\GetOperatingSystem.ps1' 54 #Region '.\public\Get-TerminalBlockDefault.ps1' -1 function Get-TerminalBlockDefault { [OutputType([hashtable])] [CmdletBinding()] param()End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { [PSCustomObject]@{ PSTypeName = "PoshCode.TerminalBlocks.Defaults" FirstAutomaticBackgroundColor = [PoshCode.TerminalBlocks.Block]::FirstAutomaticBackgroundColor AutomaticBackgroundHueStep = [PoshCode.TerminalBlocks.Block]::AutomaticBackgroundHueStep DefaultCaps = [PoshCode.TerminalBlocks.Block]::DefaultCaps DefaultSeparator = [PoshCode.TerminalBlocks.Block]::DefaultSeparator } } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Get-TerminalBlockDefault.ps1' 13 #Region '.\public\New-TerminalBlock.ps1' -1 function New-TerminalBlock { <# .Synopsis Create PoshCode.TerminalBlock with variable background colors .Description Allows changing the foreground and background colors based on elevation or success. Tests elevation fist, and then whether the last command was successful, so if you pass separate colors for each, the Elevated*Color will be used when PowerShell is running as administrator and there is no error. The Error*Color will be used whenever there's an error, whether it's elevated or not. .Example New-TerminalBlock { Show-ElapsedTime } -ForegroundColor White -BackgroundColor DarkBlue -ErrorBackground DarkRed -ElevatedForegroundColor Yellow This example shows the time elapsed executing the last command in White on a DarkBlue background, but switches the text to yellow if elevated, and the background to red on error. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'New is not state changing!')] [OutputType([PoshCode.TerminalBlocks.Block])] [CmdletBinding(DefaultParameterSetName = "Content")] [Alias("TerminalBlock", "Block")] param( # The text, object, or scriptblock to show as output [AllowNull()][EmptyStringAsNull()] [Parameter(Position = 0, ParameterSetName = "Content")] # , Mandatory=$true [Alias("InputObject")] $Content, # A special block that stores the position it would have output at [Parameter(Mandatory, ParameterSetName = "StorePosition")] [switch]$StorePosition, # A special block that recalls to the position of a previous StorePosition block [Parameter(Mandatory, ParameterSetName = "RecallPosition")] [switch]$RecallPosition, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor ) End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { switch ($PSCmdlet.ParameterSetName) { StorePosition { $PSBoundParameters["Content"] = [PoshCode.TerminalBlocks.SpecialBlock]::StorePosition $null = $PSBoundParameters.Remove("StorePosition") } RecallPosition { $PSBoundParameters["Content"] = [PoshCode.TerminalBlocks.SpecialBlock]::RecallPosition $null = $PSBoundParameters.Remove("RecallPosition") } } # The mind-blowing scriptblock hack ;-) if ($Content -is [string] -and $Content[0] -eq '{' -and $Content[-1] -eq '}') { $PSBoundParameters["Content"] = [ScriptBlock]::Create($Content.Substring(1, $Content.Length - 2)) } elseif (@($Content).Count -gt 1) { $PSBoundParameters["Content"] = @( foreach ($item in $Content) { if ($item -is [string] -and $item[0] -eq '{' -and $item[-1] -eq '}') { [ScriptBlock]::Create($item.Substring(1, $item.Length - 2)) } else { $item } } ) } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in [System.Management.Automation.PSCmdlet]::CommonParameters) { $null = $PSBoundParameters.Remove($name) } [PoshCode.TerminalBlocks.Block]$PSBoundParameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\New-TerminalBlock.ps1' 68 #Region '.\public\Reset-LastExitCode.ps1' -1 function Reset-LastExitCode { [CmdletBinding()] param()End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { $global:LASTEXITCODE = [PoshCode.TerminalBlocks.Block]::LastExitCode } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Reset-LastExitCode.ps1' 6 #Region '.\public\Set-TerminalBlockDefault.ps1' -1 filter Set-TerminalBlockDefault { [CmdletBinding()] param( # Turn on automatic background color for TerminalBlocks # If set, any TerminalBlock without a background color will automatically get a background color starting with this color and then incrementing the hue by AutomaticBackgroundHueStep (default 5). # As a reminder, a full rotation of hue is 360 degrees, so a hue step of 5 will give you 72 different colors, but these colors will be so similar most people can't tell sequential colors apart. # NOTE: By default there is no automatic background color at all. # To disable the automatic background color, set this to $null [Parameter(ValueFromPipelineByPropertyName)] [AllowNull()] [Alias("BackgroundColor")] [PoshCode.Pansies.RgbColor]$FirstAutomaticBackgroundColor, # The number of degrees to increment the hue by when generating automatic background colors # If you set this to 0, it will not increment the hue at all, and the automatic background color will always be the FirstAutomaticBackgroundColor. # # The default is 5, which gives you 72 different colors in a full rotation of hue (360 degrees). # You can set this to a larger value to get colors that are more distinct, but this will also mean fewer colors in the rotation. # # NOTE: By default there is no automatic background color at all, but if the FirstAutomaticBackgroundColor is set, the default HueStep is 5 degrees. [Parameter(ValueFromPipelineByPropertyName)] [Alias("HueStep")] [int]$AutomaticBackgroundHueStep, # The caps to use for TerminalBlocks which have no explicit caps # NOTE: The default is "","" if you never set it [Parameter(ValueFromPipelineByPropertyName)] [PoshCode.TerminalBlocks.Caps]$Caps, # The separator to use for TerminalBlocks which have no explicit separator # NOTE: The default is a space " " if you never set it [Parameter(ValueFromPipelineByPropertyName)] [string]$Separator )Process { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "ProcessBlock", "Enter" try { if ($PSBoundParameters.ContainsKey('AutomaticBackgroundHueStep')) { [PoshCode.TerminalBlocks.Block]::AutomaticBackgroundHueStep = $AutomaticBackgroundHueStep } if ($PSBoundParameters.ContainsKey('FirstAutomaticBackgroundColor')) { [PoshCode.TerminalBlocks.Block]::FirstAutomaticBackgroundColor = $FirstAutomaticBackgroundColor } if ($PSBoundParameters.ContainsKey('Caps')) { [PoshCode.TerminalBlocks.Block]::DefaultCaps = $Caps } if ($PSBoundParameters.ContainsKey('Separator')) { [PoshCode.TerminalBlocks.Block]::DefaultSeparator = $Separator } } catch { Write-Information $_ -Tags "ProcessBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "ProcessBlock", "Leave" } } } #EndRegion '.\public\Set-TerminalBlockDefault.ps1' 47 #Region '.\public\Show-AzureContext.ps1' -1 function Show-AzureContext { [Alias("AzureContextBlock","New-AzureContextBlock")] [CmdletBinding()] param( # A string to show before the output. Defaults to "$fg:32aee7&nf-md-microsoft_azure;$fg:clear" $Prefix = "$fg:32aee7&nf-md-microsoft_azure;$fg:clear", # Force imports the module if it's not imported # By default, this block only renders when Az.Accounts is imported. [switch]$Force, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if ($Force -or (Get-Module Az.Accounts)) { if (($Context = Get-AzContext)) { $Context.Name } } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-AzureContext.ps1' 18 #Region '.\public\Show-CondaContext.ps1' -1 function Show-CondaContext { <# .SYNOPSIS Shows the current anaconda context (if any) .DESCRIPTION Shows the current conda context (the value of the environment variable: CONDA_PROMPT_MODIFIER) #> [CmdletBinding()] param( # A string to show before the output. Defaults to "&nf-dev-python; " [string]$Prefix = "&nf-dev-python; ", # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { $Env:CONDA_PROMPT_MODIFIER }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-CondaContext.ps1' 15 #Region '.\public\Show-CPUName.ps1' -1 function Show-CPUName { <# .SYNOPSIS Shows the name of the primary central processing unit .NOTES This function is not implemented for macOS or Linux yet. #> [OutputType([string])] [CmdletBinding()] param( # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor)End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if ($PSVersion.Major -lt 6 -or $IsWindows) { (Get-ItemProperty -Path HKLM:\HARDWARE\DESCRIPTION\System\CentralProcessor\0 -Name ProcessorNameString).ProcessorNameString.Trim() } elseif ($IsOSX) { # TODO } elseif ($IsLinux) { # TODO } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-CPUName.ps1' 20 #Region '.\public\Show-Date.ps1' -1 function Show-Date { <# .SYNOPSIS Get the current date and/or time (by default, just the time). .DESCRIPTION Just calls Get-Date and passes the -Format and -AsUTC parameters. .EXAMPLE Show-Date -Format "h\:mm" Shows the time in 12 hour format without seconds. .EXAMPLE Show-Date -Format "H\:mm" -AsUTC Shows the UTC time in 24 hour format without seconds. #> [OutputType([string])] [CmdletBinding(DefaultParameterSetName = "SimpleFormat")] param( # A DateTime format string such as "h\:mm\:ss". Defaults to "T" [Parameter(ParameterSetName = 'SimpleFormat')] [string]$Format = 'T', # Shows the current UTC date (and/or time). [switch]$AsUTC, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { # PS5 doesn't have -AsUTC if ($AsUTC) { Get-Date -Format $Format (Get-Date).ToUniversalTime() } else { Get-Date -Format $Format } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-Date.ps1' 33 #Region '.\public\Show-DockerContext.ps1' -1 function Show-DockerContext { <# .SYNOPSIS Show the docker context #> [CmdletBinding()] param( # A string to show before the output. Defaults to "&whale;" [string]$Prefix = "&whale; ", # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if (Get-Command docker) { if (($Context = docker context show)) { $Context } } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-DockerContext.ps1' 17 #Region '.\public\Show-ElapsedTime.ps1' -1 function Show-ElapsedTime { <# .SYNOPSIS Get the time span elapsed during the execution of command (by default the previous command) .DESCRIPTION Calls Get-History to return a single command and returns the difference between the Start and End execution time #> [OutputType([string])] [CmdletBinding(DefaultParameterSetName = "SimpleFormat")] param( # A string to show before the output. [string]$Prefix = "&stopwatch;", # A Timespan format pattern such as "{0:ss\.fff}" defaults to "{0:d\d\ h\:mm\:ss\.fff}" # See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings # See also: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings [Parameter(ParameterSetName = 'SimpleFormat')] [string]$Format = "{0:d\d\ h\:mm\:ss\.fff}", # Automatically use different formats depending on the duration [Parameter(Mandatory, ParameterSetName = 'AutoFormat')] [switch]$Autoformat, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { $LastCommand = Get-History -Count 1 if(!$LastCommand) { return "" } $Duration = $LastCommand.EndExecutionTime - $LastCommand.StartExecutionTime $Result = if ($Autoformat) { if ($Duration.Days -ne 0) { "{0:d\d\ h\:mm}" -f $Duration } elseif ($Duration.Hours -ne 0) { "{0:h\:mm\:ss}" -f $Duration } elseif ($Duration.Minutes -ne 0) { "{0:m\:ss\.fff}" -f $Duration } elseif ($Duration.Seconds -ne 0) { "{0:s\.fff}s" -f $Duration } elseif ($Duration.Milliseconds -gt 10) { ("{0:fff}ms" -f $Duration).Trim("0") } else { # 956 is μ (for microsecond), but Windows PowerShell has a hard time with UTF-8 unless there's a BOM, so this is for safety ("{0:ffffff}$([char]956)s" -f $Duration).Trim("0") } } else { $Format -f $Duration } $Result }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-ElapsedTime.ps1' 48 #Region '.\public\Show-ErrorCount.ps1' -1 function Show-ErrorCount { <# .SYNOPSIS Get a count of new errors from previous command .DESCRIPTION Detects new errors generated by previous command based on tracking last seen count of errors. #> [CmdletBinding()] param( # If set, always show the output [switch]$ShowZero, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { $Count = $global:Error.Count - $script:LastErrorCount $script:LastErrorCount = $global:Error.Count if ($ShowZero -or $Count -gt 0) { $Count } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-ErrorCount.ps1' 20 #Region '.\public\Show-ExoNamespace.ps1' -1 function Show-ExoNamespace { <# .SYNOPSIS Shows the current Exchange Online Account Namespace #> [CmdletBinding()] param( # A string to show before the output. Defaults to "&nf-md-microsoft_office; " [string]$Prefix = "&nf-md-microsoft_office; ", # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if (Get-Command Get-FederatedOrganizationIdentifier -ErrorAction Ignore) { (Get-FederatedOrganizationIdentifier).AccountNamespace } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } <# elseif (Get-Command Get-AcceptedDomain -ErrorAction Ignore) { (Get-AcceptedDomain).Where{ $_.Default }.Name } #> } #EndRegion '.\public\Show-ExoNamespace.ps1' 17 #Region '.\public\Show-GPUName.ps1' -1 function Show-GPUName { <# .SYNOPSIS Shows the name of the priomary graphics processing unit .NOTES This function is not implemented for macOS or Linux yet. #> [OutputType([string])] [CmdletBinding()] param( # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor)End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if ($PSVersion.Major -lt 6 -or $IsWindows) { # Limit it to only those that have a known Refresh Rate? (Get-CimInstance -ClassName Win32_VideoController -Property Name -Filter "MinRefreshRate > 0").Name } elseif ($IsOSX) { # TODO } elseif ($IsLinux) { # TODO } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-GPUName.ps1' 21 #Region '.\public\Show-HistoryId.ps1' -1 function Show-HistoryId { <# .SYNOPSIS Shows the ID of the command you're about to type (this WILL BE the History ID of the command you run) #> [CmdletBinding()] param( # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor)End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { $MyInvocation.HistoryId }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-HistoryId.ps1' 10 #Region '.\public\Show-HostName.ps1' -1 function Show-HostName { <# .SYNOPSIS Gets the hostname of the current machine .DESCRIPTION Calls [Environment]::MachineName #> [OutputType([string])] [CmdletBinding(DefaultParameterSetName = "SimpleFormat")] param( # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor)End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { [Environment]::MachineName }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-HostName.ps1' 13 #Region '.\public\Show-JobOutput.ps1' -1 function Show-JobOutput { <# .SYNOPSIS Shows the most recent output of a specific job. .DESCRIPTION Calls Get-Job and returns the last output #> [OutputType([string])] [CmdletBinding()] param( # The name of the job to show the output of [string]$Name, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { $Job = Get-Job -Name $Name -ErrorAction SilentlyContinue if ($Job.Output.Count) { $Job.Output[-1] } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-JobOutput.ps1' 21 #Region '.\public\Show-KubeContext.ps1' -1 function Show-KubeContext { <# .SYNOPSIS Shows the current kubectl context #> [CmdletBinding()] param( # A string to show before the output. Defaults to "&nf-md-ship_wheel; " [string]$Prefix = "&nf-md-ship_wheel; ", # Show more information about the context, like the default namespace. # If set, the output will be based on the GoTemplate and will use "kubectl config view --minify" instead of "kubectl config current-context" [switch]$Detailed, # A JSON Path string to use for the output. # This will be passed to: kubectl config view --minify -o jsonpath='...' # E.g. "{.contexts[0].name}/{.contexts[0].context.namespace}" [string]$JsonPath, # The GoTemplate to use for the output. # Defaults to a string that shows contextName/namespace if a default namespace is set, but just the context name otherwise. # '{{range .contexts}}{{.name}}{{if .context.namespace}}/{{.context.namespace}}{{end}}{{end}}' [string]$GoTemplate = '{{range .contexts}}{{.name}}{{if .context.namespace}}/{{.context.namespace}}{{end}}{{end}}', # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if (Get-Command kubectl -ErrorAction Ignore) { $Context = if ($JsonPath) { kubectl config view --minify -o "jsonpath=$JsonPath" } elseif ($Detailed -or $PSBoundParameters.ContainsKey("GoTemplate")) { kubectl config view --minify --template $GoTemplate } else { kubectl config current-context } if ($Context) { $Context } } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-KubeContext.ps1' 38 #Region '.\public\Show-LastExitCode.ps1' -1 function Show-LastExitCode { <# .SYNOPSIS Show the LASTEXITCODE .DESCRIPTION Shows the exit code for native apps if the last command failed and left a LASTEXITCODE Can also show something for CommandNotFound or attmpt to execute a non-executable application #> [OutputType([string])] [CmdletBinding()] param( # A string to show before the output. Defaults to "&bomb;" [string]$Prefix = "&bomb;", # If you want to show a status even on successful commands, set this [string]$Success = "", # A string to show when a CommandNotFoundException is thrown. # Defaults to "🔍" [string]$NotFound = "&magnifyingglasstiltedleft;", # A string to show when an ApplicationFailedException is thrown. # This is typical for non-executable files on 'nix # Defaults to "🚫" [string]$NotExecutable = "&prohibited;", # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { # If there was an error ... if (-not $? -or -not [PoshCode.TerminalBlocks.Block]::LastSuccess) { # We retrieve the InvocationInfo from the most recent error using $global:error[0] if ($LastError = $global:error[0]) { # If History[-1] matches Error[0].ErrorInvocationInfo then the last error was NOT a native command if ($LastError.InvocationInfo -and (Get-History -Count 1).CommandLine -eq $global:error[0].InvocationInfo.Line) { if ($NotFound -and $LastError.Exception -is [System.Management.Automation.CommandNotFoundException]) { $NotFound } elseif ($NotExecutable -and $LastError.Exception -is [System.Management.Automation.ApplicationFailedException]) { $NotExecutable } } else { if ([PoshCode.TerminalBlocks.Block]::LastExitCode -gt 0) { [PoshCode.TerminalBlocks.Block]::LastExitCode.ToString() } elseif ($global:LASTEXITCODE -gt 0) { $global:LASTEXITCODE } } } } elseif ($Success) { $Success } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-LastExitCode.ps1' 51 #Region '.\public\Show-LocationStack.ps1' -1 function Show-LocationStack { <# .SYNOPSIS Show information about the location stack TODO: allow passing a stack name TODO: allow showing where popd would go to #> [CmdletBinding()] param( # If set, this string is repeated for each nested level # The default is "»" so "»»»" will be used for $NestedPromptlevel = 3 [string]$RepeatCharacter ="»", # LevelStrings allows you to specify an array of exact values to use for each $NestedPromptlevel (starts at 1) # E.g.: @("»", "»»", "»3", "»4", "»5", "»6", "»7", "»8", "»9") [string[]]$LevelStrings, [string]$StackName = "", # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor ) End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if ($depth = [PoshCode.TerminalBlocks.Block]::GlobalSessionState.Path.LocationStack($StackName).count) { if ($RepeatCharacter) { $RepeatCharacter * $depth } elseif ($LevelStrings -and $LevelStrings.Length -ge $depth) { $LevelStrings[$depth - 1] } else { $depth } } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-LocationStack.ps1' 32 #Region '.\public\Show-Memory.ps1' -1 function Show-Memory { <# .SYNOPSIS Shows the total memory (and optionally, free memory) .NOTES This function is not implemented for macOS or Linux yet. #> [OutputType([string])] [CmdletBinding()] param( # Whether to show the amount of used memory before the total memory [switch]$ShowUsed, # The number of decimal places to round the output to [int]$Round = 2, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { $Memory = [GC]::GetGCMemoryInfo() $Label, $Units = if ($Memory.TotalAvailableMemoryBytes -gt 1TB) { "TB", 1TB } elseif ($Memory.TotalAvailableMemoryBytes -gt 1GB) { "GB", 1GB } else { "MB", 1MB } if ($ShowUsed) { "{0:N$Round}$Label" -f ($Memory.MemoryLoadBytes / $Units) } "{0:N$Round}$Label" -f ($Memory.TotalAvailableMemoryBytes / $Units) }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-Memory.ps1' 31 #Region '.\public\Show-NestedPromptLevel.ps1' -1 function Show-NestedPromptLevel { <# .SYNOPSIS Show the nested prompt level (if any) #> [CmdletBinding()] param( # Count prefix is used as a prefix for the number # The default is "⛯ " so "⛯ 3" will be used for $NestedPromptlevel = 3 [string]$CountPrefix = "&gear; ", # If set, Repeat is repeated for each nested level # E.g. if you set "*" then "***" will be used for $NestedPromptlevel = 3 [string]$RepeatCharacter, # LevelStrings allows you to specify an array of exact values to use for each $NestedPromptlevel (starts at 1) # E.g.: @("&gear;", "&gear;&gear;", "&gear;3", "&gear;4", "&gear;5", "&gear;6", "&gear;7", "&gear;8", "&gear;9") [string[]]$LevelStrings, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor ) Begin { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "BeginBlock", "Enter" try { if (!$RepeatCharacter -and !$LevelStrings) { $PSBoundParameters["Prefix"] = $CountPrefix } } catch { Write-Information $_ -Tags "BeginBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "BeginBlock", "Leave" } } End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if ($NestedPromptLevel) { if ($RepeatCharacter) { $RepeatCharacter * $NestedPromptLevel } elseif ($LevelStrings -and $LevelStrings.Length -ge $NestedPromptLevel) { $LevelStrings[$NestedPromptLevel-1] } else { $NestedPromptLevel } } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-NestedPromptLevel.ps1' 37 #Region '.\public\Show-Newline.ps1' -1 function Show-Newline { <# .SYNOPSIS Shows a Newline .DESCRIPTION Shows a Newline This is a SpecialBlock that does not render caps or separators or color, but simply outputs a newline character. .EXAMPLE Show-Newline #> [OutputType([PoshCode.TerminalBlocks.SpecialBlock])] [CmdletBinding()] param( # The separator character(s) are used between blocks of output by this scriptblock # You can pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator = ' ', # The Content of a Newline is a Newline. Don't change it. $Content = [PoshCode.TerminalBlocks.SpecialBlock]::Newline, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-Newline.ps1' 30 #Region '.\public\Show-OSTheme.ps1' -1 function Show-OSTheme { <# .SYNOPSIS Shows the Window Theme name (and whether it is Light or Dark) .NOTES This function is not implemented for macOS or Linux yet. #> [OutputType([string])] [CmdletBinding()] param( # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor)End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if ($PSVersion.Major -lt 6 -or $IsWindows) { $themeinfo = Get-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name SystemUsesLightTheme, AppsUseLightTheme $Name = (Get-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes' -Name CurrentTheme).CurrentTheme -replace ".*[\\/]([^\\/]+).theme$", '$1' ?? "Default" $Mode = if ($themeinfo.SystemUsesLightTheme -ne $themeinfo.AppsUseLightTheme) { if ($themeinfo.SystemUsesLightTheme) { "Light/Dark" } else { "Dark/Light" } } elseif ($themeinfo.SystemUsesLightTheme) { "Light" } else { "Dark" } "$Name ($Mode)" } elseif ($IsOSX) { # TODO } elseif ($IsLinux) { # TODO } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-OSTheme.ps1' 34 #Region '.\public\Show-Palette.ps1' -1 function Show-Palette { <# .SYNOPSIS Shows the 16 colors of the terminal color palette .DESCRIPTION Shows the 16 colors of the terminal color palette, in two sections, separated by the separator. The first section displays the standard colors, while the second section displays the bright colors. #> [OutputType([string])] [CmdletBinding()] param( # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor)End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { "`e[40m `e[41m `e[42m `e[43m `e[44m `e[45m `e[46m `e[47m `e[0m" "`e[100m `e[101m `e[102m `e[103m `e[104m `e[105m `e[106m `e[107m `e[0m" }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-Palette.ps1' 15 #Region '.\public\Show-Path.ps1' -1 function Show-Path { <# .SYNOPSIS Get a shortened version of a path for human readability .DESCRIPTION Trims the length of the path using various techniques #> [CmdletBinding(DefaultParameterSetName = "Length")] param( # Optionally, a strict maximum length of path to display # Path will be truncated to ensure it's shorter [Parameter(Position = 0)] [int]$Length = [int]::MaxValue, # Optionally, a strict maximum number of levels of path to display # Path will be truncated to ensure it's shorter [Parameter()] [int]$Depth = [int]::MaxValue, # Show the drive name on the front. Does not count toward length [switch]$DriveName, # A character to use for $Home. Defaults to "~" # You can use "&House;" to get 🏠 if you have Pansies set to EnableEmoji! # NOTE: this is based on the provider. # By default, only the FileSystem provider has a Home, but you can set them! [string]$HomeString = "~", # Only shows the path down to the root of git projects [switch]$GitDir, # Show only the first letter for all directories except the last one [Parameter()] [switch]$SingleLetterPath, # Show the first letter instead of truncating [Parameter()] [switch]$LeftoversAsOneLetter, # Optionally, turn it into a hyperlink to the full path. # In Windows Terminal, for instance, this makes it show the full path on hover, and open your file manager on ctrl+click [Parameter()] [switch]$AsUrl, # The path to show (defaults to $pwd, the present working directory) [Alias("InputObject")] [string]$Path, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor ) End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { # If user passes 0 (or less), I just refuse to deal with it if ($Length -le 0 -or $Depth -le 0) { return [string]::Empty } if (!$Path) { $Path = "$Pwd" } $OriginalPath = $Path $resolved = Resolve-Path $Path $provider = $resolved.Provider $Drive = $resolved.Drive.Name + ":" $Path = $resolved.Path $BaseHome = $Provider.Home Write-Verbose "ProviderHome: $BaseHome" if ($GitDir -and "FileSystem" -eq $Provider.Name -and (Get-Command git -ErrorAction Ignore)) { Push-Location $OriginalPath -StackName "Show-Path" $toplevel = git rev-parse --show-toplevel 2>$null | Convert-Path Write-Verbose "GitDir: $TopLevel" Write-Verbose "Path: $Path" if (!$LastExitCode -and $Path.StartsWith($TopLevel, "OrdinalIgnoreCase")) { $Path = $Path.SubString($TopLevel.Length) # If we're in a gitdir, we insist on showing it (using driveName logic) $Drive = Split-Path $TopLevel -Leaf $DriveName = $true $Depth = $Depth - 1 Write-Verbose "Full: $Path" } else { Write-Verbose "Clear LastExitCode $global:LastExitCode" $global:LastExitCode = 0 } Pop-Location -StackName "Show-Path" } if ($Path) { if ($HomeString -and $BaseHome -and $Path.StartsWith($BaseHome, "OrdinalIgnoreCase")) { # If we're in $HOME, we insist on showing it (using driveName logic) $Drive = '' $DriveName = $false $Path = $HomeString + $Path.Substring($BaseHome.Length) } else { $Path = Split-Path $Path -NoQualifier } if ($provider.ItemSeparator) { # Trust the provider's separator [PoshCode.Pansies.Text]$Path = $Path.Trim($provider.ItemSeparator) $Pattern = [regex]::Escape($provider.ItemSeparator) if (!$Separator) { $Separator = $provider.ItemSeparator } } else { # Windows PowerShell [PoshCode.Pansies.Text]$Path = $Path.Trim("\") $Pattern = "\\" if (!$Separator) { $Separator = "\" } } if ($SingleLetterPath) { # Remove prefix for UNC paths $Path = $Path -replace '^[^:]+::', '' $Folders = $Path -split $Pattern if ($Folders.Length -gt 1) { # Supports emoji $Folders = $Folders[0..($Folders.Count-2)].ForEach{ [System.Text.Rune]::GetRuneAt($_,0).ToString() } + @($Folders[-1]) } $Path = $Folders -join $Separator } else { $Folders = $Path -split $Pattern } $Ellipsis = [char]0x2026 if ($Path.Length -gt $Length -or $Folders.Length -gt $Depth) { [Array]::Reverse($Folders) # Start the path with just the last folder $Path, $Folders = $Folders $PathDepth = 1 # If just the last folder is too long, truncate it if ("$Path".Length + 2 -gt $Length) { Write-Verbose "$Path ($("$Path".Length) - $Length)" $Path = $Ellipsis + "$Path".Substring("$Path".Length - $Length + 1) if ($LeftoversAsOneLetter) { $Folders = $Folders.ForEach{ [System.Text.Rune]::GetRuneAt($_,0).ToString() } $Length = [int]::MaxValue } else { $Folders = @() } } while ($Folders) { $Folder, $Folders = $Folders if ($Length -gt ("$Path".Length + $Folder.Length + 3) -and $Depth -gt $PathDepth) { $Path = $Folder + $Separator + $Path } elseif ($LeftoversAsOneLetter) { # Put back the $Folder as well $Folders = @(@($Folder) + $Folders).ForEach{ [System.Text.Rune]::GetRuneAt($_,0).ToString() } + @($Drive.Trim($provider.ItemSeparator, $Separator)) $Depth = $Length = [int]::MaxValue $DriveName = $False } else { $Path = $Ellipsis + $Separator + $Path break } $PathDepth++ } } else { $Path = $Path -replace $Pattern, $Separator } } if ($DriveName) { if ($Path) { $Path = $Drive + $Separator + $Path } else { $Path = $Drive } } if ($AsUrl -and "FileSystem" -eq $Provider.Name) { $8 = "$([char]27)]8;;" "$8{0}`a{1}$8`a" -f $OriginalPath, $Path } else { $Path } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-Path.ps1' 183 #Region '.\public\Show-PoshGitStatus.ps1' -1 function Show-PoshGitStatus { <# .SYNOPSIS Shows the git status of the current working directory. .DESCRIPTION Calls PoshGit's Get-GitStatus & Write-GitStatus to display the git status Configure via $global:GitPromptSettings #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification = "posh-git made this mess")] [OutputType([string])] [CmdletBinding()] param( # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor) dynamicparam { $Parameters = [Management.Automation.RuntimeDefinedParameterDictionary]::new() if (Get-Module posh-git) { if ($global:GitPromptSettings) { foreach($Setting in $GitPromptSettings | Get-Member -Type Property) { if ($Setting.Name -notin $MyInvocation.MyCommand.Parameters.Keys) { # $Type = $GitPromptSettings.($Setting.Name).GetType() $Type = $GitPromptSettings.GetType().GetProperty($Setting.Name).PropertyType if ($Type -eq [bool]) { $Type = [switch] } $param = [Management.Automation.RuntimeDefinedParameter]@{ Name = $Setting.Name ParameterType = $Type } $param.Attributes.Add( [Parameter]@{ ParameterSetName = "__AllParameterSets" Mandatory = $false } ) # $param.Attributes.Add([ValidateSet]::new([String[]]@(...))) $Parameters.Add($param.Name, $param) } } $Parameters } } } # Use the BEGIN block for one-time setup that doesn't need to be re-calculated in the prompt every time Begin { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "BeginBlock", "Enter" try { foreach($param in $PSBoundParameters.Keys) { if ($Parameters.ContainsKey($param)) { $global:GitPromptSettings.$param = $PSBoundParameters[$param] } } } catch { Write-Information $_ -Tags "BeginBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "BeginBlock", "Leave" } } # The end block will be turned into a closure and a TerminalBlock will be created End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if (Get-Module posh-git) { posh-git\Write-GitStatus (posh-git\Get-GitStatus) } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-PoshGitStatus.ps1' 59 #Region '.\public\Show-Space.ps1' -1 function Show-Space { <# .SYNOPSIS Shows a space .DESCRIPTION Shows a space block. Still renders caps, so it can be used with background colors to create gaps in a "PowerLine" style output. .EXAMPLE Show-Space -Caps '','' █ .EXAMPLE Show-Space -Caps '','' #> [OutputType([PoshCode.TerminalBlocks.SpecialBlock])] [CmdletBinding()] param( # The separator character(s) are used between blocks of output by this scriptblock # You can pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator = ' ', # The Content of a Spacer is a Spacer. Don't change it $Content = [PoshCode.TerminalBlocks.SpecialBlock]::Spacer, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-Space.ps1' 33 #Region '.\public\Show-UserName.ps1' -1 function Show-UserName { <# .SYNOPSIS Gets the Username of the current user, and optionally the Computer Name .DESCRIPTION Calls [Environment]::UserName .EXAMPLE Show-UserName -ShowComputerName -Separator "@" Returns "User@Computer" #> [OutputType([string])] [CmdletBinding(DefaultParameterSetName = "SimpleFormat")] param( # Whether to show the Computer Name after the Username [switch]$ShowComputerName, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { [Environment]::UserName if ($ShowComputerName) { [Environment]::MachineName } }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-UserName.ps1' 24 #Region '.\public\Show-Version.ps1' -1 function Show-Version { <# .SYNOPSIS Gets Version information about PowerShell and more .DESCRIPTION This function lets you get the various "version" information in a single output. By default, it only shows the "Shell" version, which is just $PSVersionTable.PSVersion .EXAMPLE Show-Version System, Shell -Label -Separator '' -BackgroundColor White -ForegroundColor Black | % ToString #> [OutputType([string], [array])] [CmdletBinding(DefaultParameterSetName = "SimpleFormat")] param( # The version to show. # The "OS" version is *just* the OS name # The "System" version includes the OS Name and Release (and sometimes more) # The old "OSVersion" is now "Release" which is also known as the "productVersion" and is part of the "System" version. # By default returns the System, Kernel, .NET, and PowerShell versions. [ValidateSet("OS", "System", "Release", "Build", "Kernel", ".NET", "PowerShell", "Host")] [string[]]$Component = ("System", "Kernel", ".NET", "PowerShell"), # Whether to include the label for each component (defaults to $true when no $Component is specified, otherwise $false) [switch]$Label, # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor ) End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { if ($PSBoundParameters.Count -eq 0) { $Label = $true } if (!$script:OperatingSystem) { $script:OperatingSystem = &(Get-Module TerminalBlocks) { GetOperatingSystem } } @( foreach ($Component in $Component) { @( if ($Label) { $Component + ":" } switch ($Component) { "Host" { $Host.Version.ToString() } "PowerShell" { $PSVersionTable.PSVersion.ToString() } ".NET" { [Environment]::Version.ToString() } "Kernel" { $script:OperatingSystem.KernelVersion } "OS" { $script:OperatingSystem.Name } "System" { $script:OperatingSystem.System } "Release" { $script:OperatingSystem.Release } "Build" { $script:OperatingSystem.BuildNumber } } ) -join " " } ) }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-Version.ps1' 71 #Region '.\public\Show-Weather.ps1' -1 function Show-Weather { <# .SYNOPSIS Shows the current weather .DESCRIPTION Calls wttr.in and returns the current weather .LINK https://github.com/chubin/wttr.in?tab=readme-ov-file#one-line-output https://wttr.in/:help #> [OutputType([string])] [CmdletBinding()] param( # The wttr format. Can be a single number from 1 to 4, or a custom format string. # Defaults to "%c%t" which shows an icon for the conditions, and the temperature. # If you can't handle emoji, you might like "%C%t" instead, which shows the conditions in text form # If you travel a lot, you might want to prefix with "%l: " to show the detected location. # See https://github.com/chubin/wttr.in?tab=readme-ov-file#one-line-output for more options [string]$Format = "%c%t", # The location to get the weather for. By default relies on wttr.in to determine the location based on your IP address. # You can specify a location like "Rochester" or "Rochester, NY" to get the weather for that location. # Or you can use a lowercase airport code, area code, GPS coordinates, etc. # https://wttr.in/:help for more information. [string]$Location, # Whether to use "m"etric units (Celsius, km/h, etc.) or "u"SCS units (Fahrenheit, mph, etc.) # Defaults to u or m based on whether the current culture is en-US or not. [ValidateSet("m", "u")] [string]$Units = ($PSUICulture -eq "en-US" ? "u" : "m"), # The maximum length of the block, in cells (unicode characters) # Any text longer than this will be truncated to fit # If this is set to 0, the block will be as wide as the content [int]$MaxLength, # Extra text to prepend at the start of the block [Alias("Prepend")] [String]$Prefix, # Extra text to append at the end of the block [Alias("Suffix", "Append")] [String]$Postfix, # The separator character(s) are used between blocks of output by this scriptblock # Pass two characters: the first for normal (Left aligned) blocks, the second for right-aligned blocks [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [String]$Separator, # The cap character(s) are used on the ends of blocks of output # Pass two characters: the first for the left side, the second for the right side. [ArgumentCompleter({ [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new( [System.Management.Automation.CompletionResult[]]@( # The Consolas-friendly block characters ▌and▐ and ╲ followed by all the extended Terminal characters @([string[]][char[]]@(@(0xe0b0..0xe0d4) + @(0x2588..0x259b) + @(0x256d..0x2572))).ForEach({ [System.Management.Automation.CompletionResult]::new("'$_'", $_, "ParameterValue", $_) }) )) })] [PoshCode.TerminalBlocks.Caps]$Caps, # The foreground color to use when the last command succeeded [Alias("ForegroundColor", "Fg", "DFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultForegroundColor, # The background color to use when the last command succeeded [Alias("BackgroundColor", "Bg", "DBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$DefaultBackgroundColor, # The foreground color to use when the process is elevated (running as administrator) [Alias("AdminFg", "AFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminForegroundColor, # The background color to use when the process is elevated (running as administrator) [Alias("AdminBg", "ABg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$AdminBackgroundColor, # The foreground color to use when the last command failed [Alias("ErrorFg", "EFg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorForegroundColor, # The background color to use when the last command failed [Alias("ErrorBg", "EBg")] [AllowNull()][EmptyStringAsNull()] [ArgumentCompleter([PoshCode.Pansies.Palettes.X11Palette])] [PoshCode.Pansies.RgbColor]$ErrorBackgroundColor )End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { # Support default parameter values $Parameters = Get-ParameterValue $Content = { (Invoke-RestMethod -TimeoutSec 5 "wttr.in/${Location}?${Units}&format=$Format") -replace "[ +]+", " " }.GetNewClosure() if ($Content.Ast.EndBlock.Statements.Length) { $Parameters["Content"] = $Content } # Strip common parameters if they're on here (so we can use -Verbose) foreach ($name in @($Parameters.Keys.Where{ $_ -notin [PoshCode.TerminalBlocks.Block].GetProperties().Name })) { $null = $Parameters.Remove($name) } # Store the InvocationInfo for serialization $Parameters["MyInvocation"] = [System.Management.Automation.InvocationInfo].GetProperty("ScriptPosition", [System.Reflection.BindingFlags]"Instance,NonPublic").GetValue($MyInvocation).Text [PoshCode.TerminalBlocks.Block]$Parameters } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Show-Weather.ps1' 34 #Region '.\public\Test-Elevation.ps1' -1 function Test-Elevation { <# .Synopsis Get a value indicating whether the process is elevated (running as administrator or root) #> [CmdletBinding()] param()End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { [PoshCode.TerminalBlocks.Block]::Elevated } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Test-Elevation.ps1' 10 #Region '.\public\Test-Success.ps1' -1 function Test-Success { <# .Synopsis Get a value indicating whether the last command succeeded or not #> [CmdletBinding()] param()End { Write-Information "Enter $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Enter" try { [PoshCode.TerminalBlocks.Block]::LastSuccess } catch { Write-Information $_ -Tags "EndBlock", "Exception", "Unhandled" throw } finally { Write-Information "Leave $($PSCmdlet.MyInvocation.MyCommand.Name)" -Tags "EndBlock", "Leave" } } } #EndRegion '.\public\Test-Success.ps1' 10 #Region '.\Footer.ps1' -1 & { if (Get-Command Add-MetadataConverter -ErrorAction Ignore) { $AsConverters = @{} foreach($command in Get-Command Show-*, New-TerminalBlock -Module TerminalBlocks) { $AsConverters[$command.Name] = $command.ScriptBlock } Add-MetadataConverter $AsConverters } } #EndRegion '.\Footer.ps1' 10 |