Skip to content

Commit

Permalink
Merge pull request #2 from IsWladi/dev
Browse files Browse the repository at this point in the history
Module v0.0.1: Enhanced Visuals & Autocomplete for DockerColorPosh
  • Loading branch information
IsWladi authored Dec 17, 2023
2 parents 96c61a4 + fcc7a97 commit dce8cca
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 93 deletions.
124 changes: 124 additions & 0 deletions DockerColorPosh.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
@{

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

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

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = 'd73315d0-7a80-4f1a-ab4c-59b31eb43701'

# Author of this module
Author = 'IsWladi'

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

# Copyright statement for this module
Copyright = '(c) IsWladi. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Colorful Docker outputs for enhanced readability.'

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

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

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

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# 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, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @("DockerColorPosh", "IntegrateDockerCompletion")

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

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

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# 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. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()

# A URL to the license for this module.
LicenseUri = 'https://github.com/IsWladi/DockerColorPosh/blob/main/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/IsWladi/DockerColorPosh'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false

# External dependent modules of this module
# ExternalModuleDependencies = @()

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

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

}

44 changes: 6 additions & 38 deletions docker_color_posh.psm1 → DockerColorPosh.psm1
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
# Import scripts
. $PSScriptRoot/processors/type_list/list_processor.ps1
. $PSScriptRoot/processors/type_list/container_formatter.ps1
. $PSScriptRoot/processors/type_list/generic_formatter.ps1
. $PSScriptRoot/utility/utility_functions.ps1

# Set the encoding to UTF8 to avoid problems with special characters
$OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8

# This function colorize the output of the docker command of the list type
# This function is called by the DockerColorPosh function
# This function is not intended to be called directly
function ColorizeTypeList {
Param(
[Parameter(ValueFromPipeline=$true)]
[string]$InputLine
)

Begin {
# Create an array to store each line of the docker command output
$array_lines = @()
}

Process {
# Add each line to the array
$array_lines += $InputLine
}

End {
for ($i = 0; $i -lt $array_lines.Count; $i++) {
# if the line is the first one, colorize it with yellow
if ($i -eq 0) {
Write-Host $array_lines[$i] -ForegroundColor Yellow
continue
}
# if the line is pair, colorize it better readability
if ($i % 2 -eq 0) {
Write-Host $($array_lines[$i]) -ForegroundColor DarkCyan
continue
}
# if the line is impair, colorize it better readability
Write-Host $($array_lines[$i]) -ForegroundColor Cyan
}
}
}

# This function is the main function of the module
# Is the only function exported by the module
Expand Down Expand Up @@ -117,8 +90,3 @@ function IntegrateDockerCompletion{
Register-ArgumentCompleter -CommandName $alias -ScriptBlock $completer
}
}

# Export only the DockerColorPosh function
Export-ModuleMember -Function 'DockerColorPosh'
Export-ModuleMember -Function 'IntegrateDockerCompletion'

132 changes: 80 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,87 @@
# 🌈 Docker Color Posh: A Splash of Color to Your Docker Console 🚀
<div align="center">

# DockerColorPosh
##### Colorful Docker outputs for enhanced readability.

<img alt="DockerColorPosh logo" height="280" src="/assets/DockerColorPoshLogo.png" />
</div>

## Table of contents
* [Module´s presentation](#-docker-color-posh-a-splash-of-color-to-your-docker-console-)
* [Project Status](#project-status)
* [Installation](#installation)
* [Integration with the matt9ucci/DockerCompletion module (optional)](#integration-with-the-matt9uccidockercompletion-module-optional)
* [Usage](#usage)
* [Compatible Docker commands](#compatible-docker-commands)
* [Excluded subcommands](#excluded-subcommands)
* [Contributing](#contributing)
* [Disclaimer](#disclaimer)
* [License](#license)

## 🌈 Docker Color Posh: A Splash of Color to Your Docker Console 🚀
Make Your Docker Console Come Alive!
Welcome to the vibrant world of Docker Color Posh, a PowerShell script crafted to transform your Docker console into a kaleidoscope of colors! 🎨 This nifty module isn't just about looks; it's about making your Docker command outputs not only eye-catching but also incredibly easy to read and understand. Dive into a Docker experience where each output becomes a vivid story, helping you quickly identify and interpret various elements with ease.

# Why Docker Color Posh? Because Your Console Deserves to be Fun! 🎉
## Why Docker Color Posh? Because Your Console Deserves to be Fun! 🎉
Our philosophy is simple: Docker is awesome, so why not make it visually awesome too? With docker_color_posh, you'll stick to what you know and love about Docker, but with an added zest of color. It's not just a module; it's your Docker experience, reimagined!

- 🚦 Non-Intrusive Yet Fashionable: It's like having a new paint job that doesn't change the engine. Our module is a stylish output formatter that works with your Docker commands without altering their essence.
- 🌐 Compatibility Meets Flexibility: Fear not if a command doesn't suit up in our color scheme; it will still run just as smoothly, minus the color flair. You get the best of both worlds - the complete Docker command set, with or without our colorful touch.

# Project Status
As of now, the Docker Color Posh module is in its initial stages of development. Further enhancements and feature additions are planned.
![image](https://github.com/IsWladi/Docker-Color-Posh/assets/133131317/327df00a-aa68-4b77-9745-ba3ae631ad62)

# Table of contents
- [Module´s presentation](https://github.com/IsWladi/Docker-Color-Posh/#-docker-color-posh-a-splash-of-color-to-your-docker-console-)
- [Compatible Docker commands](https://github.com/IsWladi/Docker-Color-Posh/#compatible-docker-commands)
- [Excluded subcommands](https://github.com/IsWladi/Docker-Color-Posh/#excluded-subcommands)
- [Installation](https://github.com/IsWladi/Docker-Color-Posh/#installation)
- [Integration with the matt9ucci/DockerCompletion module (optional)](https://github.com/IsWladi/Docker-Color-Posh/#integration-with-the-matt9uccidockercompletion-module-optional)
- [Usage](https://github.com/IsWladi/Docker-Color-Posh/#usage)
- [Contributing](https://github.com/IsWladi/Docker-Color-Posh/#contributing)
- [License](https://github.com/IsWladi/Docker-Color-Posh/#license)

## Project Status
- As of now, the Docker Color Posh module is in its initial stages of development. Further enhancements and feature additions are planned.
- The module can already color a significant number of Docker [commands](#compatible-docker-commands), and it features compatibility and integration with the DockerCompletion tab completion module.
- Currently, the most complete coloring is available for list-type commands (e.g., `docker ps`, `docker volume ls`, `docker network ls`).
- Response-type commands (e.g., `docker container start`, `docker rmi`) and help-type commands (e.g., `docker <command> --help`) have coloring support but it is quite basic at the moment.
- Process-type commands (e.g., `docker build`, `docker run`, `docker pull`) are not compatible for coloring. Due to the complexity of coloring interactive and animated responses that are handled by Docker itself, the module does not intend to add coloring for these types of commands in the future. Docker already stylizes these commands with some colors and animations.
<div align="center">
<img src="/assets/screenshots/docker_ps_all.png" alt="List-type: docker ps -a"/>
</div>


## Installation

To install the Docker Color Posh module and ensure it's automatically loaded in your PowerShell sessions, follow these steps:

1. Install the module into your PowerShell using the command:
```powershell
Install-Module -Name DockerColorPosh
```

2. (Optional) For convenience, you can create an alias. This allows you to use your preferred shortcut for the commands. To set up an alias, use for example:
```powershell
Set-Alias d DockerColorPosh
```

3. PowerShell profile example (for explicit loading):
```powershell
Import-Module -Name DockerColorPosh
Set-Alias d DockerColorPosh
```
* After adding these lines to your profile, the module will be automatically loaded in all future PowerShell sessions, making it ready to use immediately.
* For PowerShell 3.0 and above, the module will be automatically imported when any command from the module is used in a session, so you may not need to add the import command to your profile.

### Integration with the [matt9ucci/DockerCompletion](https://github.com/matt9ucci/DockerCompletion) module (optional)
**The DockerCompletion is a PowerShell module that provides tab completion for Docker commands. It is not required to use Docker Color Posh, but it is recommended for a better user experience.**
1. After installing the Docker Color Posh Module, [install the DockerCompletion module](https://github.com/matt9ucci/DockerCompletion#installation)
2. Execute the following line in your terminal to integrate the DockerCompletion module with Docker Color Posh: `Invoke-Expression IntegrateDockerCompletion`
3. To permanently integrate, add the line to your PowerShell profile. Make sure the line 'Invoke-Expression IntegrateDockerCompletion' is placed after the DockerColorPosh module's alias has been set up.
4. Powershell profile example:
```powershell
Import-Module -Name C:\your\path\to\DockerColorPosh\DockerColorPosh.psd1
Set-Alias d DockerColorPosh
Invoke-Expression IntegrateDockerCompletion
```
## Usage
**The Docker Color Posh module enhances Docker command outputs with color and accepts any arguments. If a command is not supported, it will execute normally without colorization. Moreover, if you have installed and integrated the DockerCompletion module, you'll enjoy the best of both worlds: completion and colorized outputs!**
To use the module, you can invoke it directly with commands such as (replace `DockerColorPosh` with your alias if you have set one):
- `DockerColorPosh ps`
- `DockerColorPosh ps -a`
- `DockerColorPosh images`
## Compatible Docker commands
**It's important to note that while these are the primary commands supported, the module is designed to accommodate additional parameters for these commands, as with standard Docker usage. For example, you can use docker ps -a to list all containers, and the output will be colorized accordingly.**
Expand Down Expand Up @@ -62,44 +122,12 @@ As of now, the Docker Color Posh module is in its initial stages of development.
| List | `docker system df -v` |
| List | `docker system df --verbose` |
## Installation
To install the Docker Color Posh module and ensure its automatic loading in your PowerShell sessions, follow these steps:
1. Download the `docker_color_posh.psm1` file from the repository.
2. Import the module into your PowerShell session using the command: `Import-Module -Name /path/to/docker_color_posh.psm1`
3. For convenience, you can create an alias. This allows you to use your preferred shortcut for the commands. To set up an alias, use: `Set-Alias d DockerColorPosh`
4. To make the module load automatically in future sessions, add the import command and your alias to your PowerShell profile.
5. After adding this line to your profile, the module will be automatically loaded in all future PowerShell sessions, making it ready to use immediately.
6. Powershell profile example:
```powershell
Import-Module -Name C:\your\path\to\docker-color-posh\docker_color_posh.psm1
Set-Alias d DockerColorPosh
```
## Integration with the [matt9ucci/DockerCompletion](https://github.com/matt9ucci/DockerCompletion) module (optional)
**The DockerCompletion is a PowerShell module that provides tab completion for Docker commands. It is not required to use Docker Color Posh, but it is recommended for a better user experience.**
1. After installing the Docker Color Posh Module, [install the DockerCompletion module](https://github.com/matt9ucci/DockerCompletion#installation)
2. Execute the following line in your terminal to integrate the DockerCompletion module with Docker Color Posh: `Invoke-Expression IntegrateDockerCompletion`
3. To permanently integrate, add the line to your PowerShell profile. Make sure the line 'Invoke-Expression IntegrateDockerCompletion' is placed after the DockerColorPosh module's alias has been set up.
4. Powershell profile example:
```powershell
Import-Module -Name C:\your\path\to\docker-color-posh\docker_color_posh.psm1
Set-Alias d DockerColorPosh
Invoke-Expression IntegrateDockerCompletion
```
## Usage
**The Docker Color Posh module enhances Docker command outputs with color and accepts any arguments. If a command is not supported, it will execute normally without colorization. Moreover, if you have installed and integrated the DockerCompletion module, you'll enjoy the best of both worlds: completion and colorized outputs!**
To use the module, you can invoke it directly with commands such as (replace `DockerColorPosh` with your alias if you have set one):
- `DockerColorPosh ps`
- `DockerColorPosh ps -a`
- `DockerColorPosh images`
## Contributing
Contributions to the Docker Color Posh module are warmly welcomed. If you have suggestions for improvements or new features, feel free to create an issue or submit a pull request on the project's repository.
## Disclaimer
"Docker Color Posh" is an independent project created by IsWladi. This module is not sponsored, endorsed by, or affiliated with Docker, Inc. or its affiliates in any way. Docker is a registered trademark of Docker, Inc. and is mentioned here only for descriptive purposes and with no intention of infringement. This module is an independent effort to enhance the user experience in using Docker and does not imply any legal, commercial, or economic relationship with Docker, Inc.
## License
A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.
Binary file added assets/DockerColorPoshLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/docker_help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/docker_images.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/docker_ps_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/docker_start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions processors/type_list/container_formatter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function ContainerFormatter {
param (
[Parameter(Mandatory = $true)]
[string[]]$array_lines,
[Parameter(Mandatory = $true)]
[int]$i
)

if ($i -eq 0) {
Write-Host $array_lines[$i] -ForegroundColor Yellow
return
}
# determine the state of the container
# One of created, restarting, running, removing, paused, exited, or dead
$container_state = "Other"# Prevents the variable from being null

# check every state possible and assign it to the variable
if ($array_lines[$i] -match "Up") {
$container_state = "Up"
} elseif ($array_lines[$i] -match "Exited") {
$container_state = "Exited"
}

$color_command = if ($i % 2 -eq 0) { "DarkCyan" } else { "Cyan" }

# Create a hashtable to store the colors of each state
$stateColors = @{
"Up" = "Green"
"Exited" = "Red"
"Other"= $color_command
}
$color_subcommand = $stateColors[$container_state]

# if the state it´s not Up or Exited, colorize it without resalt the state
if ($container_state -eq "Other") {
Write-Host $array_lines[$i] -ForegroundColor $color_command
} else {
ParseSubExpressionRegex -full_cmd $array_lines[$i] -regex $container_state -sub_cmd_color $color_subcommand -main_color $color_command
}
}
20 changes: 20 additions & 0 deletions processors/type_list/generic_formatter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function GenericFormatter {
param (
[Parameter(Mandatory = $true)]
[string[]]$array_lines,
[Parameter(Mandatory = $true)]
[int]$i
)
# if the line is the first one, colorize it with yellow
if ($i -eq 0) {
Write-Host $array_lines[$i] -ForegroundColor Yellow
return
}
# if the line is pair, colorize it better readability
if ($i % 2 -eq 0) {
Write-Host $($array_lines[$i]) -ForegroundColor DarkCyan
return
}
# if the line is impair, colorize it better readability
Write-Host $($array_lines[$i]) -ForegroundColor Cyan
}
Loading

0 comments on commit dce8cca

Please sign in to comment.