Skip to content

Commit

Permalink
Merge pull request #170 from StartAutomating/Posh-Tips-And-Tricks
Browse files Browse the repository at this point in the history
Posh 0.1.3 - Posh Tips and Tricks
  • Loading branch information
StartAutomating committed Aug 12, 2023
2 parents 7b4266f + bbe6c00 commit 3762881
Show file tree
Hide file tree
Showing 84 changed files with 2,416 additions and 203 deletions.
51 changes: 51 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion Demos/Posh.demo.ps1
Expand Up @@ -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('
(?<NameOfCaputre>Pattern) # Comment
(?<NameOfCapture>Pattern) # Comment
','IgnoreCase,IgnorePatternWhitespace')


Expand Down
13 changes: 9 additions & 4 deletions Formatting/FileSystem/FileTableView.format.ps1
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions 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 ''
}
5 changes: 5 additions & 0 deletions 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
17 changes: 1 addition & 16 deletions 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
17 changes: 1 addition & 16 deletions 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
9 changes: 9 additions & 0 deletions 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


}
13 changes: 0 additions & 13 deletions Formatting/Posh/Posh.Resources.format.ps1

This file was deleted.

3 changes: 3 additions & 0 deletions 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
}
14 changes: 14 additions & 0 deletions 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
}
}
}
15 changes: 15 additions & 0 deletions Formatting/Posh/Posh.format.ps1
Expand Up @@ -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
}
56 changes: 56 additions & 0 deletions 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
}
}
1 change: 1 addition & 0 deletions Formatting/XML/SelectXmlInfo.format.ps1
@@ -0,0 +1 @@
Write-FormatView -TypeName Microsoft.PowerShell.Commands.SelectXmlInfo -Property Node, Pattern -GroupByProperty "Path"

0 comments on commit 3762881

Please sign in to comment.