diff --git a/README.md b/README.md index 2447258..065986f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Terminal-Icons/Private/Resolve-Icon.ps1 b/Terminal-Icons/Private/Resolve-Icon.ps1 index 3c2c071..203d000 100644 --- a/Terminal-Icons/Private/Resolve-Icon.ps1 +++ b/Terminal-Icons/Private/Resolve-Icon.ps1 @@ -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' { @@ -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) { diff --git a/Terminal-Icons/Private/Set-PathResolver.ps1 b/Terminal-Icons/Private/Set-PathResolver.ps1 new file mode 100644 index 0000000..29abb81 --- /dev/null +++ b/Terminal-Icons/Private/Set-PathResolver.ps1 @@ -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 + } +} diff --git a/Terminal-Icons/Public/Set-TerminalIconPathResolver.ps1 b/Terminal-Icons/Public/Set-TerminalIconPathResolver.ps1 new file mode 100644 index 0000000..6767db6 --- /dev/null +++ b/Terminal-Icons/Public/Set-TerminalIconPathResolver.ps1 @@ -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 + } +} diff --git a/Terminal-Icons/Terminal-Icons.psm1 b/Terminal-Icons/Terminal-Icons.psm1 index d7ae702..1760c6b 100644 --- a/Terminal-Icons/Terminal-Icons.psm1 +++ b/Terminal-Icons/Terminal-Icons.psm1 @@ -24,6 +24,10 @@ $userThemeData = @{ Icon = @{} } } +$PathResolver = { + param($Path) + $Path +} # Import builtin icon/color themes and convert colors to escape sequences $colorSequences = @{} diff --git a/docs/en-US/Set-TerminalIconPathResolver.md b/docs/en-US/Set-TerminalIconPathResolver.md new file mode 100644 index 0000000..11e6d20 --- /dev/null +++ b/docs/en-US/Set-TerminalIconPathResolver.md @@ -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] [-ProgressAction ] [-WhatIf] + [-Confirm] [] +``` + +## 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