Skip to content

Instantly share code, notes, and snippets.

@nickcox
Created May 5, 2022 23:22
Show Gist options
  • Save nickcox/b4591113b70c087bd9226124843127a8 to your computer and use it in GitHub Desktop.
Save nickcox/b4591113b70c087bd9226124843127a8 to your computer and use it in GitHub Desktop.
Apply PowerShell styles to an LSColors format string
Function Use-LSColors {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$LSColors
)
$LSColors -Split ":" | % {
$param, $arg = $_ -Split "="
if ($param -eq 'di') {
$PSStyle.FileInfo.Directory = "`e[${arg}m"
}
elseif ($param -eq 'ln') {
$PSStyle.FileInfo.SymbolicLink = "`e[${arg}m"
}
elseif ($param -eq 'ex') {
$PSStyle.FileInfo.Executable = "`e[${arg}m"
}
elseif ($param -like '`*.*') {
$PSStyle.FileInfo.Extension[$param.Substring(1)] = "`e[${arg}m"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment