diff --git a/release/FileInfo.ps1 b/FileInfo.ps1 similarity index 60% rename from release/FileInfo.ps1 rename to FileInfo.ps1 index b3b41ab..905ccef 100644 --- a/release/FileInfo.ps1 +++ b/FileInfo.ps1 @@ -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 } @@ -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 @@ -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 } -} \ No newline at end of file +} diff --git a/LICENSE b/LICENSE index d4f3859..c529ea4 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/release/MatchInfo.ps1 b/MatchInfo.ps1 similarity index 100% rename from release/MatchInfo.ps1 rename to MatchInfo.ps1 diff --git a/PSColor.psm1 b/PSColor.psm1 new file mode 100644 index 0000000..9633850 --- /dev/null +++ b/PSColor.psm1 @@ -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 diff --git a/release/PSColorHelper.ps1 b/PSColorHelper.ps1 similarity index 100% rename from release/PSColorHelper.ps1 rename to PSColorHelper.ps1 diff --git a/release/ProcessInfo.ps1 b/ProcessInfo.ps1 similarity index 100% rename from release/ProcessInfo.ps1 rename to ProcessInfo.ps1 diff --git a/PsColor.psd1 b/PsColor.psd1 new file mode 100644 index 0000000..dc5420f --- /dev/null +++ b/PsColor.psd1 @@ -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 = '' + +} + diff --git a/README.md b/README.md index 5bd0b20..8da3704 100644 --- a/README.md +++ b/README.md @@ -8,26 +8,40 @@ Provides color highlighting for some basic PowerShell output. It currently rewri ## Installation -The easiest way to install, by far, is to use [PsGet](http://psget.net/). Once PsGet is installed you can simply run `Install-Module PSColor`. +(TODO) Publish this thing in the Powershell Gallery with a jaunty name that doesn't conflict. -Alternativly, you can download the file [PSColor.zip](https://github.com/Davlind/PSColor/raw/master/release/PSColor.zip) and extract it to a folder named `PSColor` in any of your PowerShell module paths. (Run `$env:PSModulePath` to see your paths.) - -If you want PSColor to be ran automatically you can add `Import-Module PSColor` to your PowerShell Profile. To locate your profile, run `$profile` +Alternativly, you can just git clone this repo in your user profile's powershell module directory. ## Configuration -You can configure PSColor by overriding the values of colors, patterns etc. Configurations should be added after `Import-Module PSColor` in your PowerShell profile. The default configuration looks like: +(TODO) A theme switcher would be swell: something that starts with a blank theme that doesn't hammer a Get-ChildItem when simply importing the module. + +If you want PSColor to be ran automatically you can add `Import-Module PSColor` to your PowerShell Profile. To locate your profile, run `$profile`. + +After importing the module, run `Get-PSColorConfig` to load the builtin color theme. This will instance a file `PSColorTable.json` in the same directory as your PowerShell Profile. + +The next time you import the module, or re-run `Get-PSColorConfig`, you will get your new colors loaded. + +You can configure PSColor by overriding the values of colors, patterns etc. + + +## The PowerShell object $global:PSColor ```powershell $global:PSColor = @{ File = @{ Default = @{ Color = 'White' } Directory = @{ Color = 'Cyan'} Hidden = @{ Color = 'DarkGray'; Pattern = '^\.' } - Code = @{ Color = 'Magenta'; Pattern = '\.(java|c|cpp|cs|js|css|html)$' } - Executable = @{ Color = 'Red'; Pattern = '\.(exe|bat|cmd|py|pl|ps1|psm1|vbs|rb|reg)$' } + 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)$' } - Compressed = @{ Color = 'Green'; Pattern = '\.(zip|tar|gz|rar|jar|war)$' } + Image = @{ Color = 'DarkYellow'; Pattern = '\.(jpg|gif|bmp|jpeg|tif|tiff|png|psd)$' } + 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)$' } + Compressed = @{ Color = 'Green'; Pattern = '\.(7z|zip|tar|gz|rar|jar|war)$' } } Service = @{ Default = @{ Color = 'White' } @@ -40,7 +54,7 @@ $global:PSColor = @{ LineNumber = @{ Color = 'Yellow' } Line = @{ Color = 'White' } } - NoMatch = @{ + NoMatch = @{ Default = @{ Color = 'White' } Path = @{ Color = 'Cyan'} LineNumber = @{ Color = 'Yellow' } @@ -49,8 +63,96 @@ $global:PSColor = @{ } ``` -E.g. if you would like to override the red color for Executables, in favour of blue; you could add the following to your PowerShell profile: +## The JSON object that instances after the first run: -```powershell -$global:PSColor.File.Executable.Color = 'Blue' +```json +{ + "File": { + "Machine": { + "Pattern": "\\.(bin|dll|iso|img|ovf|ova)$", + "Color": "Blue" + }, + "Audio": { + "Pattern": "\\.(mp3|aif|wav|wma|aif|iff|m4a)$", + "Color": "DarkBlue" + }, + "Default": { + "Color": "White" + }, + "Hidden": { + "Pattern": "^\\.", + "Color": "DarkGray" + }, + "Compressed": { + "Pattern": "\\.(7z|zip|tar|gz|rar|jar|war)$", + "Color": "Green" + }, + "Image": { + "Pattern": "\\.(jpg|gif|bmp|jpeg|tif|tiff|png|psd|ico)$", + "Color": "DarkYellow" + }, + "Code": { + "Pattern": "\\.(java|c|cpp|cs|js|css|html|py)$", + "Color": "Magenta" + }, + "Executable": { + "Pattern": "\\.(exe|bat|cmd|py|pl|ps1|psm1|vbs|rb|reg|msi)$", + "Color": "Red" + }, + "Video": { + "Pattern": "\\.(avi|mov|mpg|mp4|wmv|m4v)$", + "Color": "DarkCyan" + }, + "Office": { + "Pattern": "\\.(xls|xlsx|xlsm|pdf|docx|doc|ppt|pptx|sdc|sdd|ott|odf|pub|rtf|vsd|vsdx)$", + "Color": "DarkRed" + }, + "Text": { + "Pattern": "\\.(txt|cfg|conf|ini|csv|log|config|xml|yml|md|markdown)$", + "Color": "Yellow" + }, + "Directory": { + "Color": "Cyan" + } + }, + "NoMatch": { + "LineNumber": { + "Color": "Yellow" + }, + "Line": { + "Color": "White" + }, + "Default": { + "Color": "White" + }, + "Path": { + "Color": "Cyan" + } + }, + "Match": { + "LineNumber": { + "Color": "Yellow" + }, + "Line": { + "Color": "White" + }, + "Default": { + "Color": "White" + }, + "Path": { + "Color": "Cyan" + } + }, + "Service": { + "Running": { + "Color": "DarkGreen" + }, + "Default": { + "Color": "White" + }, + "Stopped": { + "Color": "DarkRed" + } + } +} ``` diff --git a/release/ServiceController.ps1 b/ServiceController.ps1 similarity index 100% rename from release/ServiceController.ps1 rename to ServiceController.ps1 diff --git a/release/PSColor.psm1 b/release/PSColor.psm1 deleted file mode 100644 index 18b6ddd..0000000 --- a/release/PSColor.psm1 +++ /dev/null @@ -1,109 +0,0 @@ - -Add-Type -assemblyname System.ServiceProcess - -. "$PSScriptRoot\PSColorHelper.ps1" -. "$PSScriptRoot\FileInfo.ps1" -. "$PSScriptRoot\ServiceController.ps1" -. "$PSScriptRoot\MatchInfo.ps1" -. "$PSScriptRoot\ProcessInfo.ps1" - -$global:PSColor = @{ - File = @{ - Default = @{ Color = 'White' } - Directory = @{ Color = 'Cyan'} - Hidden = @{ Color = 'DarkGray'; Pattern = '^\.' } - Code = @{ Color = 'Magenta'; Pattern = '\.(java|c|cpp|cs|js|css|html)$' } - Executable = @{ Color = 'Red'; Pattern = '\.(exe|bat|cmd|py|pl|ps1|psm1|vbs|rb|reg)$' } - Text = @{ Color = 'Yellow'; Pattern = '\.(txt|cfg|conf|ini|csv|log|config|xml|yml|md|markdown)$' } - Compressed = @{ Color = 'Green'; Pattern = '\.(zip|tar|gz|rar|jar|war)$' } - } - Service = @{ - Default = @{ Color = 'White' } - Running = @{ Color = 'DarkGreen' } - Stopped = @{ Color = 'DarkRed' } - } - Match = @{ - Default = @{ Color = 'White' } - Path = @{ Color = 'Cyan'} - LineNumber = @{ Color = 'Yellow' } - Line = @{ Color = 'White' } - } -} - -$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 \ No newline at end of file diff --git a/release/PSColor.zip b/release/PSColor.zip deleted file mode 100644 index 7c77b48..0000000 Binary files a/release/PSColor.zip and /dev/null differ diff --git a/release/PsColor.psd1 b/release/PsColor.psd1 deleted file mode 100644 index a850b33..0000000 Binary files a/release/PsColor.psd1 and /dev/null differ diff --git a/src/FileInfo.ps1 b/src/FileInfo.ps1 deleted file mode 100644 index 73053c0..0000000 --- a/src/FileInfo.ps1 +++ /dev/null @@ -1,100 +0,0 @@ - -# Helper method to write file length in a more human readable format -function Write-FileLength -{ - param ($length) - - if ($length -eq $null) - { - return "" - } - elseif ($length -ge 1GB) - { - return ($length / 1GB).ToString("F") + 'GB' - } - elseif ($length -ge 1MB) - { - return ($length / 1MB).ToString("F") + 'MB' - } - elseif ($length -ge 1KB) - { - return ($length / 1KB).ToString("F") + 'KB' - } - - return $length.ToString() + ' ' -} - -# Outputs a line of a DirectoryInfo or FileInfo -function Write-Color-LS -{ - param ([string]$color = "white", $file) - - $length = if ($file -is [System.IO.DirectoryInfo]) { $null } else { $file.length } - 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 $length), $file.name) -foregroundcolor $color -} - -function FileInfo { - param ( - [Parameter(Mandatory=$True,Position=1)] - [System.IO.FileSystemInfo] $file - ) - - $regex_opts = ([System.Text.RegularExpressions.RegexOptions]::IgnoreCase) - - $hidden = New-Object System.Text.RegularExpressions.Regex( - $global:PSColor.File.Hidden.Pattern, $regex_opts) - $code = New-Object System.Text.RegularExpressions.Regex( - $global:PSColor.File.Code.Pattern, $regex_opts) - $executable = New-Object System.Text.RegularExpressions.Regex( - $global:PSColor.File.Executable.Pattern, $regex_opts) - $text_files = New-Object System.Text.RegularExpressions.Regex( - $global:PSColor.File.Text.Pattern, $regex_opts) - $compressed = New-Object System.Text.RegularExpressions.Regex( - $global:PSColor.File.Compressed.Pattern, $regex_opts) - - if ($file -is [System.IO.DirectoryInfo]) - { - $currentdir = $file.Parent.FullName - } else - { - $currentdir = $file.DirectoryName - } - if($script:directory -ne $currentdir) - { - $script:directory = $currentdir - Write-Host - Write-Host " Directory: " -noNewLine - Write-Host " $currentdir`n" -foregroundcolor "Green" - Write-Host "Mode LastWriteTime Length Name" - Write-Host "---- ------------- ------ ----" - } - - if ($hidden.IsMatch($file.Name)) - { - Write-Color-LS $global:PSColor.File.Hidden.Color $file - } - elseif ($file -is [System.IO.DirectoryInfo]) - { - Write-Color-LS $global:PSColor.File.Directory.Color $file - } - elseif ($code.IsMatch($file.Name)) - { - Write-Color-LS $global:PSColor.File.Code.Color $file - } - elseif ($executable.IsMatch($file.Name)) - { - Write-Color-LS $global:PSColor.File.Executable.Color $file - } - elseif ($text_files.IsMatch($file.Name)) - { - Write-Color-LS $global:PSColor.File.Text.Color $file - } - elseif ($compressed.IsMatch($file.Name)) - { - Write-Color-LS $global:PSColor.File.Compressed.Color $file - } - else - { - Write-Color-LS $global:PSColor.File.Default.Color $file - } -} diff --git a/src/MatchInfo.ps1 b/src/MatchInfo.ps1 deleted file mode 100644 index a3f1571..0000000 --- a/src/MatchInfo.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -function PrintContext(){ - param ( - [Parameter(Mandatory=$True)] - $display, - [Parameter(Mandatory=$True)] - $filename, - [Parameter(Mandatory=$True)] - $start - ) - $display | foreach { - Write-Host " ${filename}" -foregroundcolor $global:PSColor.NoMatch.Path.Color -noNewLine - Write-Host ":" -foregroundcolor $global:PSColor.NoMatch.Default.Color -NoNewline - Write-Host "$start" -foregroundcolor $global:PSColor.NoMatch.LineNumber.Color -noNewLine - Write-Host ":" -foregroundcolor $global:PSColor.NoMatch.Default.Color -NoNewline - write-host "$_" -foregroundcolor $global:PSColor.NoMatch.Line.Color - $start++ - } -} - -function MatchInfo { - param ( - [Parameter(Mandatory=$True,Position=1)] - $match - ) - - if ($match.Context) {PrintContext $match.Context.DisplayPreContext $match.RelativePath($pwd) ($match.LineNumber - $match.Context.DisplayPreContext.Count)} - Write-Host '> ' -ForegroundColor $global:PSColor.Match.Default.Color -NoNewline - Write-host $match.RelativePath($pwd) -foregroundcolor $global:PSColor.Match.Path.Color -noNewLine - Write-host ':' -foregroundcolor $global:PSColor.Match.Default.Color -noNewLine - Write-host $match.LineNumber -foregroundcolor $global:PSColor.Match.LineNumber.Color -noNewLine - Write-host ':' -foregroundcolor $global:PSColor.Match.Default.Color -noNewLine - Write-host $match.Line -foregroundcolor $global:PSColor.Match.Line.Color - if ($match.Context) {PrintContext $match.Context.DisplayPostContext $match.RelativePath($pwd) ($match.LineNumber + 1)} -} \ No newline at end of file diff --git a/src/PSColor.psm1 b/src/PSColor.psm1 deleted file mode 100644 index aa7595c..0000000 --- a/src/PSColor.psm1 +++ /dev/null @@ -1,67 +0,0 @@ - -Add-Type -assemblyname System.ServiceProcess - -. "$PSScriptRoot\PSColorHelper.ps1" -. "$PSScriptRoot\FileInfo.ps1" -. "$PSScriptRoot\ServiceController.ps1" -. "$PSScriptRoot\MatchInfo.ps1" -. "$PSScriptRoot\ProcessInfo.ps1" - - - -$global:PSColor = @{ - File = @{ - Default = @{ Color = 'White' } - Directory = @{ Color = 'Cyan'} - Hidden = @{ Color = 'DarkGray'; Pattern = '^\.' } - Code = @{ Color = 'Magenta'; Pattern = '\.(java|c|cpp|cs|js|css|html)$' } - Executable = @{ Color = 'Red'; Pattern = '\.(exe|bat|cmd|py|pl|ps1|psm1|vbs|rb|reg)$' } - Text = @{ Color = 'Yellow'; Pattern = '\.(txt|cfg|conf|ini|csv|log|config|xml|yml|md|markdown)$' } - Compressed = @{ Color = 'Green'; Pattern = '\.(zip|tar|gz|rar|jar|war|7z)$' } - } - 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' } - } -} - -$script:showHeader=$true - -New-CommandWrapper Out-Default -Process { - - 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 - } -} -end { - write-host "" - $script:showHeader=$true -} - -Export-ModuleMember \ No newline at end of file diff --git a/src/PSColorHelper.ps1 b/src/PSColorHelper.ps1 deleted file mode 100644 index 44931d8..0000000 --- a/src/PSColorHelper.ps1 +++ /dev/null @@ -1,12 +0,0 @@ -# Helper method for simulating ellipsis -function CutString -{ - param ([string]$message, $length) - - if ($message.length -gt $length) - { - return $message.SubString(0, $length-3) + '...' - } - - return $message -} \ No newline at end of file diff --git a/src/ProcessInfo.ps1 b/src/ProcessInfo.ps1 deleted file mode 100644 index 7b16aae..0000000 --- a/src/ProcessInfo.ps1 +++ /dev/null @@ -1,31 +0,0 @@ -function Write-Color-Process -{ - 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 -} - -function ProcessInfo { - param ( - [Parameter(Mandatory=$True,Position=1)] - $process - ) - - if($script:showHeader) - { - Write-Host - Write-Host 'Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName' - Write-Host '------- ------ ----- ----- ----- ------ -- -----------' - $script:showHeader=$false - } - $id = $_.Id - $owner = (Get-WmiObject -Class Win32_Process -Filter "ProcessId = $id").getowner() - - Write-Host ("{0,7} {1,7} {2,8} {3} {4}" -f $_.Handles, ` - [math]::Round($_.NonpagedSystemMemorySize / 1KB), ` - [math]::Round($_.PagedMemorySize / 1KB), - $owner.domain, - $owner.user - - ) -} \ No newline at end of file diff --git a/src/PsColor.psd1 b/src/PsColor.psd1 deleted file mode 100644 index a850b33..0000000 Binary files a/src/PsColor.psd1 and /dev/null differ diff --git a/src/ServiceController.ps1 b/src/ServiceController.ps1 deleted file mode 100644 index 2d4cbf2..0000000 --- a/src/ServiceController.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -# Outputs a line of a ServiceController -function Write-Color-Service -{ - param ([string]$color = "white", $service) - - Write-host ("{0,-8}" -f $_.Status) -foregroundcolor $color -noNewLine - Write-host (" {0,-18} {1,-39}" -f (CutString $_.Name 18), (CutString $_.DisplayName 38)) -foregroundcolor "white" -} - -function ServiceController { - param ( - [Parameter(Mandatory=$True,Position=1)] - $service - ) - - if($script:showHeader) - { - Write-Host - Write-Host "Status Name DisplayName" - $script:showHeader=$false - } - - if ($service.Status -eq 'Stopped') - { - Write-Color-Service $global:PSColor.Service.Stopped.Color $service - } - elseif ($service.Status -eq 'Running') - { - Write-Color-Service $global:PSColor.Service.Running.Color $service - } - else { - Write-Color-Service $global:PSColor.Service.Default.Color $service - } -} \ No newline at end of file diff --git a/tools/build.ps1 b/tools/build.ps1 deleted file mode 100644 index 3f70d99..0000000 --- a/tools/build.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -<# -.SYNOPSIS - Generates a manifest for the module - and bundles all of the module source files - and manifest into a distributable ZIP file. -#> - -$ErrorActionPreference = "Stop" - -$scriptPath = Split-Path -LiteralPath $(if ($PSVersionTable.PSVersion.Major -ge 3) { $PSCommandPath } else { & { $MyInvocation.ScriptName } }) - -$src = (Join-Path (Split-Path $scriptPath) 'src') -$dist = (Join-Path (Split-Path $scriptPath) 'release') -if (Test-Path $dist) { - Remove-Item $dist -Force -Recurse -} -New-Item $dist -ItemType Directory | Out-Null - -Write-Host "Creating release archive..." - -# Copy the distributable files to the dist folder. -Copy-Item -Path "$src\*" ` - -Destination $dist ` - -Recurse - -# Requires .NET 4.5 -[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null - -$zipFileName = Join-Path ([System.IO.Path]::GetDirectoryName($dist)) "PSColor.zip" - -# Overwrite the ZIP if it already already exists. -if (Test-Path $zipFileName) { - Remove-Item $zipFileName -Force -} - -$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal -$includeBaseDirectory = $false -[System.IO.Compression.ZipFile]::CreateFromDirectory($dist, $zipFileName, $compressionLevel, $includeBaseDirectory) - -Move-Item $zipFileName $dist -Force \ No newline at end of file