diff --git a/CHANGELOG.md b/CHANGELOG.md index 619712f..1dbd3e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,54 @@ +## Posh 0.1.3: Posh Tips and Tricks + +* New Formatting: + * Adding Select-XML Formatter (#107) + * Posh.Preset.Collection (#153) + * Posh.Tip.Command (#166) +* Updated Formatting: + * Making DirectoryIcon customizable / changing default to triangle (#169) + * Integrating Tips/Links into Posh Formatting (#165) + * Improving Formatting of Select-String (#109) (thanks @mdgrs-mei ! ) +* Added Tips and Tricks to Modules (#118) and added the first round of tips/tricks: + * NegativeIndexingFibonacci Trick (#168) + * GenericTypes Tip (#167) + * Ordered Hashtables Tip (#156) + * Hashtables Tip (#155) + * AssigningLoopOutput Tip (#145) + * RangeOperator Tip (#151) + * NegativeIndex Tip (#150) + * TernaryOperator Tip (#148) + * Creating PsuedoObjects Trick (#144) + * AssigningIfStatements Tip (#144) + * Tip - Trinity of Discoverability (#142) + * Tip - You Can Get Help On a Script (#147) + * Tip - Everything Is An Object (#140) + * Trick - The Parameter Set That Was Not There (#141) + * Multiple Assignment Tip (#143) + * LoopLabels Tip (#146) + * see issues #166 +* New Extended Types: + * Posh.Preset.Collection (#153) + * Posh.Preset.Command (#154) + * Posh.ExtensionCollection + * .Count (#162) + * .Refresh() (#123) + * .Random (#124) + * .All (#128) + * get/set .CommandType (#127) + * get/set .Path (#126) + * get/set Module (#125) +* Updated Extended Types + * PSModuleInfo.Link (#64/#157/#158/#159/#160) + * PSModuleInfo.Preset (#64/#153) + * PSModuleInfo.Tip(s)/Trick(s) (#119, #120) + * $Posh.Host.get/set_Title (#130) + * Fixing stackable functions (#110, thanks @mdgrs-mei !) +* Updating Posh.Preset.Command.Use help (#154) +* Adding FileIcons Preset (#163) +* Making TabExpansion Stackable (#116) + +--- + ## Posh 0.1.2: * New Demos diff --git a/Demos/Posh.demo.ps1 b/Demos/Posh.demo.ps1 index 9efa83e..7a0cb33 100644 --- a/Demos/Posh.demo.ps1 +++ b/Demos/Posh.demo.ps1 @@ -85,7 +85,7 @@ Invoke-RestMethod https://pssvg.start-automating.com/Examples/HelloWorld.svg # Regular Expressions are also syntax highlighted, helping us all hopefully understand them better. [Regex]::new(' -(?Pattern) # Comment +(?Pattern) # Comment ','IgnoreCase,IgnorePatternWhitespace') diff --git a/Formatting/FileSystem/FileTableView.format.ps1 b/Formatting/FileSystem/FileTableView.format.ps1 index 8a7bbd1..124f329 100644 --- a/Formatting/FileSystem/FileTableView.format.ps1 +++ b/Formatting/FileSystem/FileTableView.format.ps1 @@ -27,8 +27,13 @@ Write-FormatView -TypeName FileSystemTypes -Property LastWriteTime, Length, Name } else { $(if ($_ -is [IO.DirectoryInfo]) { - $PSStyle.FileInfo.Directory - "`u{1F5BF} " + $PSStyle.FileInfo.Directory + if ($PSStyle.FileInfo.DirectoryIcon) { + "$($PSStyle.FileInfo.DirectoryIcon)" + " " + } else { + "▶ " + } + } else { if ( $PSStyle.FileInfo.Extension.Keys -and @@ -56,8 +61,8 @@ Write-FormatView -TypeName FileSystemTypes -Property LastWriteTime, Length, Name $extraSpace = $true - if ($Posh.FileIcons) { - + if ($psStyle.FileInfo.ExtensionIcon -and $psStyle.FileInfo.ExtensionIcon[$_.Extension]) { + "$($psStyle.FileInfo.ExtensionIcon[$_.Extension]) " } else { $(switch ($_.Extension) { diff --git a/Formatting/Posh/Posh.LinkControl.format.ps1 b/Formatting/Posh/Posh.LinkControl.format.ps1 new file mode 100644 index 0000000..05890bb --- /dev/null +++ b/Formatting/Posh/Posh.LinkControl.format.ps1 @@ -0,0 +1,18 @@ +Write-FormatView -TypeName n/a -Name "Posh.Link" -AsControl -Action { + @( + if ($_.Name -and $_.Url) { + if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { + $psStyle.FormatHyperlink($_.Name, $_.Url) + } else { + "[$($_.Name)]($($_.Url))" + } + } elseif ($_.Url) { + $uri = [uri]$_.Url + if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { + $psStyle.FormatHyperlink($_.Url, $uri) + } else { + "[$($_.Url)]($($uri))" + } + } + ) -join '' +} \ No newline at end of file diff --git a/Formatting/Posh/Posh.Module.Link.format.ps1 b/Formatting/Posh/Posh.Module.Link.format.ps1 new file mode 100644 index 0000000..c103d48 --- /dev/null +++ b/Formatting/Posh/Posh.Module.Link.format.ps1 @@ -0,0 +1,5 @@ +Write-FormatView -TypeName Posh.Module.Link -Action { + Write-FormatViewExpression -ScriptBlock { $_ } -ControlName Posh.Link +} -GroupByProperty Source + +Write-FormatView -TypeName Posh.Module.Link -Property Name, Url -GroupByProperty Source \ No newline at end of file diff --git a/Formatting/Posh/Posh.Module.Screenshot.format.ps1 b/Formatting/Posh/Posh.Module.Screenshot.format.ps1 index edf0cf0..cdbeed2 100644 --- a/Formatting/Posh/Posh.Module.Screenshot.format.ps1 +++ b/Formatting/Posh/Posh.Module.Screenshot.format.ps1 @@ -1,20 +1,5 @@ Write-FormatView -TypeName Posh.Module.Screenshot -Action { - @( - if ($_.Name -and $_.Url) { - if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { - $psStyle.FormatHyperlink($_.Name, $_.Url) - } else { - "![$($_.Name)]($($_.Url))" - } - } elseif ($_.Url) { - $uri = [uri]$_.Url - if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { - $psStyle.FormatHyperlink($_.Url, $uri) - } else { - "![$($_.Url)]($($uri))" - } - } - ) -join '' + Write-FormatViewExpression -ScriptBlock { $_ } -ControlName Posh.Link } -GroupByProperty Source Write-FormatView -TypeName Posh.Module.Screenshot -Property Name, Url -GroupByProperty Source \ No newline at end of file diff --git a/Formatting/Posh/Posh.Module.Video.format.ps1 b/Formatting/Posh/Posh.Module.Video.format.ps1 index 11e20f8..9b9fab7 100644 --- a/Formatting/Posh/Posh.Module.Video.format.ps1 +++ b/Formatting/Posh/Posh.Module.Video.format.ps1 @@ -1,20 +1,5 @@ Write-FormatView -TypeName Posh.Module.Video -Action { - @( - if ($_.Name -and $_.Url) { - if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { - $psStyle.FormatHyperlink($_.Name, $_.Url) - } else { - "[$($_.Name)]($($_.Url))" - } - } elseif ($_.Url) { - $uri = [uri]$_.Url - if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { - $psStyle.FormatHyperlink($_.Url, $uri) - } else { - "[$($_.Url)]($($uri))" - } - } - ) -join '' + Write-FormatViewExpression -ScriptBlock { $_ } -ControlName Posh.Link } -GroupByProperty Source Write-FormatView -TypeName Posh.Module.Video -Property Name, Url -GroupByProperty Source \ No newline at end of file diff --git a/Formatting/Posh/Posh.PresetCollection.format.ps1 b/Formatting/Posh/Posh.PresetCollection.format.ps1 new file mode 100644 index 0000000..910e684 --- /dev/null +++ b/Formatting/Posh/Posh.PresetCollection.format.ps1 @@ -0,0 +1,9 @@ +Write-FormatView -TypeName Posh.Preset.Collection -Action { + Write-FormatViewExpression -ScriptBlock { + Show-Markdown -InputObject $_.README + } + + Write-FormatViewExpression -Newline + + +} \ No newline at end of file diff --git a/Formatting/Posh/Posh.Resources.format.ps1 b/Formatting/Posh/Posh.Resources.format.ps1 deleted file mode 100644 index a6018ae..0000000 --- a/Formatting/Posh/Posh.Resources.format.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -Write-FormatView -TypeName Posh.Resources -Action { - Write-FormatViewExpression -ScriptBlock { - Show-Markdown -InputObject $_.README - } -If { $_.README } - - Write-FormatViewExpression -Newline - - Write-FormatViewExpression -ScriptBlock { - $_ | - Select-Object -ExcludeProperty README -Property * | - Format-Yaml - } -} \ No newline at end of file diff --git a/Formatting/Posh/Posh.Tip.Collection.format.ps1 b/Formatting/Posh/Posh.Tip.Collection.format.ps1 new file mode 100644 index 0000000..61d4b9d --- /dev/null +++ b/Formatting/Posh/Posh.Tip.Collection.format.ps1 @@ -0,0 +1,3 @@ +Write-FormatView -TypeName Posh.Tip.Collection -Action { + Write-FormatViewExpression -Property Random -ControlName Posh.Tip.Control +} \ No newline at end of file diff --git a/Formatting/Posh/Posh.Tip.Command.format.ps1 b/Formatting/Posh/Posh.Tip.Command.format.ps1 new file mode 100644 index 0000000..b6b39e7 --- /dev/null +++ b/Formatting/Posh/Posh.Tip.Command.format.ps1 @@ -0,0 +1,14 @@ +Write-FormatView -TypeName Posh.Tip.Command -Action { + Write-FormatViewExpression -ScriptBlock { $_ } -ControlName Posh.Tip.Control +} + +Write-FormatView -TypeName n/a -Name Posh.Tip.Control -AsControl -Action { + Write-FormatViewExpression -ScriptBlock { + $showDemoCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand('Show-Demo', 'Function') + if ($showDemoCommand -and $_.Content -is [scriptblock]) { + Show-Demo -DemoScript $_.Content -AutoPlay | Out-Null + } else { + $_.Content + } + } +} \ No newline at end of file diff --git a/Formatting/Posh/Posh.format.ps1 b/Formatting/Posh/Posh.format.ps1 index 71a4639..ab2ac7b 100644 --- a/Formatting/Posh/Posh.format.ps1 +++ b/Formatting/Posh/Posh.format.ps1 @@ -14,4 +14,19 @@ Write-FormatView -TypeName Posh -Action { Write-FormatViewExpression -Style "Foreground.Green" -ScriptBlock { $_.PrivateData.ExtendedDescription } + + Write-FormatViewExpression -Newline + Write-FormatViewExpression -Newline + + Write-FormatViewExpression -Style 'Foreground.Cyan' -ScriptBlock { + "To see PowerShell tips, use `$posh.Tips" + } + + Write-FormatViewExpression -Newline + + Write-FormatViewExpression -Style 'Foreground.Cyan' -ScriptBlock { + "To see PowerShell links, use `$posh.Links" + } + + Write-FormatViewExpression -Newline } \ No newline at end of file diff --git a/Formatting/RegEx/MatchInfo.format.ps1 b/Formatting/RegEx/MatchInfo.format.ps1 new file mode 100644 index 0000000..576e2b9 --- /dev/null +++ b/Formatting/RegEx/MatchInfo.format.ps1 @@ -0,0 +1,56 @@ +Write-FormatView -TypeName Microsoft.PowerShell.Commands.MatchInfo -Action { + $matchInfo = $_ + $isFileMatch = $matchInfo.Path -and ($matchInfo.Path -ne 'InputStream') + $currentLocation = $ExecutionContext.SessionState.Path.CurrentLocation + $relativePath = $matchInfo.RelativePath($currentLocation) + $originalLine = $( + if ($matchInfo.ToEmphasizedString) { + $matchInfo.ToEmphasizedString($currentLocation) + } elseif ($isFileMatch) { + $matchInfo.ToString().Replace($matchInfo.Path, $relativePath) + } else { + $matchInfo.ToString() + } + ) + + if ($PSStyle) { + $PoshModule = $posh + if ($isFileMatch) { + # Match in a file item + $colorTable = @( + $PSStyle.Foreground.Green + $PSStyle.Foreground.Yellow + ) + + $colorIndex = . $PoshModule { + # Create a module scope variable + if (-not $script:MatchInfoColorIndex) { + $script:MatchInfoColorIndex = @{ + index = 0 + lastFilepath = $args[0] + } + } + $script:MatchInfoColorIndex + } $relativePath + if ($colorIndex.lastFilepath -ne $relativePath) { + $colorIndex.index = ($colorIndex.index + 1) % $colorTable.Count + $colorIndex.lastFilepath = $relativePath + } + + $color = $colorTable[$colorIndex.index] + $coloredPath = $color + $relativePath + $PSStyle.Reset + + if ($PSStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { + $hyperLink = $PSStyle.FormatHyperlink($coloredPath, $matchInfo.Path) + $originalLine.Replace($relativePath, $hyperLink) + } else { + $originalLine.Replace($relativePath, $coloredPath) + } + } else { + # Match in a text input + $originalLine + } + } else { + $originalLine + } +} diff --git a/Formatting/XML/SelectXmlInfo.format.ps1 b/Formatting/XML/SelectXmlInfo.format.ps1 new file mode 100644 index 0000000..556c3f9 --- /dev/null +++ b/Formatting/XML/SelectXmlInfo.format.ps1 @@ -0,0 +1 @@ +Write-FormatView -TypeName Microsoft.PowerShell.Commands.SelectXmlInfo -Property Node, Pattern -GroupByProperty "Path" \ No newline at end of file diff --git a/Posh.format.ps1xml b/Posh.format.ps1xml index 4dfccff..f9188b4 100644 --- a/Posh.format.ps1xml +++ b/Posh.format.ps1xml @@ -92,6 +92,58 @@ $script:TreeDepth++; + + Posh.Link + + + + + + + @( + if ($_.Name -and $_.Url) { + if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { + $psStyle.FormatHyperlink($_.Name, $_.Url) + } else { + "[$($_.Name)]($($_.Url))" + } + } elseif ($_.Url) { + $uri = [uri]$_.Url + if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { + $psStyle.FormatHyperlink($_.Url, $uri) + } else { + "[$($_.Url)]($($uri))" + } + } + ) -join '' + + + + + + + + + Posh.Tip.Control + + + + + + + $showDemoCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand('Show-Demo', 'Function') + if ($showDemoCommand -and $_.Content -is [scriptblock]) { + Show-Demo -DemoScript $_.Content -AutoPlay | Out-Null + } else { + $_.Content + } + + + + + + + TypeBase @@ -2298,8 +2350,13 @@ if ($Request -or $Host.UI.SupportsHTML) { } else { $(if ($_ -is [IO.DirectoryInfo]) { - $PSStyle.FileInfo.Directory - "`u{1F5BF} " + $PSStyle.FileInfo.Directory + if ($PSStyle.FileInfo.DirectoryIcon) { + "$($PSStyle.FileInfo.DirectoryIcon)" + " " + } else { + "▶ " + } + } else { if ( $PSStyle.FileInfo.Extension.Keys -and @@ -2327,8 +2384,8 @@ if ($Request -or $Host.UI.SupportsHTML) { $extraSpace = $true - if ($Posh.FileIcons) { - + if ($psStyle.FileInfo.ExtensionIcon -and $psStyle.FileInfo.ExtensionIcon[$_.Extension]) { + "$($psStyle.FileInfo.ExtensionIcon[$_.Extension]) " } else { $(switch ($_.Extension) { @@ -2565,6 +2622,58 @@ if ($Request -or $Host.UI.SupportsHTML) { } + + + + if ($psStyle) { + @(foreach ($styleProp in 'Foreground.Cyan') { + if ($styleProp -match '\.') { + $styleGroup, $styleProp = $styleProp -split '\.' + $psStyle.$styleGroup.$styleProp + } else { + $psStyle.$styleProp + } + }) -ne '' -join '' +} + + + + "To see PowerShell tips, use `$posh.Tips" + + + + + if ($PSStyle) { + $PSStyle.Reset + } + + + + + if ($psStyle) { + @(foreach ($styleProp in 'Foreground.Cyan') { + if ($styleProp -match '\.') { + $styleGroup, $styleProp = $styleProp -split '\.' + $psStyle.$styleGroup.$styleProp + } else { + $psStyle.$styleProp + } + }) -ne '' -join '' +} + + + + "To see PowerShell links, use `$posh.Links" + + + + + if ($PSStyle) { + $PSStyle.Reset + } + + + @@ -2692,6 +2801,56 @@ if ($Request -or $Host.UI.SupportsHTML) { + + Posh.Module.Link + + Posh.Module.Link + + + Source + + + + + + + $_ + Posh.Link + + + + + + + + Posh.Module.Link + + Posh.Module.Link + + + Source + + + + + + + + + + + + + Name + + + Url + + + + + + Posh.Module.Logo @@ -2771,24 +2930,8 @@ if ($Request -or $Host.UI.SupportsHTML) { - - @( - if ($_.Name -and $_.Url) { - if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { - $psStyle.FormatHyperlink($_.Name, $_.Url) - } else { - "![$($_.Name)]($($_.Url))" - } - } elseif ($_.Url) { - $uri = [uri]$_.Url - if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { - $psStyle.FormatHyperlink($_.Url, $uri) - } else { - "![$($_.Url)]($($uri))" - } - } - ) -join '' - + $_ + Posh.Link @@ -2837,24 +2980,8 @@ if ($Request -or $Host.UI.SupportsHTML) { - - @( - if ($_.Name -and $_.Url) { - if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { - $psStyle.FormatHyperlink($_.Name, $_.Url) - } else { - "[$($_.Name)]($($_.Url))" - } - } elseif ($_.Url) { - $uri = [uri]$_.Url - if ($psStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { - $psStyle.FormatHyperlink($_.Url, $uri) - } else { - "[$($_.Url)]($($uri))" - } - } - ) -join '' - + $_ + Posh.Link @@ -2971,6 +3098,26 @@ if ($Request -or $Host.UI.SupportsHTML) { + + Posh.Preset.Collection + + Posh.Preset.Collection + + + + + + + + Show-Markdown -InputObject $_.README + + + + + + + + Posh.Profiles @@ -3243,56 +3390,35 @@ if ($Request -or $Host.UI.SupportsHTML) { - Posh.Resources + Posh.Tip.Collection - Posh.Resources + Posh.Tip.Collection - - $_.README - - - Show-Markdown -InputObject $_.README - + Random + Posh.Tip.Control - + + + + + + + Posh.Tip.Command + + Posh.Tip.Command + + + + + - $moduleName = 'Posh' - - do { - $lm = Get-Module -Name $moduleName -ErrorAction Ignore - if (-not $lm) { continue } - if ($lm.FormatPartsLoaded) { break } - $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { - foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { - $ParentNode = $partNodeName.Node.ParentNode - "$($ParentNode.Name)={ - $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" - } - }) -join [Environment]::NewLine - New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | - Import-Module -Global - $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") - - if (-not $lm.OnRemove) { - $lm.OnRemove = $onRemove - } else { - $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) - } - $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force - - } while ($false) - - - - $_ | - Select-Object -ExcludeProperty README -Property * | - & ${Posh_Format-Yaml} - + $_ + Posh.Tip.Control @@ -3680,6 +3806,107 @@ if ($Request -or $Host.UI.SupportsHTML) { + + Microsoft.PowerShell.Commands.MatchInfo + + Microsoft.PowerShell.Commands.MatchInfo + + + + + + + + $matchInfo = $_ + $isFileMatch = $matchInfo.Path -and ($matchInfo.Path -ne 'InputStream') + $currentLocation = $ExecutionContext.SessionState.Path.CurrentLocation + $relativePath = $matchInfo.RelativePath($currentLocation) + $originalLine = $( + if ($matchInfo.ToEmphasizedString) { + $matchInfo.ToEmphasizedString($currentLocation) + } elseif ($isFileMatch) { + $matchInfo.ToString().Replace($matchInfo.Path, $relativePath) + } else { + $matchInfo.ToString() + } + ) + + if ($PSStyle) { + $PoshModule = $posh + if ($isFileMatch) { + # Match in a file item + $colorTable = @( + $PSStyle.Foreground.Green + $PSStyle.Foreground.Yellow + ) + + $colorIndex = . $PoshModule { + # Create a module scope variable + if (-not $script:MatchInfoColorIndex) { + $script:MatchInfoColorIndex = @{ + index = 0 + lastFilepath = $args[0] + } + } + $script:MatchInfoColorIndex + } $relativePath + if ($colorIndex.lastFilepath -ne $relativePath) { + $colorIndex.index = ($colorIndex.index + 1) % $colorTable.Count + $colorIndex.lastFilepath = $relativePath + } + + $color = $colorTable[$colorIndex.index] + $coloredPath = $color + $relativePath + $PSStyle.Reset + + if ($PSStyle.FormatHyperlink -and -not $env:GITHUB_WORKSPACE) { + $hyperLink = $PSStyle.FormatHyperlink($coloredPath, $matchInfo.Path) + $originalLine.Replace($relativePath, $hyperLink) + } else { + $originalLine.Replace($relativePath, $coloredPath) + } + } else { + # Match in a text input + $originalLine + } + } else { + $originalLine + } + + + + + + + + + Microsoft.PowerShell.Commands.SelectXmlInfo + + Microsoft.PowerShell.Commands.SelectXmlInfo + + + Path + + + + + + + + + + + + + Node + + + Pattern + + + + + + System.Xml.XmlElement diff --git a/Posh.ps.psm1 b/Posh.ps.psm1 index e443651..39e0600 100644 --- a/Posh.ps.psm1 +++ b/Posh.ps.psm1 @@ -37,6 +37,7 @@ $Posh.pstypenames.Insert(0,'Posh') $stackableFunctions = [Ordered]@{ Prompt = 'prompt' Input = 'PSConsoleHostReadLine' + TabExpansion = 'TabExpansion2' } foreach ($stackableFunctionKeyValue in $stackableFunctions.GetEnumerator()) { @@ -84,21 +85,6 @@ $poshCommands = $posh | Add-Member NoteProperty Commands $poshCommands -Force -$PoshResources = [Ordered]@{ - PSTypeName = 'Posh.Resources' - 'PowerShell Guide' = 'https://PowerShellGuide.com/' - 'PowerShell.Org' = 'https://powershell.org/' - 'PowerShell Discord' = 'https://discord.com/invite/powershell' - 'PowerShell Project' = 'https://github.com/PowerShell/PowerShell' - 'PowerShell GitHub' = 'https://github.com/topics/powershell' - 'PowerShell Twitter' = 'https://twitter.com/search?q=%23PowerShell' - 'PowerShell Facebook' = 'https://www.facebook.com/groups/powershell/' - 'PowerShell LinkedIn' = 'https://www.linkedin.com/feed/hashtag/?keywords=powershell' - 'PoshProject' = $posh.PrivateData.PSData.ProjectURI -} - -$posh | Add-Member NoteProperty Resources ([PSCustomObject]$PoshResources) - Export-ModuleMember -Variable posh $posh.OnRemove = { diff --git a/Posh.psd1 b/Posh.psd1 index 8a52004..a0f351e 100644 --- a/Posh.psd1 +++ b/Posh.psd1 @@ -1,5 +1,5 @@ @{ - ModuleVersion = '0.1.2' + ModuleVersion = '0.1.3' FormatsToProcess = 'Posh.format.ps1xml' TypesToProcess = 'Posh.types.ps1xml' RootModule = 'Posh.psm1' @@ -15,6 +15,57 @@ IconURI = 'https://raw.githubusercontent.com/StartAutomating/Posh/main/Assets/Posh.png' Tags = 'Posh', '.ps1xml', 'Format','Output','Types', 'Colorized', 'Prompt', 'Customization' ReleaseNotes = @' +## Posh 0.1.3: Posh Tips and Tricks + +* New Formatting: + * Adding Select-XML Formatter (#107) + * Posh.Preset.Collection (#153) + * Posh.Tip.Command (#166) +* Updated Formatting: + * Making DirectoryIcon customizable / changing default to triangle (#169) + * Integrating Tips/Links into Posh Formatting (#165) + * Improving Formatting of Select-String (#109) (thanks @mdgrs-mei ! ) +* Added Tips and Tricks to Modules (#118) and added the first round of tips/tricks: + * NegativeIndexingFibonacci Trick (#168) + * GenericTypes Tip (#167) + * Ordered Hashtables Tip (#156) + * Hashtables Tip (#155) + * AssigningLoopOutput Tip (#145) + * RangeOperator Tip (#151) + * NegativeIndex Tip (#150) + * TernaryOperator Tip (#148) + * Creating PsuedoObjects Trick (#144) + * AssigningIfStatements Tip (#144) + * Tip - Trinity of Discoverability (#142) + * Tip - You Can Get Help On a Script (#147) + * Tip - Everything Is An Object (#140) + * Trick - The Parameter Set That Was Not There (#141) + * Multiple Assignment Tip (#143) + * LoopLabels Tip (#146) + * see issues #166 +* New Extended Types: + * Posh.Preset.Collection (#153) + * Posh.Preset.Command (#154) + * Posh.ExtensionCollection + * .Count (#162) + * .Refresh() (#123) + * .Random (#124) + * .All (#128) + * get/set .CommandType (#127) + * get/set .Path (#126) + * get/set Module (#125) +* Updated Extended Types + * PSModuleInfo.Link (#64/#157/#158/#159/#160) + * PSModuleInfo.Preset (#64/#153) + * PSModuleInfo.Tip(s)/Trick(s) (#119, #120) + * $Posh.Host.get/set_Title (#130) + * Fixing stackable functions (#110, thanks @mdgrs-mei !) +* Updating Posh.Preset.Command.Use help (#154) +* Adding FileIcons Preset (#163) +* Making TabExpansion Stackable (#116) + +--- + ## Posh 0.1.2: * New Demos @@ -84,13 +135,28 @@ Pattern = '\.(?>PowerShell|Posh)\.Preset\.(?>psd1|json|clixml)$' Description = "A data file that defines a PowerShell preset." } - "Posh.Trivia" = @{ - Pattern = '\.(?>PowerShell|Posh)\.Trivia\.psd1$' + "Posh.Tip" = @{ + Pattern = ' + (?:\.(?>PowerShell|Posh))? # Optional Posh or PowerShell + \.(?>Tips?|Tricks?|Trivia) # dot followed by Tip(s), Tricks(s), or Trivia + (?:\.(?>psd1|ps1|txt|md|json|clixml)$) # match the extension + ' } } Recommends = "EZOut", "PipeScript", "HelpOut", "PSSVG", "Splatter", "ShowDemo" + Links = @{ + 'PowerShell Guide' = 'https://PowerShellGuide.com/' + 'PowerShell.Org' = 'https://powershell.org/' + 'PowerShell Discord' = 'https://discord.com/invite/powershell' + 'PowerShell Project' = 'https://github.com/PowerShell/PowerShell' + 'PowerShell GitHub' = 'https://github.com/topics/powershell' + 'PowerShell Twitter' = 'https://twitter.com/search?q=%23PowerShell' + 'PowerShell Facebook' = 'https://www.facebook.com/groups/powershell/' + 'PowerShell LinkedIn' = 'https://www.linkedin.com/feed/hashtag/?keywords=powershell' + } + Screenshot = @{ "Improved-File-Formatting" = "https://raw.githubusercontent.com/StartAutomating/Posh/main/Assets/Improved-File-Formatting.gif" "Get-Command-In-Color" = "https://raw.githubusercontent.com/StartAutomating/Posh/main/Assets/Get-Command-In-Color.gif" diff --git a/Posh.psm1 b/Posh.psm1 index 7b28f59..8d1266e 100644 --- a/Posh.psm1 +++ b/Posh.psm1 @@ -41,6 +41,7 @@ $Posh.pstypenames.Insert(0,'Posh') $stackableFunctions = [Ordered]@{ Prompt = 'prompt' Input = 'PSConsoleHostReadLine' + TabExpansion = 'TabExpansion2' } foreach ($stackableFunctionKeyValue in $stackableFunctions.GetEnumerator()) { @@ -88,21 +89,6 @@ $poshCommands = $posh | Add-Member NoteProperty Commands $poshCommands -Force -$PoshResources = [Ordered]@{ - PSTypeName = 'Posh.Resources' - 'PowerShell Guide' = 'https://PowerShellGuide.com/' - 'PowerShell.Org' = 'https://powershell.org/' - 'PowerShell Discord' = 'https://discord.com/invite/powershell' - 'PowerShell Project' = 'https://github.com/PowerShell/PowerShell' - 'PowerShell GitHub' = 'https://github.com/topics/powershell' - 'PowerShell Twitter' = 'https://twitter.com/search?q=%23PowerShell' - 'PowerShell Facebook' = 'https://www.facebook.com/groups/powershell/' - 'PowerShell LinkedIn' = 'https://www.linkedin.com/feed/hashtag/?keywords=powershell' - 'PoshProject' = $posh.PrivateData.PSData.ProjectURI -} - -$posh | Add-Member NoteProperty Resources ([PSCustomObject]$PoshResources) - Export-ModuleMember -Variable posh $posh.OnRemove = { diff --git a/Posh.types.ps1xml b/Posh.types.ps1xml index be35eb6..c94e86d 100644 --- a/Posh.types.ps1xml +++ b/Posh.types.ps1xml @@ -97,24 +97,6 @@ Get-Job Get-Module - - Presets - - # Get-Module -$moduleRoots = Get-Module | Split-Path | Select-Object -Unique - - -foreach ($extensionFile in $posh.Commands.FindExtensions.Invoke(@( - $posh - $moduleRoots - )) -) { - if ($extensionFile.pstypenames -contains 'Posh.Preset.Command') { - $extensionFile - } -} - - Process @@ -817,6 +799,162 @@ Get-History -Id $historyIDS + + Posh.ExtensionCollection + + + Refresh + + + + All + + <# +.SYNOPSIS + Gets all items in an extension collection. +.DESCRIPTION + Gets all items in a collection of extended commands. +#> +if (-not $this.'.Cache') { + if (-not $this.'.Module') { return @() } + + $findExtensionArgs = @($this.'.Module') + @($this.'.Path') + $allExtensionsFound = + @(:nextExtension + foreach ($foundExtension in + $posh.Commands.FindExtensions.Invoke($findExtensionArgs) + ) + { + if ($this.'.CommandType') { + foreach ($typename in $this.'.CommandType') { + if ($foundExtension.pstypenames -contains $typename) { + $foundExtension + continue nextExtension + } + } + } else { + $foundExtension + } + } + ) + $this | + Add-Member NoteProperty '.Cache' $allExtensionsFound -Force +} + +return $this.'.Cache' + + + + CommandType + + <# +.SYNOPSIS + Gets an extension collection's CommandType +.DESCRIPTION + Gets the extended CommandTypes(s) that are stored in an extension collection. + + CommandTypes can be defined in a module's manifest. +#> +return $this.'.CommandType' + + + <# +.SYNOPSIS + Sets an extension collection's command type +.DESCRIPTION + Sets the extended command types in an extension collection. +#> +param( +# The path. If this is empty all extended commands will be present in the collection +[string[]] +$CommandType +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.CommandType' -Value $CommandType -Force + + + + Count + + <# +.SYNOPSIS + Gets the extension count. +.DESCRIPTION + Gets the count of all extensions in a collection. +#> +$this.All.Length + + + + Module + + <# +.SYNOPSIS + Gets an extension collection's module +.DESCRIPTION + Gets the module that defines extended types in an extension collection. +#> +return $this.'.Module' + + + <# +.SYNOPSIS + Sets an extension collection's module +.DESCRIPTION + Sets the module that defines extended command types in an extension collection. +#> +param( +# The module. +[Management.Automation.PSModuleInfo] +$Module +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.Module' -Value $module -Force + + + + Path + + <# +.SYNOPSIS + Gets an extension collection's Path +.DESCRIPTION + Gets the Path(s) that store extensions in an extension collection. +#> +return $this.'.Path' + + + <# +.SYNOPSIS + Sets an extension collection's path +.DESCRIPTION + Sets the path that defines extended command types in an extension collection. +#> +param( +# The path. If this is empty, only extensions that are functions or aliases will be found. +[string[]] +$Path +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.Path' -Value $Path -Force + + + + Random + + <# +.SYNOPSIS + Gets a random extended command +.DESCRIPTION + Gets a random extended command from an ExtensionCollection. +#> +$this.All | Get-Random + + + + Posh.Host @@ -836,6 +974,39 @@ Get-History -Id $historyIDS $this.UI.RawUI.BufferSize.Height + + Title + + <# +.SYNOPSIS + Gets the host's title +.DESCRIPTION + Gets the host's window title. +.EXAMPLE + $Posh.Title +#> +$this.UI.RawUI.WindowTitle + + + + <# +.SYNOPSIS + Sets the host's title +.DESCRIPTION + Sets the host's window title. + + Unfortunately, this will be ignored if running in Visual Studio Code. +.EXAMPLE + $Posh.Title = "Sup?" +#> +param( +[string] +$Title +) +$this.UI.RawUI.WindowTitle = $title + + + Width @@ -944,7 +1115,7 @@ $Value -$toPrepend = $this.Stringify($prompt) +$toPrepend = $this.Stringify($Value) $currentFunction = $posh.ExecutionContext.SessionState.InvokeCommand.InvokeScript("`$function:$($this.FunctionName)") $this.Current = "@(. { $toPrepend} ; . { $currentFunction }) -join ''" @@ -1015,7 +1186,7 @@ foreach ($arg in $args) { } } $newFunc = "@( - `$existingOutput =. { $function:prompt }; + `$existingOutput =. { $currentFunction }; `$replacePattern = $replaceRegex `$replaceWith = $toReplace `$replacePattern.Replace(`$existingOutput, `$replaceWith) @@ -1253,6 +1424,250 @@ You can also provide default values for any command's parameters. + + Posh.Preset.Collection + + + Refresh + + + + All + + <# +.SYNOPSIS + Gets all items in an extension collection. +.DESCRIPTION + Gets all items in a collection of extended commands. +#> +if (-not $this.'.Cache') { + if (-not $this.'.Module') { return @() } + + $findExtensionArgs = @($this.'.Module') + @($this.'.Path') + $allExtensionsFound = + @(:nextExtension + foreach ($foundExtension in + $posh.Commands.FindExtensions.Invoke($findExtensionArgs) + ) + { + if ($this.'.CommandType') { + foreach ($typename in $this.'.CommandType') { + if ($foundExtension.pstypenames -contains $typename) { + $foundExtension + continue nextExtension + } + } + } else { + $foundExtension + } + } + ) + $this | + Add-Member NoteProperty '.Cache' $allExtensionsFound -Force +} + +return $this.'.Cache' + + + + CommandType + + <# +.SYNOPSIS + Gets an extension collection's CommandType +.DESCRIPTION + Gets the extended CommandTypes(s) that are stored in an extension collection. + + CommandTypes can be defined in a module's manifest. +#> +return $this.'.CommandType' + + + <# +.SYNOPSIS + Sets an extension collection's command type +.DESCRIPTION + Sets the extended command types in an extension collection. +#> +param( +# The path. If this is empty all extended commands will be present in the collection +[string[]] +$CommandType +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.CommandType' -Value $CommandType -Force + + + + Count + + <# +.SYNOPSIS + Gets the extension count. +.DESCRIPTION + Gets the count of all extensions in a collection. +#> +$this.All.Length + + + + Module + + <# +.SYNOPSIS + Gets an extension collection's module +.DESCRIPTION + Gets the module that defines extended types in an extension collection. +#> +return $this.'.Module' + + + <# +.SYNOPSIS + Sets an extension collection's module +.DESCRIPTION + Sets the module that defines extended command types in an extension collection. +#> +param( +# The module. +[Management.Automation.PSModuleInfo] +$Module +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.Module' -Value $module -Force + + + + Path + + <# +.SYNOPSIS + Gets an extension collection's Path +.DESCRIPTION + Gets the Path(s) that store extensions in an extension collection. +#> +return $this.'.Path' + + + <# +.SYNOPSIS + Sets an extension collection's path +.DESCRIPTION + Sets the path that defines extended command types in an extension collection. +#> +param( +# The path. If this is empty, only extensions that are functions or aliases will be found. +[string[]] +$Path +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.Path' -Value $Path -Force + + + + Random + + <# +.SYNOPSIS + Gets a random extended command +.DESCRIPTION + Gets a random extended command from an ExtensionCollection. +#> +$this.All | Get-Random + + + + README + ## Posh Presets + +Posh Presets provide a way to store and apply presets for a variable. + +They are simply data files, where each key or property repesents a expression and it's value represents what it will be set to. + +Preset files can be .psd1, .json, or .clixml. + +To see what presets can do, use $Posh.Presets | Get-Member + + + + + Posh.Preset.Command + + + Apply + Use + + + Use + + + + Posh.Profiles @@ -1668,7 +2083,7 @@ $Value -$toPrepend = $this.Stringify($prompt) +$toPrepend = $this.Stringify($Value) $currentFunction = $posh.ExecutionContext.SessionState.InvokeCommand.InvokeScript("`$function:$($this.FunctionName)") $this.Current = "@(. { $toPrepend} ; . { $currentFunction }) -join ''" @@ -1739,7 +2154,7 @@ foreach ($arg in $args) { } } $newFunc = "@( - `$existingOutput =. { $function:prompt }; + `$existingOutput =. { $currentFunction }; `$replacePattern = $replaceRegex `$replaceWith = $toReplace `$replacePattern.Replace(`$existingOutput, `$replaceWith) @@ -1922,7 +2337,7 @@ $Value -$toPrepend = $this.Stringify($prompt) +$toPrepend = $this.Stringify($Value) $currentFunction = $posh.ExecutionContext.SessionState.InvokeCommand.InvokeScript("`$function:$($this.FunctionName)") $this.Current = "@(. { $toPrepend} ; . { $currentFunction }) -join ''" @@ -1993,7 +2408,7 @@ foreach ($arg in $args) { } } $newFunc = "@( - `$existingOutput =. { $function:prompt }; + `$existingOutput =. { $currentFunction }; `$replacePattern = $replaceRegex `$replaceWith = $toReplace `$replacePattern.Replace(`$existingOutput, `$replaceWith) @@ -2076,6 +2491,35 @@ $posh.ExecutionContext.SessionState.PSVariable.Set("function:$($this.FunctionNam + + Posh.Tip.Command + + + Content + + switch -regex ($this.Source) { + '\.psd1$' { + (Import-LocalizedData -BaseDirectory ($this.Source | Split-Path) -FileName ($this.Source | Split-Path -Leaf)).Content + } + '\.json$' { + (Get-Content $this.Source -Raw | ConvertFrom-Json).Content + } + '\.md$' { + Show-Markdown -LiteralPath $this.Source + } + '\.ps1$' { + $showDemoCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand('Show-Demo', 'Function') + if ($showDemoCommand) { + $this.ScriptBlock + } else { + Get-Content $this.Source -Raw + } + } +} + + + + System.Management.Automation.PSModuleInfo @@ -2083,10 +2527,26 @@ $posh.ExecutionContext.SessionState.PSVariable.Set("function:$($this.FunctionNam Demos Demo + + Links + Link + + + Presets + Preset + Recommendations Recommendation + + Resource + Link + + + Resources + Link + Screenshots Screenshot @@ -2095,6 +2555,18 @@ $posh.ExecutionContext.SessionState.PSVariable.Set("function:$($this.FunctionNam Tests Test + + Tips + Tip + + + Trick + Tip + + + Tricks + Tip + Videos Video @@ -2167,6 +2639,31 @@ $this | Select-Object -Unique + + Link + + <# +.SYNOPSIS + Gets Module Links +.DESCRIPTION + Lists hyperlinks from this module. +.EXAMPLE + $posh.Links +#> +$this.LinkList(@( + $this.PrivateData.Link + $this.PrivateData.Links + $this.PrivateData.Resource + $this.PrivateData.Resources + $this.PrivateData.PSData.Link + $this.PrivateData.PSData.Links + $this.PrivateData.PSData.Resource + $this.PrivateData.PSData.Resources +), "Posh.Module.Link") + + + + Logo @@ -2189,6 +2686,38 @@ $this.LinkList(@( + + Preset + + <# +.SYNOPSIS + Get's a module's presets +.DESCRIPTION + Gets presets from a module. + + Any module can contain `*.preset(s)` files, of the extensions: + + * .psd1 + * .json + * .clixml + + The collection of presets can be accessed in a Module's .Preset(s) properties +#> +if (-not $this.'.Preset') { + $PresetCollection = + [PSCustomObject][Ordered]@{ + PSTypeName = 'Posh.ExtensionCollection' + Module = $posh + Path = @(Get-Module | Split-Path) -as [string[]] + CommandType = 'Posh.Preset.Command' + } + $PresetCollection.pstypenames.insert(0,'Posh.Preset.Collection') + $this | + Add-Member NoteProperty '.Preset' $PresetCollection -Force +} +$this.'.Preset' + + Recommendation @@ -2258,6 +2787,42 @@ $this | Select-Object -Unique + + Tip + + <# +.SYNOPSIS + Get's a module's tips +.DESCRIPTION + Gets tips and tricks from a module. + + Any module can contain `*.tip(s)` or `*.trick(s)` files, of the extensions: + + * .md + * .txt + * .ps1 + * .psd1 + * .json + * .clixml + + The collection of tips can be accessed in a Module's .Tip(s) or .Trick(s) properties + +#> +if (-not $this.'.Tip') { + $tipCollection = + [PSCustomObject][Ordered]@{ + PSTypeName = 'Posh.ExtensionCollection' + Module = $posh + Path = $this.Path | Split-Path + CommandType = 'Posh.Tip.Command' + } + + $tipCollection.pstypenames.insert(0,'Posh.Tip.Collection') + $this | Add-Member NoteProperty '.Tip' $tipCollection -Force +} +$this.'.Tip' + + Video diff --git a/Presets/FileIcons.Posh.Preset.psd1 b/Presets/FileIcons.Posh.Preset.psd1 new file mode 100644 index 0000000..e150990 --- /dev/null +++ b/Presets/FileIcons.Posh.Preset.psd1 @@ -0,0 +1,43 @@ +@{ + '$psStyle.FileInfo.ExtensionIcon' = @{ + '.ps1' = "⟩" + '.sh' = '⟩' + '.zip' = "◈" + '.deb' = "◈" + '.pkg' = "◈" + '.nupkg' = "◈" + '.msixbundle' = "◈" + '.iso' = '◈' + '.srt' = '⧳' + '.vtt' = '⧳' + '.exe' = '⋇' + '.psd1'= "⧳" # ⨇ + '.psm1'= '⧳' # '⨈' + '.ttf' = '🗛' + '.woff' = '🗛' + '.fon' = '🗛' + '.ttc' = '🗛' + '.json' = "⧳" + '.mp3' ='♬' + '.wav' ='♬' + '.txt' = '≣' + '.md' = '≣' + '.inf' ='⚙' + '.ini' ='⚙' + '.mpg' ='▰' + '.mp4' ='▰' + '.mkv' ='▰' + '.avi' ='▰' + '.gif' ='▰' + '.jpg' = '▭' + '.png' = '▭' + '.svg' = '⬢' + '.ico' = '⬢' + '.ps1xml' = "⧳" + '.clixml' = "⧳" + '.clix' = "⧳" + '.xml' = "⧳" + } +} + + diff --git a/TipsAndTricks/AddingHashtables.Tip.ps1 b/TipsAndTricks/AddingHashtables.Tip.ps1 new file mode 100644 index 0000000..d8a9791 --- /dev/null +++ b/TipsAndTricks/AddingHashtables.Tip.ps1 @@ -0,0 +1,2 @@ +# You can add two hashtables together in PowerShell +@{a='b'} + @{c='d'} diff --git a/TipsAndTricks/AssigningIfStatements.Tip.ps1 b/TipsAndTricks/AssigningIfStatements.Tip.ps1 new file mode 100644 index 0000000..f381239 --- /dev/null +++ b/TipsAndTricks/AssigningIfStatements.Tip.ps1 @@ -0,0 +1,10 @@ +# In PowerShell, you can assign the results of any expression. + +# Including an `if`! + +$IsFriday = + if ([DateTime]::now.DayOfWeek -as [int] -eq 5) { + $true + } + +$IsFriday \ No newline at end of file diff --git a/TipsAndTricks/AssigningLoopOutput.Tip.ps1 b/TipsAndTricks/AssigningLoopOutput.Tip.ps1 new file mode 100644 index 0000000..91d321e --- /dev/null +++ b/TipsAndTricks/AssigningLoopOutput.Tip.ps1 @@ -0,0 +1,10 @@ +# You can assign the output of a loop in PowerShell + +$OddNumbers = + foreach ($n in 1..100) { + if ($n % 2) { + $n + } + } + +$OddNumbers diff --git a/TipsAndTricks/CreatingPsuedoObjects.Trick.ps1 b/TipsAndTricks/CreatingPsuedoObjects.Trick.ps1 new file mode 100644 index 0000000..48f8914 --- /dev/null +++ b/TipsAndTricks/CreatingPsuedoObjects.Trick.ps1 @@ -0,0 +1,5 @@ +# You can make psuedoobjects out of thin air! + +[PSCustomObject][Ordered]@{ + Name = "James" +} \ No newline at end of file diff --git a/TipsAndTricks/EverythingIsAnObject.Tip.ps1 b/TipsAndTricks/EverythingIsAnObject.Tip.ps1 new file mode 100644 index 0000000..00f06b1 --- /dev/null +++ b/TipsAndTricks/EverythingIsAnObject.Tip.ps1 @@ -0,0 +1,3 @@ +# Everything is an object in PowerShell. + +"Everything is an object in PowerShell" | Get-Member \ No newline at end of file diff --git a/TipsAndTricks/GenericTypes.Tip.ps1 b/TipsAndTricks/GenericTypes.Tip.ps1 new file mode 100644 index 0000000..89a0b53 --- /dev/null +++ b/TipsAndTricks/GenericTypes.Tip.ps1 @@ -0,0 +1,12 @@ +# You can use generic types in PowerShell. + +# Just include inner types in inner brackets +[Collections.Generic.List[BigInt]]::new( + [BigInt[]]@(0,1) +) + +# Whitespace does not matter too much. +[Collections.Generic.Dictionary[ + string, + PSObject +]]::new() + @{a='b'} \ No newline at end of file diff --git a/TipsAndTricks/LoopLabels.Tip.ps1 b/TipsAndTricks/LoopLabels.Tip.ps1 new file mode 100644 index 0000000..ae3df75 --- /dev/null +++ b/TipsAndTricks/LoopLabels.Tip.ps1 @@ -0,0 +1,10 @@ +# Loops can have labels! + +:GameLoop do { + if ($Game.Playing) { + continue GameLoop + } +} while ($false) + +# This makes it easier to control when a loop exits. + diff --git a/TipsAndTricks/MultipleAssignment.Tip.ps1 b/TipsAndTricks/MultipleAssignment.Tip.ps1 new file mode 100644 index 0000000..7d7bc0c --- /dev/null +++ b/TipsAndTricks/MultipleAssignment.Tip.ps1 @@ -0,0 +1,3 @@ +# You can assign multiple variables in one assignment +$one, $two = 1,2 + diff --git a/TipsAndTricks/NegativeIndexing.Tip.ps1 b/TipsAndTricks/NegativeIndexing.Tip.ps1 new file mode 100644 index 0000000..e575410 --- /dev/null +++ b/TipsAndTricks/NegativeIndexing.Tip.ps1 @@ -0,0 +1,4 @@ +# Collections that take an integer index can be negative indexed. + +# This will look backwards thru a collection +@(1..100)[-2] \ No newline at end of file diff --git a/TipsAndTricks/NegativeIndexingFibonacci.Trick.ps1 b/TipsAndTricks/NegativeIndexingFibonacci.Trick.ps1 new file mode 100644 index 0000000..3eceedc --- /dev/null +++ b/TipsAndTricks/NegativeIndexingFibonacci.Trick.ps1 @@ -0,0 +1,18 @@ +# People spend so much time demonstrating Fibonacci recursively +# Let's show how we can do this iteratively with negative indexing +& { + param( + [ValidateRange(0,2kb)] + $FibonacciNumber + ) + + $FibonacciSequenece = [Collections.Generic.List[BigInt]]::new([BigInt[]]@(0,1)) + + do { + $FibonacciSequenece.Add( + $FibonacciSequenece[-1] + $FibonacciSequenece[-2] + ) + } while ($FibonacciSequenece.Count -lt $FibonacciNumber) + $FibonacciSequenece + +} -FibonacciNumber 17 \ No newline at end of file diff --git a/TipsAndTricks/OrderedHashtables.Tip.ps1 b/TipsAndTricks/OrderedHashtables.Tip.ps1 new file mode 100644 index 0000000..48cc028 --- /dev/null +++ b/TipsAndTricks/OrderedHashtables.Tip.ps1 @@ -0,0 +1,13 @@ +# PowerShell hashtables are not always stored in the order they are declared. +@{ + MaybeFirstKey = 1 + MaybeSecondKey = 2 + MaybeThirdKey = 3 +} + +# If you want to ensure the order of hashtables, cast them to [Ordered] +[Ordered]@{ + FirstKey = 1 + SecondKey = 2 + ThirdKey = 3 +} diff --git a/TipsAndTricks/RangeOperator.Tip.ps1 b/TipsAndTricks/RangeOperator.Tip.ps1 new file mode 100644 index 0000000..2497352 --- /dev/null +++ b/TipsAndTricks/RangeOperator.Tip.ps1 @@ -0,0 +1,9 @@ +# PowerShell has a range operator + +1..10 + +# Ranges can be variables or expressions +(Get-Random -Min 1 -Max 10)..(Get-Random -Min 1 -Max 10) + +# You can also use ranges to index. +@(1..10)[0..4] \ No newline at end of file diff --git a/TipsAndTricks/TernaryOperator.Tip.ps1 b/TipsAndTricks/TernaryOperator.Tip.ps1 new file mode 100644 index 0000000..90f7310 --- /dev/null +++ b/TipsAndTricks/TernaryOperator.Tip.ps1 @@ -0,0 +1,7 @@ +# In PowerShell 7, there's a ternary operator. + +# Let's use it to toss a coin + +$CoinToss = (Get-Random) % 2 ? 'Heads' : 'Tails' + +$CoinToss \ No newline at end of file diff --git a/TipsAndTricks/TheParameterSetThatWasNotThere.Trick.ps1 b/TipsAndTricks/TheParameterSetThatWasNotThere.Trick.ps1 new file mode 100644 index 0000000..75aac4f --- /dev/null +++ b/TipsAndTricks/TheParameterSetThatWasNotThere.Trick.ps1 @@ -0,0 +1,15 @@ +# Parameter Sets are more powerful than you think: + +# You can use "The Parameter Set That Wasn't There" to allow a command to be called with no parameters + +# (and to know when that happens) + +& { + [CmdletBinding(DefaultParameterSetName="NoParameters")] + param( + [Parameter(Mandatory,ParameterSetName="SomeParameters")] + $SomeParameter + ) + + $PSCmdlet.ParameterSetName +} diff --git a/TipsAndTricks/TrinityOfDiscoverability.Tip.ps1 b/TipsAndTricks/TrinityOfDiscoverability.Tip.ps1 new file mode 100644 index 0000000..fe68594 --- /dev/null +++ b/TipsAndTricks/TrinityOfDiscoverability.Tip.ps1 @@ -0,0 +1,16 @@ +# Whenever you need to find your way around PowerShell, remember the trinity of discoverability + +# Get-Command helps you find commands + +Get-Command -Module Microsoft.PowerShell.* + +# Get-Help gives you help about commands + +Get-Help Get-Help + +# Get-Member tells you what an object can do: + +Get-Command | Get-Member + + + diff --git a/TipsAndTricks/YouCanGetHelpOnAScript.Tip.ps1 b/TipsAndTricks/YouCanGetHelpOnAScript.Tip.ps1 new file mode 100644 index 0000000..4f688d9 --- /dev/null +++ b/TipsAndTricks/YouCanGetHelpOnAScript.Tip.ps1 @@ -0,0 +1,13 @@ +# Get-Help isn't just got commands. + +# You can Get-Help on any Script, too. + +$scriptPath = + Get-Module Posh | + Split-Path | + Join-Path -ChildPath "Types" | + Join-Path -ChildPath "PSModuleInfo" | + Join-Path -ChildPath "get_Tip.ps1" + +Get-Help $scriptPath + \ No newline at end of file diff --git a/Types/PSModuleInfo/Alias.psd1 b/Types/PSModuleInfo/Alias.psd1 index a4e4aeb..ca0fd0f 100644 --- a/Types/PSModuleInfo/Alias.psd1 +++ b/Types/PSModuleInfo/Alias.psd1 @@ -4,4 +4,11 @@ Videos = 'Video' Demos = 'Demo' Tests = 'Test' + Tips = 'Tip' + Trick = 'Tip' + Tricks = 'Tip' + Links = 'Link' + Resource = 'Link' + Resources = 'Link' + Presets = 'Preset' } \ No newline at end of file diff --git a/Types/PSModuleInfo/get_Link.ps1 b/Types/PSModuleInfo/get_Link.ps1 new file mode 100644 index 0000000..13c06d9 --- /dev/null +++ b/Types/PSModuleInfo/get_Link.ps1 @@ -0,0 +1,19 @@ +<# +.SYNOPSIS + Gets Module Links +.DESCRIPTION + Lists hyperlinks from this module. +.EXAMPLE + $posh.Links +#> +$this.LinkList(@( + $this.PrivateData.Link + $this.PrivateData.Links + $this.PrivateData.Resource + $this.PrivateData.Resources + $this.PrivateData.PSData.Link + $this.PrivateData.PSData.Links + $this.PrivateData.PSData.Resource + $this.PrivateData.PSData.Resources +), "Posh.Module.Link") + diff --git a/Types/PSModuleInfo/get_Preset.ps1 b/Types/PSModuleInfo/get_Preset.ps1 new file mode 100644 index 0000000..9629c9a --- /dev/null +++ b/Types/PSModuleInfo/get_Preset.ps1 @@ -0,0 +1,27 @@ +<# +.SYNOPSIS + Get's a module's presets +.DESCRIPTION + Gets presets from a module. + + Any module can contain `*.preset(s)` files, of the extensions: + + * .psd1 + * .json + * .clixml + + The collection of presets can be accessed in a Module's .Preset(s) properties +#> +if (-not $this.'.Preset') { + $PresetCollection = + [PSCustomObject][Ordered]@{ + PSTypeName = 'Posh.ExtensionCollection' + Module = $posh + Path = @(Get-Module | Split-Path) -as [string[]] + CommandType = 'Posh.Preset.Command' + } + $PresetCollection.pstypenames.insert(0,'Posh.Preset.Collection') + $this | + Add-Member NoteProperty '.Preset' $PresetCollection -Force +} +$this.'.Preset' \ No newline at end of file diff --git a/Types/PSModuleInfo/get_Tip.ps1 b/Types/PSModuleInfo/get_Tip.ps1 new file mode 100644 index 0000000..d964bb0 --- /dev/null +++ b/Types/PSModuleInfo/get_Tip.ps1 @@ -0,0 +1,31 @@ +<# +.SYNOPSIS + Get's a module's tips +.DESCRIPTION + Gets tips and tricks from a module. + + Any module can contain `*.tip(s)` or `*.trick(s)` files, of the extensions: + + * .md + * .txt + * .ps1 + * .psd1 + * .json + * .clixml + + The collection of tips can be accessed in a Module's .Tip(s) or .Trick(s) properties + +#> +if (-not $this.'.Tip') { + $tipCollection = + [PSCustomObject][Ordered]@{ + PSTypeName = 'Posh.ExtensionCollection' + Module = $posh + Path = $this.Path | Split-Path + CommandType = 'Posh.Tip.Command' + } + + $tipCollection.pstypenames.insert(0,'Posh.Tip.Collection') + $this | Add-Member NoteProperty '.Tip' $tipCollection -Force +} +$this.'.Tip' \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/Posh.Preset.Collection/README.md b/Types/Posh.ExtensionCollection/Posh.Preset.Collection/README.md new file mode 100644 index 0000000..c680cf3 --- /dev/null +++ b/Types/Posh.ExtensionCollection/Posh.Preset.Collection/README.md @@ -0,0 +1,9 @@ +## Posh Presets + +Posh Presets provide a way to store and apply presets for a variable. + +They are simply data files, where each key or property repesents a expression and it's value represents what it will be set to. + +Preset files can be .psd1, .json, or .clixml. + +To see what presets can do, use $Posh.Presets | Get-Member \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/Refresh.ps1 b/Types/Posh.ExtensionCollection/Refresh.ps1 new file mode 100644 index 0000000..4aec81d --- /dev/null +++ b/Types/Posh.ExtensionCollection/Refresh.ps1 @@ -0,0 +1 @@ +$this | Add-Member NoteProperty '.Cache' @() -Force \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/get_All.ps1 b/Types/Posh.ExtensionCollection/get_All.ps1 new file mode 100644 index 0000000..2abeea7 --- /dev/null +++ b/Types/Posh.ExtensionCollection/get_All.ps1 @@ -0,0 +1,33 @@ +<# +.SYNOPSIS + Gets all items in an extension collection. +.DESCRIPTION + Gets all items in a collection of extended commands. +#> +if (-not $this.'.Cache') { + if (-not $this.'.Module') { return @() } + + $findExtensionArgs = @($this.'.Module') + @($this.'.Path') + $allExtensionsFound = + @(:nextExtension + foreach ($foundExtension in + $posh.Commands.FindExtensions.Invoke($findExtensionArgs) + ) + { + if ($this.'.CommandType') { + foreach ($typename in $this.'.CommandType') { + if ($foundExtension.pstypenames -contains $typename) { + $foundExtension + continue nextExtension + } + } + } else { + $foundExtension + } + } + ) + $this | + Add-Member NoteProperty '.Cache' $allExtensionsFound -Force +} + +return $this.'.Cache' \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/get_CommandType.ps1 b/Types/Posh.ExtensionCollection/get_CommandType.ps1 new file mode 100644 index 0000000..17bf9b6 --- /dev/null +++ b/Types/Posh.ExtensionCollection/get_CommandType.ps1 @@ -0,0 +1,9 @@ +<# +.SYNOPSIS + Gets an extension collection's CommandType +.DESCRIPTION + Gets the extended CommandTypes(s) that are stored in an extension collection. + + CommandTypes can be defined in a module's manifest. +#> +return $this.'.CommandType' \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/get_Count.ps1 b/Types/Posh.ExtensionCollection/get_Count.ps1 new file mode 100644 index 0000000..772d8b2 --- /dev/null +++ b/Types/Posh.ExtensionCollection/get_Count.ps1 @@ -0,0 +1,7 @@ +<# +.SYNOPSIS + Gets the extension count. +.DESCRIPTION + Gets the count of all extensions in a collection. +#> +$this.All.Length \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/get_Module.ps1 b/Types/Posh.ExtensionCollection/get_Module.ps1 new file mode 100644 index 0000000..54f570b --- /dev/null +++ b/Types/Posh.ExtensionCollection/get_Module.ps1 @@ -0,0 +1,7 @@ +<# +.SYNOPSIS + Gets an extension collection's module +.DESCRIPTION + Gets the module that defines extended types in an extension collection. +#> +return $this.'.Module' \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/get_Path.ps1 b/Types/Posh.ExtensionCollection/get_Path.ps1 new file mode 100644 index 0000000..af92e07 --- /dev/null +++ b/Types/Posh.ExtensionCollection/get_Path.ps1 @@ -0,0 +1,7 @@ +<# +.SYNOPSIS + Gets an extension collection's Path +.DESCRIPTION + Gets the Path(s) that store extensions in an extension collection. +#> +return $this.'.Path' \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/get_Random.ps1 b/Types/Posh.ExtensionCollection/get_Random.ps1 new file mode 100644 index 0000000..20eec3c --- /dev/null +++ b/Types/Posh.ExtensionCollection/get_Random.ps1 @@ -0,0 +1,7 @@ +<# +.SYNOPSIS + Gets a random extended command +.DESCRIPTION + Gets a random extended command from an ExtensionCollection. +#> +$this.All | Get-Random \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/set_CommandType.ps1 b/Types/Posh.ExtensionCollection/set_CommandType.ps1 new file mode 100644 index 0000000..70c4f82 --- /dev/null +++ b/Types/Posh.ExtensionCollection/set_CommandType.ps1 @@ -0,0 +1,13 @@ +<# +.SYNOPSIS + Sets an extension collection's command type +.DESCRIPTION + Sets the extended command types in an extension collection. +#> +param( +# The path. If this is empty all extended commands will be present in the collection +[string[]] +$CommandType +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.CommandType' -Value $CommandType -Force \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/set_Module.ps1 b/Types/Posh.ExtensionCollection/set_Module.ps1 new file mode 100644 index 0000000..6cf71ab --- /dev/null +++ b/Types/Posh.ExtensionCollection/set_Module.ps1 @@ -0,0 +1,13 @@ +<# +.SYNOPSIS + Sets an extension collection's module +.DESCRIPTION + Sets the module that defines extended command types in an extension collection. +#> +param( +# The module. +[Management.Automation.PSModuleInfo] +$Module +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.Module' -Value $module -Force \ No newline at end of file diff --git a/Types/Posh.ExtensionCollection/set_Path.ps1 b/Types/Posh.ExtensionCollection/set_Path.ps1 new file mode 100644 index 0000000..d0c85e7 --- /dev/null +++ b/Types/Posh.ExtensionCollection/set_Path.ps1 @@ -0,0 +1,13 @@ +<# +.SYNOPSIS + Sets an extension collection's path +.DESCRIPTION + Sets the path that defines extended command types in an extension collection. +#> +param( +# The path. If this is empty, only extensions that are functions or aliases will be found. +[string[]] +$Path +) + +Add-Member -InputObject $this -MemberType NoteProperty -Name '.Path' -Value $Path -Force \ No newline at end of file diff --git a/Types/Posh.Host/get_Title.ps1 b/Types/Posh.Host/get_Title.ps1 new file mode 100644 index 0000000..560e47d --- /dev/null +++ b/Types/Posh.Host/get_Title.ps1 @@ -0,0 +1,9 @@ +<# +.SYNOPSIS + Gets the host's title +.DESCRIPTION + Gets the host's window title. +.EXAMPLE + $Posh.Title +#> +$this.UI.RawUI.WindowTitle diff --git a/Types/Posh.Host/set_Title.ps1 b/Types/Posh.Host/set_Title.ps1 new file mode 100644 index 0000000..208356b --- /dev/null +++ b/Types/Posh.Host/set_Title.ps1 @@ -0,0 +1,15 @@ +<# +.SYNOPSIS + Sets the host's title +.DESCRIPTION + Sets the host's window title. + + Unfortunately, this will be ignored if running in Visual Studio Code. +.EXAMPLE + $Posh.Title = "Sup?" +#> +param( +[string] +$Title +) +$this.UI.RawUI.WindowTitle = $title diff --git a/Types/Posh.Preset.Command/Alias.psd1 b/Types/Posh.Preset.Command/Alias.psd1 new file mode 100644 index 0000000..f89b7d1 --- /dev/null +++ b/Types/Posh.Preset.Command/Alias.psd1 @@ -0,0 +1,3 @@ +@{ + Apply = 'Use' +} \ No newline at end of file diff --git a/Types/Posh.Preset.Command/Use.ps1 b/Types/Posh.Preset.Command/Use.ps1 new file mode 100644 index 0000000..182ebd9 --- /dev/null +++ b/Types/Posh.Preset.Command/Use.ps1 @@ -0,0 +1,62 @@ +<# +.SYNOPSIS + Uses a preset +.DESCRIPTION + Uses or applies a Posh preset. + + Posh presets will take the data in a *.preset.* file and apply it to a variable. +#> + +$importedData = + switch -regex ($this.Source) { + '\.psd1$' { + $importedAsLocalizedData = Import-LocalizedData -BaseDirectory ($this.Source | Split-Path) -FileName ($this.Source | Split-Path -Leaf) + if ($importedAsLocalizedData) { + $replacedContent = [IO.File]::ReadAllText($this.Source) -replace '\@\{', '[Ordered]@{' + & ([ScriptBlock]::Create($replacedContent)) + } + } + '\.json$' { + Get-Content $this.Source -Raw | ConvertFrom-Json + } + '.\clixml' { + Import-Clixml $this.Source + } + } + + +if ($importedData -is [Collections.IDictionary]) { + $importedData = [PSCustomObject]$importedData +} + +foreach ($importedProperty in $importedData.psobject.properties) { + if ($importedProperty.Name -notmatch '^\$') { continue } + + $importedNameScript = [ScriptBlock]::Create($importedProperty.Name) + $valueToImport = $importedProperty.Value + if (-not $importedNameScript) { continue } + + $statements = $importedNameScript.Ast.EndBlock.Statements + + $currentValue = try { . $importedNameScript } catch {$null} + + # If we are importing a dictionary value, try to set each value within the dictionary + if ($valueToImport -is [Collections.IDictionary]) { + if ($currentValue -is [Collections.IDictionary]) { + foreach ($ToImport in $valueToImport.GetEnumerator()) { + $currentValue[$ToImport.Key] = $ToImport.Value + } + } + } elseif ($valueToImport.GetType -and ( + $valueToImport.GetType().IsPrimitive -or + $valueToImport.GetType() -in [string], [DateTime], [timespan] + )) { + $global:ExecutionContext.SessionState.InvokeCommand.InvokeScript( + "$importedNameScript = $valueToImport" + ) + } elseif ($currentValue -is [Collections.IDictionary]) { + foreach ($ToImport in $valueToImport.psobject.properties) { + $currentValue[$ToImport.Name] = $ToImport.Value + } + } +} \ No newline at end of file diff --git a/Types/Posh.Stackable/Prepend.ps1 b/Types/Posh.Stackable/Prepend.ps1 index 864972a..dced1c2 100644 --- a/Types/Posh.Stackable/Prepend.ps1 +++ b/Types/Posh.Stackable/Prepend.ps1 @@ -13,6 +13,6 @@ $Value -$toPrepend = $this.Stringify($prompt) +$toPrepend = $this.Stringify($Value) $currentFunction = $posh.ExecutionContext.SessionState.InvokeCommand.InvokeScript("`$function:$($this.FunctionName)") $this.Current = "@(. { $toPrepend} ; . { $currentFunction }) -join ''" \ No newline at end of file diff --git a/Types/Posh.Stackable/Replace.ps1 b/Types/Posh.Stackable/Replace.ps1 index fe0cd15..496b7f4 100644 --- a/Types/Posh.Stackable/Replace.ps1 +++ b/Types/Posh.Stackable/Replace.ps1 @@ -40,7 +40,7 @@ foreach ($arg in $args) { } } $newFunc = "@( - `$existingOutput =. { $function:prompt }; + `$existingOutput =. { $currentFunction }; `$replacePattern = $replaceRegex `$replaceWith = $toReplace `$replacePattern.Replace(`$existingOutput, `$replaceWith) diff --git a/Types/Posh.Tip.Command/get_Content.ps1 b/Types/Posh.Tip.Command/get_Content.ps1 new file mode 100644 index 0000000..812c484 --- /dev/null +++ b/Types/Posh.Tip.Command/get_Content.ps1 @@ -0,0 +1,19 @@ +switch -regex ($this.Source) { + '\.psd1$' { + (Import-LocalizedData -BaseDirectory ($this.Source | Split-Path) -FileName ($this.Source | Split-Path -Leaf)).Content + } + '\.json$' { + (Get-Content $this.Source -Raw | ConvertFrom-Json).Content + } + '\.md$' { + Show-Markdown -LiteralPath $this.Source + } + '\.ps1$' { + $showDemoCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand('Show-Demo', 'Function') + if ($showDemoCommand) { + $this.ScriptBlock + } else { + Get-Content $this.Source -Raw + } + } +} \ No newline at end of file diff --git a/Types/Posh/get_Presets.ps1 b/Types/Posh/get_Presets.ps1 deleted file mode 100644 index 1b66b07..0000000 --- a/Types/Posh/get_Presets.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -# Get-Module -$moduleRoots = Get-Module | Split-Path | Select-Object -Unique - - -foreach ($extensionFile in $posh.Commands.FindExtensions.Invoke(@( - $posh - $moduleRoots - )) -) { - if ($extensionFile.pstypenames -contains 'Posh.Preset.Command') { - $extensionFile - } -} \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 619712f..1dbd3e6 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,54 @@ +## Posh 0.1.3: Posh Tips and Tricks + +* New Formatting: + * Adding Select-XML Formatter (#107) + * Posh.Preset.Collection (#153) + * Posh.Tip.Command (#166) +* Updated Formatting: + * Making DirectoryIcon customizable / changing default to triangle (#169) + * Integrating Tips/Links into Posh Formatting (#165) + * Improving Formatting of Select-String (#109) (thanks @mdgrs-mei ! ) +* Added Tips and Tricks to Modules (#118) and added the first round of tips/tricks: + * NegativeIndexingFibonacci Trick (#168) + * GenericTypes Tip (#167) + * Ordered Hashtables Tip (#156) + * Hashtables Tip (#155) + * AssigningLoopOutput Tip (#145) + * RangeOperator Tip (#151) + * NegativeIndex Tip (#150) + * TernaryOperator Tip (#148) + * Creating PsuedoObjects Trick (#144) + * AssigningIfStatements Tip (#144) + * Tip - Trinity of Discoverability (#142) + * Tip - You Can Get Help On a Script (#147) + * Tip - Everything Is An Object (#140) + * Trick - The Parameter Set That Was Not There (#141) + * Multiple Assignment Tip (#143) + * LoopLabels Tip (#146) + * see issues #166 +* New Extended Types: + * Posh.Preset.Collection (#153) + * Posh.Preset.Command (#154) + * Posh.ExtensionCollection + * .Count (#162) + * .Refresh() (#123) + * .Random (#124) + * .All (#128) + * get/set .CommandType (#127) + * get/set .Path (#126) + * get/set Module (#125) +* Updated Extended Types + * PSModuleInfo.Link (#64/#157/#158/#159/#160) + * PSModuleInfo.Preset (#64/#153) + * PSModuleInfo.Tip(s)/Trick(s) (#119, #120) + * $Posh.Host.get/set_Title (#130) + * Fixing stackable functions (#110, thanks @mdgrs-mei !) +* Updating Posh.Preset.Command.Use help (#154) +* Adding FileIcons Preset (#163) +* Making TabExpansion Stackable (#116) + +--- + ## Posh 0.1.2: * New Demos diff --git a/docs/Posh.ExtensionCollection.get_All.md b/docs/Posh.ExtensionCollection.get_All.md new file mode 100644 index 0000000..a6e990b --- /dev/null +++ b/docs/Posh.ExtensionCollection.get_All.md @@ -0,0 +1,21 @@ +Posh.ExtensionCollection.get_All() +---------------------------------- + + + + +### Synopsis +Gets all items in an extension collection. + + + +--- + + +### Description + +Gets all items in a collection of extended commands. + + + +--- diff --git a/docs/Posh.ExtensionCollection.get_CommandType.md b/docs/Posh.ExtensionCollection.get_CommandType.md new file mode 100644 index 0000000..b6e3818 --- /dev/null +++ b/docs/Posh.ExtensionCollection.get_CommandType.md @@ -0,0 +1,23 @@ +Posh.ExtensionCollection.get_CommandType() +------------------------------------------ + + + + +### Synopsis +Gets an extension collection's CommandType + + + +--- + + +### Description + +Gets the extended CommandTypes(s) that are stored in an extension collection. + +CommandTypes can be defined in a module's manifest. + + + +--- diff --git a/docs/Posh.ExtensionCollection.get_Count.md b/docs/Posh.ExtensionCollection.get_Count.md new file mode 100644 index 0000000..d0b24ac --- /dev/null +++ b/docs/Posh.ExtensionCollection.get_Count.md @@ -0,0 +1,21 @@ +Posh.ExtensionCollection.get_Count() +------------------------------------ + + + + +### Synopsis +Gets the extension count. + + + +--- + + +### Description + +Gets the count of all extensions in a collection. + + + +--- diff --git a/docs/Posh.ExtensionCollection.get_Module.md b/docs/Posh.ExtensionCollection.get_Module.md new file mode 100644 index 0000000..444a462 --- /dev/null +++ b/docs/Posh.ExtensionCollection.get_Module.md @@ -0,0 +1,21 @@ +Posh.ExtensionCollection.get_Module() +------------------------------------- + + + + +### Synopsis +Gets an extension collection's module + + + +--- + + +### Description + +Gets the module that defines extended types in an extension collection. + + + +--- diff --git a/docs/Posh.ExtensionCollection.get_Path.md b/docs/Posh.ExtensionCollection.get_Path.md new file mode 100644 index 0000000..638b842 --- /dev/null +++ b/docs/Posh.ExtensionCollection.get_Path.md @@ -0,0 +1,21 @@ +Posh.ExtensionCollection.get_Path() +----------------------------------- + + + + +### Synopsis +Gets an extension collection's Path + + + +--- + + +### Description + +Gets the Path(s) that store extensions in an extension collection. + + + +--- diff --git a/docs/Posh.ExtensionCollection.get_Random.md b/docs/Posh.ExtensionCollection.get_Random.md new file mode 100644 index 0000000..e31f0b5 --- /dev/null +++ b/docs/Posh.ExtensionCollection.get_Random.md @@ -0,0 +1,21 @@ +Posh.ExtensionCollection.get_Random() +------------------------------------- + + + + +### Synopsis +Gets a random extended command + + + +--- + + +### Description + +Gets a random extended command from an ExtensionCollection. + + + +--- diff --git a/docs/Posh.ExtensionCollection.set_CommandType.md b/docs/Posh.ExtensionCollection.set_CommandType.md new file mode 100644 index 0000000..d90f9a4 --- /dev/null +++ b/docs/Posh.ExtensionCollection.set_CommandType.md @@ -0,0 +1,42 @@ +Posh.ExtensionCollection.set_CommandType() +------------------------------------------ + + + + +### Synopsis +Sets an extension collection's command type + + + +--- + + +### Description + +Sets the extended command types in an extension collection. + + + +--- + + +### Parameters +#### **CommandType** + +The path. If this is empty all extended commands will be present in the collection + + + + + + +|Type |Required|Position|PipelineInput| +|------------|--------|--------|-------------| +|`[String[]]`|false |1 |false | + + + + + +--- diff --git a/docs/Posh.ExtensionCollection.set_Module.md b/docs/Posh.ExtensionCollection.set_Module.md new file mode 100644 index 0000000..32efe2f --- /dev/null +++ b/docs/Posh.ExtensionCollection.set_Module.md @@ -0,0 +1,42 @@ +Posh.ExtensionCollection.set_Module() +------------------------------------- + + + + +### Synopsis +Sets an extension collection's module + + + +--- + + +### Description + +Sets the module that defines extended command types in an extension collection. + + + +--- + + +### Parameters +#### **Module** + +The module. + + + + + + +|Type |Required|Position|PipelineInput| +|----------------|--------|--------|-------------| +|`[PSModuleInfo]`|false |1 |false | + + + + + +--- diff --git a/docs/Posh.ExtensionCollection.set_Path.md b/docs/Posh.ExtensionCollection.set_Path.md new file mode 100644 index 0000000..b504e1b --- /dev/null +++ b/docs/Posh.ExtensionCollection.set_Path.md @@ -0,0 +1,42 @@ +Posh.ExtensionCollection.set_Path() +----------------------------------- + + + + +### Synopsis +Sets an extension collection's path + + + +--- + + +### Description + +Sets the path that defines extended command types in an extension collection. + + + +--- + + +### Parameters +#### **Path** + +The path. If this is empty, only extensions that are functions or aliases will be found. + + + + + + +|Type |Required|Position|PipelineInput| +|------------|--------|--------|-------------| +|`[String[]]`|false |1 |false | + + + + + +--- diff --git a/docs/Posh.Host.get_Title.md b/docs/Posh.Host.get_Title.md new file mode 100644 index 0000000..ee3f26f --- /dev/null +++ b/docs/Posh.Host.get_Title.md @@ -0,0 +1,32 @@ +Posh.Host.get_Title() +--------------------- + + + + +### Synopsis +Gets the host's title + + + +--- + + +### Description + +Gets the host's window title. + + + +--- + + +### Examples +#### EXAMPLE 1 +```PowerShell +$Posh.Title +``` + + + +--- diff --git a/docs/Posh.Host.set_Title.md b/docs/Posh.Host.set_Title.md new file mode 100644 index 0000000..2b8eac3 --- /dev/null +++ b/docs/Posh.Host.set_Title.md @@ -0,0 +1,51 @@ +Posh.Host.set_Title() +--------------------- + + + + +### Synopsis +Sets the host's title + + + +--- + + +### Description + +Sets the host's window title. + +Unfortunately, this will be ignored if running in Visual Studio Code. + + + +--- + + +### Examples +#### EXAMPLE 1 +```PowerShell +$Posh.Title = "Sup?" +``` + + + +--- + + +### Parameters +#### **Title** + + + + +|Type |Required|Position|PipelineInput| +|----------|--------|--------|-------------| +|`[String]`|false |1 |false | + + + + + +--- diff --git a/docs/Posh.Preset.Collection.get_All.md b/docs/Posh.Preset.Collection.get_All.md new file mode 100644 index 0000000..582140e --- /dev/null +++ b/docs/Posh.Preset.Collection.get_All.md @@ -0,0 +1,21 @@ +Posh.Preset.Collection.get_All() +-------------------------------- + + + + +### Synopsis +Gets all items in an extension collection. + + + +--- + + +### Description + +Gets all items in a collection of extended commands. + + + +--- diff --git a/docs/Posh.Preset.Collection.get_CommandType.md b/docs/Posh.Preset.Collection.get_CommandType.md new file mode 100644 index 0000000..bcbd851 --- /dev/null +++ b/docs/Posh.Preset.Collection.get_CommandType.md @@ -0,0 +1,23 @@ +Posh.Preset.Collection.get_CommandType() +---------------------------------------- + + + + +### Synopsis +Gets an extension collection's CommandType + + + +--- + + +### Description + +Gets the extended CommandTypes(s) that are stored in an extension collection. + +CommandTypes can be defined in a module's manifest. + + + +--- diff --git a/docs/Posh.Preset.Collection.get_Count.md b/docs/Posh.Preset.Collection.get_Count.md new file mode 100644 index 0000000..eb9a677 --- /dev/null +++ b/docs/Posh.Preset.Collection.get_Count.md @@ -0,0 +1,21 @@ +Posh.Preset.Collection.get_Count() +---------------------------------- + + + + +### Synopsis +Gets the extension count. + + + +--- + + +### Description + +Gets the count of all extensions in a collection. + + + +--- diff --git a/docs/Posh.Preset.Collection.get_Module.md b/docs/Posh.Preset.Collection.get_Module.md new file mode 100644 index 0000000..62d12a3 --- /dev/null +++ b/docs/Posh.Preset.Collection.get_Module.md @@ -0,0 +1,21 @@ +Posh.Preset.Collection.get_Module() +----------------------------------- + + + + +### Synopsis +Gets an extension collection's module + + + +--- + + +### Description + +Gets the module that defines extended types in an extension collection. + + + +--- diff --git a/docs/Posh.Preset.Collection.get_Path.md b/docs/Posh.Preset.Collection.get_Path.md new file mode 100644 index 0000000..7a76d0b --- /dev/null +++ b/docs/Posh.Preset.Collection.get_Path.md @@ -0,0 +1,21 @@ +Posh.Preset.Collection.get_Path() +--------------------------------- + + + + +### Synopsis +Gets an extension collection's Path + + + +--- + + +### Description + +Gets the Path(s) that store extensions in an extension collection. + + + +--- diff --git a/docs/Posh.Preset.Collection.get_Random.md b/docs/Posh.Preset.Collection.get_Random.md new file mode 100644 index 0000000..9bcaebb --- /dev/null +++ b/docs/Posh.Preset.Collection.get_Random.md @@ -0,0 +1,21 @@ +Posh.Preset.Collection.get_Random() +----------------------------------- + + + + +### Synopsis +Gets a random extended command + + + +--- + + +### Description + +Gets a random extended command from an ExtensionCollection. + + + +--- diff --git a/docs/Posh.Preset.Collection.set_CommandType.md b/docs/Posh.Preset.Collection.set_CommandType.md new file mode 100644 index 0000000..4ae034b --- /dev/null +++ b/docs/Posh.Preset.Collection.set_CommandType.md @@ -0,0 +1,42 @@ +Posh.Preset.Collection.set_CommandType() +---------------------------------------- + + + + +### Synopsis +Sets an extension collection's command type + + + +--- + + +### Description + +Sets the extended command types in an extension collection. + + + +--- + + +### Parameters +#### **CommandType** + +The path. If this is empty all extended commands will be present in the collection + + + + + + +|Type |Required|Position|PipelineInput| +|------------|--------|--------|-------------| +|`[String[]]`|false |1 |false | + + + + + +--- diff --git a/docs/Posh.Preset.Collection.set_Module.md b/docs/Posh.Preset.Collection.set_Module.md new file mode 100644 index 0000000..128bc10 --- /dev/null +++ b/docs/Posh.Preset.Collection.set_Module.md @@ -0,0 +1,42 @@ +Posh.Preset.Collection.set_Module() +----------------------------------- + + + + +### Synopsis +Sets an extension collection's module + + + +--- + + +### Description + +Sets the module that defines extended command types in an extension collection. + + + +--- + + +### Parameters +#### **Module** + +The module. + + + + + + +|Type |Required|Position|PipelineInput| +|----------------|--------|--------|-------------| +|`[PSModuleInfo]`|false |1 |false | + + + + + +--- diff --git a/docs/Posh.Preset.Collection.set_Path.md b/docs/Posh.Preset.Collection.set_Path.md new file mode 100644 index 0000000..5991174 --- /dev/null +++ b/docs/Posh.Preset.Collection.set_Path.md @@ -0,0 +1,42 @@ +Posh.Preset.Collection.set_Path() +--------------------------------- + + + + +### Synopsis +Sets an extension collection's path + + + +--- + + +### Description + +Sets the path that defines extended command types in an extension collection. + + + +--- + + +### Parameters +#### **Path** + +The path. If this is empty, only extensions that are functions or aliases will be found. + + + + + + +|Type |Required|Position|PipelineInput| +|------------|--------|--------|-------------| +|`[String[]]`|false |1 |false | + + + + + +--- diff --git a/docs/Posh.Preset.Command.Use.md b/docs/Posh.Preset.Command.Use.md new file mode 100644 index 0000000..68ccec3 --- /dev/null +++ b/docs/Posh.Preset.Command.Use.md @@ -0,0 +1,23 @@ +Posh.Preset.Command.Use() +------------------------- + + + + +### Synopsis +Uses a preset + + + +--- + + +### Description + +Uses or applies a Posh preset. + +Posh presets will take the data in a *.preset.* file and apply it to a variable. + + + +--- diff --git a/docs/System.Management.Automation.PSModuleInfo.get_Link.md b/docs/System.Management.Automation.PSModuleInfo.get_Link.md new file mode 100644 index 0000000..8ce7b10 --- /dev/null +++ b/docs/System.Management.Automation.PSModuleInfo.get_Link.md @@ -0,0 +1,32 @@ +System.Management.Automation.PSModuleInfo.get_Link() +---------------------------------------------------- + + + + +### Synopsis +Gets Module Links + + + +--- + + +### Description + +Lists hyperlinks from this module. + + + +--- + + +### Examples +#### EXAMPLE 1 +```PowerShell +$posh.Links +``` + + + +--- diff --git a/docs/System.Management.Automation.PSModuleInfo.get_Preset.md b/docs/System.Management.Automation.PSModuleInfo.get_Preset.md new file mode 100644 index 0000000..aef4199 --- /dev/null +++ b/docs/System.Management.Automation.PSModuleInfo.get_Preset.md @@ -0,0 +1,29 @@ +System.Management.Automation.PSModuleInfo.get_Preset() +------------------------------------------------------ + + + + +### Synopsis +Get's a module's presets + + + +--- + + +### Description + +Gets presets from a module. + +Any module can contain `*.preset(s)` files, of the extensions: + +* .psd1 +* .json +* .clixml + +The collection of presets can be accessed in a Module's .Preset(s) properties + + + +--- diff --git a/docs/System.Management.Automation.PSModuleInfo.get_Tip.md b/docs/System.Management.Automation.PSModuleInfo.get_Tip.md new file mode 100644 index 0000000..a7938cf --- /dev/null +++ b/docs/System.Management.Automation.PSModuleInfo.get_Tip.md @@ -0,0 +1,32 @@ +System.Management.Automation.PSModuleInfo.get_Tip() +--------------------------------------------------- + + + + +### Synopsis +Get's a module's tips + + + +--- + + +### Description + +Gets tips and tricks from a module. + +Any module can contain `*.tip(s)` or `*.trick(s)` files, of the extensions: + +* .md +* .txt +* .ps1 +* .psd1 +* .json +* .clixml + +The collection of tips can be accessed in a Module's .Tip(s) or .Trick(s) properties + + + +---