From eb3346153a42e53d5e50a6c06c45dbae3cbda9c0 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 20 Apr 2021 09:09:02 -0700 Subject: [PATCH] Add Set-TerminalIconsIcon, Get-TerminalIconsGlyphs Get-TerminalIconsGlyphs allows users to see the available glyph set for easier theme customization. It also allows argument completion over the set of available glyphs. Set-TerminalIconsIcon allows users to update an existing file name, file extension, or directory name to use a different icon. It also allows users to "swap" one glyph for another in the current theme, which allows streamlined theme customization. --- .../Public/Get-TerminalIconsGlyphs.ps1 | 27 +++ .../Public/Set-TerminalIconsIcon.ps1 | 134 +++++++++++ Terminal-Icons/Terminal-Icons.psd1 | 4 +- docs/en-US/Get-TerminalIconsGlyphs.md | 50 ++++ docs/en-US/Set-TerminalIconsIcon.md | 218 ++++++++++++++++++ 5 files changed, 431 insertions(+), 2 deletions(-) create mode 100644 Terminal-Icons/Public/Get-TerminalIconsGlyphs.ps1 create mode 100644 Terminal-Icons/Public/Set-TerminalIconsIcon.ps1 create mode 100644 docs/en-US/Get-TerminalIconsGlyphs.md create mode 100644 docs/en-US/Set-TerminalIconsIcon.md diff --git a/Terminal-Icons/Public/Get-TerminalIconsGlyphs.ps1 b/Terminal-Icons/Public/Get-TerminalIconsGlyphs.ps1 new file mode 100644 index 0000000..5ee7ff6 --- /dev/null +++ b/Terminal-Icons/Public/Get-TerminalIconsGlyphs.ps1 @@ -0,0 +1,27 @@ +function Get-TerminalIconsGlyphs { + <# + .SYNOPSIS + Gets the list of glyphs known to Terminal-Icons. + .DESCRIPTION + Gets a hashtable with the available glyph names and icons. Useful in creating a custom theme. + .EXAMPLE + PS> Get-TerminalIconsGlyphs + + Gets the table of glyph names and icons. + .INPUTS + None. + .OUTPUTS + None. + .LINK + Get-TerminalIconsIconTheme + .LINK + Set-TerminalIconsIcon + #> + [cmdletbinding()] + param() + + # This is also helpful for argument completers needing glyphs - + # ArgumentCompleterAttribute isn't able to access script variables but it + # CAN call commands. + $script:glyphs +} diff --git a/Terminal-Icons/Public/Set-TerminalIconsIcon.ps1 b/Terminal-Icons/Public/Set-TerminalIconsIcon.ps1 new file mode 100644 index 0000000..fe30896 --- /dev/null +++ b/Terminal-Icons/Public/Set-TerminalIconsIcon.ps1 @@ -0,0 +1,134 @@ +function Set-TerminalIconsIcon { + <# + .SYNOPSIS + Set a specific icon in the current Terminal-Icons icon theme or allows + swapping one glyph for another. + .DESCRIPTION + Set the Terminal-Icons icon for a specific file/directory or glyph to a + named glyph. + + Also allows all uses of a specific glyph to be replaced with a different + glyph. + .PARAMETER Directory + The well-known directory name to match for the icon. + .PARAMETER FileName + The well-known file name to match for the icon. + .PARAMETER FileExtension + The file extension to match for the icon. + .PARAMETER NewGlyph + The name of the new glyph to use when swapping. + .PARAMETER Glyph + The name of the glyph to use; or, when swapping glyphs, the name of the + glyph you want to change. + .PARAMETER Force + Bypass confirmation messages. + .EXAMPLE + PS> Set-TerminalIconsIcon -FileName "README.md" -Glyph "nf-fa-file_text" + + Set README.md files to display a text file icon. + .EXAMPLE + PS> Set-TerminalIconsIcon -FileExtension ".xml" -Glyph "nf-mdi-file_xml" + + Set XML files to display an XML file icon. + .EXAMPLE + PS> Set-TerminalIconsIcon -Directory ".github" -Glyph "nf-mdi-github_face" + + Set directories named ".github" to display an Octocat face icon. + .EXAMPLE + PS> Set-TerminalIconsIcon -Glyph "nf-mdi-xml" -NewGlyph "nf-mdi-file_xml" + + Changes all uses of the "nf-mdi-xml" double-wide glyph to be the "nf-mdi-file_xml" + single-width XML file glyph. + .INPUTS + None. + + The command does not accept pipeline input. + .OUTPUTS + None. + .LINK + Get-TerminalIconsIconTheme + .LINK + Get-TerminalIconsTheme + .LINK + Get-TerminalIconsGlyphs + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = "ArgumentCompleter parameters don't all get used.")] + [cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "FileExtension")] + param( + [Parameter(ParameterSetName = "Directory", Mandatory)] + [ArgumentCompleter( { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + (Get-TerminalIconsIconTheme).Values.Types.Directories.WellKnown.Keys | Where-Object { $_ -like "$wordToComplete*" } | Sort-Object + })] + [ValidateNotNullOrEmpty()] + [string]$Directory, + + [Parameter(ParameterSetName = "FileName", Mandatory)] + [ArgumentCompleter( { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + (Get-TerminalIconsIconTheme).Values.Types.Files.WellKnown.Keys | Where-Object { $_ -like "$wordToComplete*" } | Sort-Object + })] + [ValidateNotNullOrEmpty()] + [string]$FileName, + + [Parameter(ParameterSetName = "FileExtension", Mandatory)] + [ArgumentCompleter( { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + (Get-TerminalIconsIconTheme).Values.Types.Files.Keys | Where-Object { $_.StartsWith(".") -and $_ -like "$wordToComplete*" } | Sort-Object + })] + [ValidatePattern("^\.")] + [string]$FileExtension, + + [Parameter(ParameterSetName = "SwapGlyph", Mandatory)] + [ArgumentCompleter( { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + (Get-TerminalIconsGlyphs).Keys | Where-Object { $_ -like "*$wordToComplete*" } | Sort-Object + })] + [ValidateNotNullOrEmpty()] + [string]$NewGlyph, + + [Parameter(Mandatory)] + [ArgumentCompleter( { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + (Get-TerminalIconsGlyphs).Keys | Where-Object { $_ -like "*$wordToComplete*" } | Sort-Object + })] + [ValidateNotNullOrEmpty()] + [string]$Glyph, + + [switch]$Force + ) + + If($PSCmdlet.ParameterSetName -eq "Directory") { + If ($Force -or $PSCmdlet.ShouldProcess("$Directory = $Glyph", 'Set well-known directory icon')) { + (Get-TerminalIconsIconTheme).Values.Types.Directories.WellKnown[$Directory] = $Glyph + } + } + ElseIf ($PSCmdlet.ParameterSetName -eq "FileName") { + If ($Force -or $PSCmdlet.ShouldProcess("$FileName = $Glyph", 'Set well-known file name icon')) { + (Get-TerminalIconsIconTheme).Values.Types.Files.WellKnown[$FileName] = $Glyph + } + } + ElseIf ($PSCmdlet.ParameterSetName -eq "FileExtension") { + If ($Force -or $PSCmdlet.ShouldProcess("$FileExtension = $Glyph", 'Set file extension icon')) { + (Get-TerminalIconsIconTheme).Values.Types.Files[$FileExtension] = $Glyph + } + } + ElseIf ($PSCmdlet.ParameterSetName -eq "SwapGlyph") { + If ($Force -or $PSCmdlet.ShouldProcess("$Glyph to $NewGlyph", 'Swap glyph usage')) { + # Directories + $toModify = (Get-TerminalIconsTheme).Icon.Types.Directories.WellKnown + $keys = $toModify.Keys | Where-Object { $toModify[$_] -eq $Glyph } + $keys | ForEach-Object { $toModify[$_] = $NewGlyph } + + # Files + $toModify = (Get-TerminalIconsTheme).Icon.Types.Files.WellKnown + $keys = $toModify.Keys | Where-Object { $toModify[$_] -eq $Glyph } + $keys | ForEach-Object { $toModify[$_] = $NewGlyph } + + # Extensions + $toModify = (Get-TerminalIconsTheme).Icon.Types.Files + $keys = $toModify.Keys | Where-Object { $_.StartsWith(".") -and $toModify[$_] -eq $Glyph } + $keys | ForEach-Object { $toModify[$_] = $NewGlyph } + } + } +} diff --git a/Terminal-Icons/Terminal-Icons.psd1 b/Terminal-Icons/Terminal-Icons.psd1 index 200e8d4..986383c 100644 --- a/Terminal-Icons/Terminal-Icons.psd1 +++ b/Terminal-Icons/Terminal-Icons.psd1 @@ -15,9 +15,11 @@ 'Add-TerminalIconsIconTheme' 'Format-TerminalIcons' 'Get-TerminalIconsColorTheme' + 'Get-TerminalIconsGlyphs' 'Get-TerminalIconsIconTheme' 'Get-TerminalIconsTheme' 'Set-TerminalIconsColorTheme' + 'Set-TerminalIconsIcon' 'Set-TerminalIconsIconTheme' 'Show-TerminalIconsTheme' ) @@ -34,5 +36,3 @@ } } } - - diff --git a/docs/en-US/Get-TerminalIconsGlyphs.md b/docs/en-US/Get-TerminalIconsGlyphs.md new file mode 100644 index 0000000..b18e471 --- /dev/null +++ b/docs/en-US/Get-TerminalIconsGlyphs.md @@ -0,0 +1,50 @@ +--- +external help file: Terminal-Icons-help.xml +Module Name: Terminal-Icons +online version: +schema: 2.0.0 +--- + +# Get-TerminalIconsGlyphs + +## SYNOPSIS +Gets the list of glyphs known to Terminal-Icons. + +## SYNTAX + +``` +Get-TerminalIconsGlyphs [] +``` + +## DESCRIPTION +Gets a hashtable with the available glyph names and icons. +Useful in creating a custom theme. + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-TerminalIconsGlyphs +``` + +Gets the table of glyph names and icons. + +## PARAMETERS + +### 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 + +### None. +## OUTPUTS + +### None. +## NOTES + +## RELATED LINKS + +[Get-TerminalIconsIconTheme]() + +[Set-TerminalIconsIcon]() + diff --git a/docs/en-US/Set-TerminalIconsIcon.md b/docs/en-US/Set-TerminalIconsIcon.md new file mode 100644 index 0000000..3d1e11a --- /dev/null +++ b/docs/en-US/Set-TerminalIconsIcon.md @@ -0,0 +1,218 @@ +--- +external help file: Terminal-Icons-help.xml +Module Name: Terminal-Icons +online version: +schema: 2.0.0 +--- + +# Set-TerminalIconsIcon + +## SYNOPSIS +Set a specific icon in the current Terminal-Icons icon theme or allows +swapping one glyph for another. + +## SYNTAX + +### FileExtension (Default) +``` +Set-TerminalIconsIcon -FileExtension -Glyph [-Force] [-WhatIf] [-Confirm] + [] +``` + +### Directory +``` +Set-TerminalIconsIcon -Directory -Glyph [-Force] [-WhatIf] [-Confirm] [] +``` + +### FileName +``` +Set-TerminalIconsIcon -FileName -Glyph [-Force] [-WhatIf] [-Confirm] [] +``` + +### SwapGlyph +``` +Set-TerminalIconsIcon -NewGlyph -Glyph [-Force] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +Set the Terminal-Icons icon for a specific file/directory or glyph to a +named glyph. + +Also allows all uses of a specific glyph to be replaced with a different +glyph. + +## EXAMPLES + +### EXAMPLE 1 +``` +Set-TerminalIconsIcon -FileName "README.md" -Glyph "nf-fa-file_text" +``` + +Set README.md files to display a text file icon. + +### EXAMPLE 2 +``` +Set-TerminalIconsIcon -FileExtension ".xml" -Glyph "nf-mdi-file_xml" +``` + +Set XML files to display an XML file icon. + +### EXAMPLE 3 +``` +Set-TerminalIconsIcon -Directory ".github" -Glyph "nf-mdi-github_face" +``` + +Set directories named ".github" to display an Octocat face icon. + +### EXAMPLE 4 +``` +Set-TerminalIconsIcon -Glyph "nf-mdi-xml" -NewGlyph "nf-mdi-file_xml" +``` + +Changes all uses of the "nf-mdi-xml" double-wide glyph to be the "nf-mdi-file_xml" +single-width XML file glyph. + +## PARAMETERS + +### -Directory +The well-known directory name to match for the icon. + +```yaml +Type: String +Parameter Sets: Directory +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FileName +The well-known file name to match for the icon. + +```yaml +Type: String +Parameter Sets: FileName +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FileExtension +The file extension to match for the icon. + +```yaml +Type: String +Parameter Sets: FileExtension +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NewGlyph +The name of the new glyph to use when swapping. + +```yaml +Type: String +Parameter Sets: SwapGlyph +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Glyph +The name of the glyph to use; or, when swapping glyphs, the name of the +glyph you want to change. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Force +Bypass confirmation messages. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +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 +``` + +### 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 + +### None. +### The command does not accept pipeline input. +## OUTPUTS + +### None. +## NOTES + +## RELATED LINKS + +[Get-TerminalIconsIconTheme]() + +[Get-TerminalIconsTheme]() + +[Get-TerminalIconsGlyphs]() +