Skip to content

Commit

Permalink
Merge pull request #35 from tillig/set-terminaliconsicon
Browse files Browse the repository at this point in the history
Add Set-TerminalIconsIcon, Get-TerminalIconsGlyphs
  • Loading branch information
devblackops authored Apr 21, 2021
2 parents be1e6cd + eb33461 commit 86d26af
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Terminal-Icons/Public/Get-TerminalIconsGlyphs.ps1
Original file line number Diff line number Diff line change
@@ -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
}
134 changes: 134 additions & 0 deletions Terminal-Icons/Public/Set-TerminalIconsIcon.ps1
Original file line number Diff line number Diff line change
@@ -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 }
}
}
}
4 changes: 2 additions & 2 deletions Terminal-Icons/Terminal-Icons.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
'Add-TerminalIconsIconTheme'
'Format-TerminalIcons'
'Get-TerminalIconsColorTheme'
'Get-TerminalIconsGlyphs'
'Get-TerminalIconsIconTheme'
'Get-TerminalIconsTheme'
'Set-TerminalIconsColorTheme'
'Set-TerminalIconsIcon'
'Set-TerminalIconsIconTheme'
'Show-TerminalIconsTheme'
)
Expand All @@ -34,5 +36,3 @@
}
}
}


50 changes: 50 additions & 0 deletions docs/en-US/Get-TerminalIconsGlyphs.md
Original file line number Diff line number Diff line change
@@ -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 [<CommonParameters>]
```

## 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]()

Loading

0 comments on commit 86d26af

Please sign in to comment.