Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.
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
50 changes: 43 additions & 7 deletions release/FileInfo.ps1 → FileInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function Write-FileLength
function Write-Color-LS
{
param ([string]$color = "white", $file)

Write-host ("{0,-7} {1,25} {2,10} {3}" -f $file.mode, ([String]::Format("{0,10} {1,8}", $file.LastWriteTime.ToString("d"), $file.LastWriteTime.ToString("t"))), (Write-FileLength $file.length), $file.name) -foregroundcolor $color
}

Expand All @@ -46,21 +45,34 @@ function FileInfo {
$global:PSColor.File.Code.Pattern, $regex_opts)
$executable = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Executable.Pattern, $regex_opts)
$machine = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Machine.Pattern, $regex_opts)
$text_files = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Text.Pattern, $regex_opts)
$image_files = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Image.Pattern, $regex_opts)
$audio_files = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Audio.Pattern, $regex_opts)
$video_files = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Video.Pattern, $regex_opts)
$office_files = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Office.Pattern, $regex_opts)
$compressed = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Compressed.Pattern, $regex_opts)
$temporary = New-Object System.Text.RegularExpressions.Regex(
$global:PSColor.File.Temporary.Pattern, $regex_opts)


if($script:showHeader)
{
Write-Host
Write-Host " Directory: " -noNewLine
Write-Host " $(pwd)`n" -foregroundcolor "Green"
Write-Host "Mode LastWriteTime Length Name"
Write-Host "---- ------------- ------ ----"
Write-Host " Directory: " -foregroundcolor ($PSColor.Meta.Directory.Color) -NoNewline
Write-Host " $(pwd)`n" -foregroundcolor ($PSColor.Meta.DirectoryPath.Color)
Write-Host "Mode LastWriteTime Length Name" -foregroundcolor ($PSColor.Meta.Row.Color)
Write-Host "---- ------------- ------ ----" -foregroundcolor ($PSColor.Meta.Divider.Color)
$script:showHeader=$false
}

if ($hidden.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Hidden.Color $file
Expand All @@ -76,17 +88,41 @@ function FileInfo {
elseif ($executable.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Executable.Color $file
}
elseif ($machine.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Machine.Color $file
}
elseif ($text_files.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Text.Color $file
}
elseif ($image_files.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Image.Color $file
}
elseif ($audio_files.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Audio.Color $file
}
elseif ($video_files.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Video.Color $file
}
elseif ($office_files.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Office.Color $file
}
elseif ($compressed.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Compressed.Color $file
}
elseif ($temporary.IsMatch($file.Name))
{
Write-Color-LS $global:PSColor.File.Temporary.Color $file
}
else
{
Write-Color-LS $global:PSColor.File.Default.Color $file
}
}
}
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2016 David Lindblad
Copyright (c) 2020 Aaron Bockelie

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
File renamed without changes.
159 changes: 159 additions & 0 deletions PSColor.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@

Add-Type -assemblyname System.ServiceProcess

. "$PSScriptRoot\PSColorHelper.ps1"
. "$PSScriptRoot\FileInfo.ps1"
. "$PSScriptRoot\ServiceController.ps1"
. "$PSScriptRoot\MatchInfo.ps1"
. "$PSScriptRoot\ProcessInfo.ps1"



Function Get-PSColorConfig {
[CmdletBinding()]
Param([switch]$Defaults)
#generate path to json color defition file
$PSColorTablePath = Join-Path -Path (Get-ChildItem $profile.CurrentUserCurrentHost).DirectoryName -Childpath PSColorTable.json
if ($Defaults) {
Remove-Item $PSColorTablePath
}
#if the file doesn't exist, generate a template config objcet
if (!(Test-Path $PSColorTablePath)) {
$global:PSColor = @{
Meta = @{
Directory = @{ Color = 'DarkGreen' }
Row = @{ Color = 'Green' }
Divider = @{ Color = 'DarkGreen' }
DirectoryPath = @{ Color = 'Green' }
}
File = @{
Default = @{ Color = 'White' }
Directory = @{ Color = 'Cyan'}
Hidden = @{ Color = 'DarkGray'; Pattern = '^\.' }
Code = @{ Color = 'Magenta'; Pattern = '\.(java|c|cpp|cs|js|css|html|py)$' }
Executable = @{ Color = 'Red'; Pattern = '\.(exe|bat|cmd|py|pl|ps1|psm1|vbs|rb|reg|msi)$' }
Machine = @{ Color = 'Blue'; Pattern = '\.(bin|dll|iso|img|ovf|ova)$' }
Text = @{ Color = 'Yellow'; Pattern = '\.(txt|cfg|conf|ini|csv|log|config|xml|yml|md|markdown)$' }
Image = @{ Color = 'DarkYellow'; Pattern = '\.(jpg|gif|bmp|jpeg|tif|tiff|png|psd|ico)$' }
Audio = @{ Color = 'DarkBlue'; Pattern = '\.(mp3|aif|wav|wma|aif|iff|m4a)$' }
Video = @{ Color = 'DarkCyan'; Pattern = '\.(avi|mov|mpg|mp4|wmv|m4v)$' }
Office = @{ Color = 'DarkRed'; Pattern = '\.(xls|xlsx|xlsm|pdf|docx|doc|ppt|pptx|sdc|sdd|ott|odf|pub|rtf|vsd|vsdx)$' }
Compressed = @{ Color = 'Green'; Pattern = '\.(7z|zip|tar|gz|rar|jar|war)$' }
Temporary = @{ Color = 'Red'; Pattern = '\.(tmp|old|foo|baz|bak)$' }
}
Service = @{
Default = @{ Color = 'White' }
Running = @{ Color = 'DarkGreen' }
Stopped = @{ Color = 'DarkRed' }
}
Match = @{
Default = @{ Color = 'White' }
Path = @{ Color = 'Cyan'}
LineNumber = @{ Color = 'Yellow' }
Line = @{ Color = 'White' }
}
NoMatch = @{
Default = @{ Color = 'White' }
Path = @{ Color = 'Cyan'}
LineNumber = @{ Color = 'Yellow' }
Line = @{ Color = 'White' }
}
}
Write-Warning ("PSColorTable definition file not found at " + $PSColorTablePath + "`r`nCreating default configuration file.`r`nThis only happens if the file doesn't previously exist.")
$global:PSColor | ConvertTo-Json | Out-File $PSColorTablePath
}
else {
if ($global:PSColor) {
Write-Verbose "Overwriting PSColor global variable"
$OMP = get-module -ListAvailable | ?{$_.Name -match "oh-my-posh"}
if ($OMP) {
Write-Warning "oh-my-posh detected, which instances it's own PSColor preference dictionary"
Write-Warning "This should work, but check for compatibility if you experience weirdness."
}
}
$global:PSColor = @{}
Write-Verbose "Loaded PSColors"
(Get-Content $PSColorTablePath | ConvertFrom-Json).psobject.properties | ForEach-Object { $global:PSColor[$_.Name] = $_.Value }
}
}



$script:showHeader=$true

function Out-Default {
[CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability='None')]
param(
[switch]
${Transcript},

[Parameter(Position=0, ValueFromPipeline=$true)]
[psobject]
${InputObject})

begin
{
try {
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
{
$PSBoundParameters['OutBuffer'] = 1
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Core\Out-Default', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }

$steppablePipeline = $scriptCmd.GetSteppablePipeline()
$steppablePipeline.Begin($PSCmdlet)
} catch {
throw
}
}

process
{
try {
if(($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo]))
{
FileInfo $_
$_ = $null
}

elseif($_ -is [System.ServiceProcess.ServiceController])
{
ServiceController $_
$_ = $null
}

elseif($_ -is [Microsoft.Powershell.Commands.MatchInfo])
{
MatchInfo $_
$_ = $null
}
else {
$steppablePipeline.Process($_)
}
} catch {
throw
}
}

end
{
try {
write-host ""
$script:showHeader=$true
$steppablePipeline.End()
} catch {
throw
}
}
<#

.ForwardHelpTargetName Out-Default
.ForwardHelpCategory Function

#>
}

Export-ModuleMember Out-Default
Export-ModuleMember Get-PSColorConfig
File renamed without changes.
File renamed without changes.
96 changes: 96 additions & 0 deletions PsColor.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#
# Module manifest for module 'PsColor'
#
# Generated by: David Lindblad
#
# Generated on: 2014-12-13
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'PSColor.psm1'

# Version number of this module.
ModuleVersion = '2.0.0.0'

# ID used to uniquely identify this module
GUID = '04ff7250-50e1-4f11-adc8-d1b8034981b4'

# Author of this module
Author = 'Aaron Bockelie'

# Company or vendor of this module
# CompanyName = 'Unknown'

# Copyright statement for this module
Copyright = '(c) 2016, 2020 David Lindblad, Aaron Bockelie'

# Description of the functionality provided by this module
Description = 'Basic color highlighting'

# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module
FunctionsToExport = '*'

# Cmdlets to export from this module
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = '*'

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess
# PrivateData = ''

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

Loading