Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Set-TerminalIconPathResolver #124

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Set-TerminalIconsColorTheme | **DEPRECATED** Set the Terminal-Icons color theme.
Set-TerminalIconsIconTheme | **DEPRECATED** Set the Terminal-Icons icon theme.
Set-TerminalIconsTheme | Set the Terminal-Icons icon and/or color theme.
Show-TerminalIconsTheme | List example directories and files to show the currently applied color and icon themes.
Set-TerminalIconPathResolver| Set the path resolver script block to handle target of symlinks before it be display.

## Screenshots

Expand Down
4 changes: 2 additions & 2 deletions Terminal-Icons/Private/Resolve-Icon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Resolve-Icon {
} else {
$colorSet = $script:colorReset
}
$displayInfo['Target'] = ' ' + $glyphs['nf-md-arrow_right_thick'] + ' ' + $FileInfo.Target
$displayInfo['Target'] = ' ' + $glyphs['nf-md-arrow_right_thick'] + ' ' + (&$script:PathResolver $FileInfo.Target)
break
}
'SymbolicLink' {
Expand All @@ -55,7 +55,7 @@ function Resolve-Icon {
} else {
$colorSet = $script:colorReset
}
$displayInfo['Target'] = ' ' + $glyphs['nf-md-arrow_right_thick'] + ' ' + $FileInfo.Target
$displayInfo['Target'] = ' ' + $glyphs['nf-md-arrow_right_thick'] + ' ' + (&$script:PathResolver $FileInfo.Target)
break
} default {
if ($icons) {
Expand Down
19 changes: 19 additions & 0 deletions Terminal-Icons/Private/Set-PathResolver.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Set-PathResolver {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[AllowNull()]
[scriptblock]$Resolver
)

if(-not $PathResolver) {
$script:PathResolver = {
param($Path)
$Path
}
}
else{
$script:PathResolver = $Resolver
}
}
34 changes: 34 additions & 0 deletions Terminal-Icons/Public/Set-TerminalIconPathResolver.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function Set-TerminalIconPathResolver {
<#
.SYNOPSIS
Set the path resolver for processing symbol's target before displaying.
.DESCRIPTION
Set the path resolver for processing symbol's target before displaying.
.PARAMETER Resolver
The path resolver to set.
.EXAMPLE
PS> Set-TerminalIconPathResolver -Resolver { param($Path) $Path.Replace($HOME, '~') }

Set the path resolver to replace the home directory with '~'.
.INPUTS
ScriptBlock

You can pipe a scriptblock to this function.
.OUTPUTS
None.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '', Justification='Implemented in private function')]
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(
Mandatory,
ValueFromPipeline
)]
[AllowNull()]
[scriptblock]$Resolver
)

process {
Set-PathResolver -Resolver $Resolver
}
}
4 changes: 4 additions & 0 deletions Terminal-Icons/Terminal-Icons.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ $userThemeData = @{
Icon = @{}
}
}
$PathResolver = {
param($Path)
$Path
}

# Import builtin icon/color themes and convert colors to escape sequences
$colorSequences = @{}
Expand Down
107 changes: 107 additions & 0 deletions docs/en-US/Set-TerminalIconPathResolver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
external help file: Terminal-Icons-help.xml
Module Name: Terminal-Icons
online version:
schema: 2.0.0
---

# Set-TerminalIconPathResolver

## SYNOPSIS
Set the path resolver for processing symbol's target before displaying.

## SYNTAX

```
Set-TerminalIconPathResolver [-Resolver] <ScriptBlock> [-ProgressAction <ActionPreference>] [-WhatIf]
[-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Set the path resolver for processing symbol's target before displaying.

## EXAMPLES

### EXAMPLE 1
```
Set-TerminalIconPathResolver -Resolver { param($Path) $Path.Replace($HOME, '~') }
```

Set the path resolver to replace the home directory with '~'.

## PARAMETERS

### -Resolver
The path resolver to set.

```yaml
Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ProgressAction
{{ Fill ProgressAction Description }}

```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### ScriptBlock
### You can pipe a scriptblock to this function.
## OUTPUTS

### None.
## NOTES

## RELATED LINKS