Skip to content

Commit 74832fb

Browse files
v2.21.0
1 parent 11d6c4a commit 74832fb

17 files changed

+601
-36
lines changed

PSScriptTools.psd1

232 Bytes
Binary file not shown.

PSScriptTools.psm1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ Get-ChildItem -path $PSScriptRoot\functions\*.ps1 | ForEach-Object -process {
99
. $_.FullName
1010
}
1111

12+
#define the global PSAnsiFileMap variable
13+
$json = "psansifilemap.json"
14+
#test for user version
15+
$userjson = Join-Path -path $HOME -ChildPath $json
16+
$modjson = Join-Path -path $PSScriptRoot -ChildPath $json
17+
18+
if (Test-Path -path $userjson) {
19+
$map = $userjson
20+
}
21+
else {
22+
$map = $modjson
23+
}
24+
25+
Set-Variable -Name PSAnsiFileMap -value (Get-Content -path $map | ConvertFrom-Json) -Scope Global
26+
1227
#add ToDo options to the ISE or VS Code
1328
if ($psEditor) {
1429
#This may not be working in newer versions of the PowerShell extension under PowerShell 7

README.md

Lines changed: 124 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This PowerShell module contains a number of functions you might use to enhance y
66

77
## Current Release
88

9-
You can get the current release from this repository or install this from the PowerShell Gallery:
9+
You can get the current release from this repository or install this the PowerShell Gallery:
1010

1111
```powershell
1212
Install-Module PSScriptTools
@@ -15,7 +15,7 @@ Install-Module PSScriptTools
1515
or in PowerShell 7:
1616

1717
```powershell
18-
Install-Module PSScriptTools -scope CurrentUser
18+
Install-Module PSScriptTools [-scope CurrentUser]
1919
```
2020

2121
Starting in v2.2.0, the module was restructured to better support Desktop and Core editions. But starting with version 2.13.0, the module design has reverted. All commands will be exported. Anything that is platform specific should be handled on a per command basis. It is assumed you will be running this module in Windows PowerShell 5.1 or PowerShell 7.
@@ -1103,7 +1103,9 @@ If you are running PowerShell 7 and specifying a file system path, you can displ
11031103

11041104
![show file system tree](images/show-tree2.png)
11051105

1106-
I have long term plans to have a user-configurable color map for different item types.
1106+
Beginning with v2.21.0, this command uses ANSI Color schemes from a json file.
1107+
You can customize the file if you wish.
1108+
See the [PSAnsiMap](#PSAnsiMap) section of this README.
11071109

11081110
This command has an alias of `pstree`.
11091111

@@ -1135,7 +1137,9 @@ C:\work\Alpha\
11351137
...
11361138
```
11371139

1138-
Show a tree listing with files including a few properties. This example is using parameter and command aliases.
1140+
This example is using parameter and command aliases.
1141+
You can display a tree listing with files including user specified properties.
1142+
Use a value of * to show all properties.
11391143

11401144
## Format-Functions
11411145

@@ -1191,9 +1195,32 @@ TotalMemGB FreeMemGB PctFree
11911195

11921196
## Scripting Tools
11931197

1198+
### [Get-GitSize](docs/Get-GitSize.md)
1199+
1200+
Use this command to determine how much space the hidden `.git` folder is consuming.
1201+
1202+
```powershell
1203+
PS C:\scripts\PSScriptTools> Get-GitSize
1204+
1205+
Path Files SizeKB
1206+
---- ----- ------
1207+
C:\scripts\PSScriptTools 751 6859.9834
1208+
```
1209+
1210+
This is the default, formatted view. The object has other properties you can use.
1211+
1212+
```powershell
1213+
Name : PSScriptTools
1214+
Path : C:\scripts\PSScriptTools
1215+
Files : 751
1216+
Size : 7024623
1217+
Date : 3/5/2020 2:57:06 PM
1218+
Computername : BOVINE320
1219+
```
1220+
11941221
### [Remove-MergedBranch](docs/Remove-MergedBranch.md)
11951222

1196-
When using git you may create a number of branches.
1223+
When using `git` you may create a number of branches.
11971224
Presumably you merge these branches into the main or master branch.
11981225
You can this command to remove all merged branches other than master and the current branch.
11991226
You must be in the root of your project to run this command.
@@ -1337,11 +1364,11 @@ If you run this command within VS Code and specify `-Passthru`, the resulting fi
13371364

13381365
### [Test-IsPSWindows](docs/Test-IsPSWindows.md)
13391366

1340-
PowerShell Core introduced the `$IsWindows` variable. However it is not available on Windows PowerShell. Use this command to perform a simple test if the computer is either running Windows or using the Desktop PSEdition. The command returns True or False.
1367+
PowerShell Core introduced the `$IsWindows` variable. However it is not available on Windows PowerShell. Use this command to perform a simple test if the computer is either running Windows or using the Desktop PSEdition. The command returns `True` or `False`.
13411368

13421369
### [Write-Detail](docs/Write-Detail.md)
13431370

1344-
This command is designed to be used within your functions and scripts to make it easier to write a detailed message that you can use as verbose output. The assumption is that you are using an advanced function with a Begin, Process and End scriptblocks. You can create a detailed message to indicate what part of the code is being executed. The output can be configured to include a datetime stamp or just the time.
1371+
This command is designed to be used within your functions and scripts to make it easier to write a detailed message that you can use as verbose output. The assumption is that you are using an advanced function with a `Begin`, `Process` and `End` scriptblocks. You can create a detailed message to indicate what part of the code is being executed. The output can be configured to include a datetime stamp or just the time.
13451372

13461373
```powershell
13471374
PS C:\> write-detail "Getting file information" -Prefix Process -Date
@@ -1389,6 +1416,95 @@ This will display the service status color-coded.
13891416

13901417
![ServiceAnsi](images/serviceansi.png)
13911418

1419+
### PSAnsiMap
1420+
1421+
I have done something similar for output from `Get-ChildItem`.
1422+
The module includes json file that is exported as a global variable called `PSAnsiFileMap`.
1423+
1424+
```powershell
1425+
PS C:\scripts\PSScriptTools> $PSAnsiFileMap
1426+
1427+
Description Pattern Ansi
1428+
----------- ------- ----
1429+
PowerShell \.ps(d|m)?1$
1430+
Text \.(txt)|(md)|(log)$
1431+
DataFile \.(json)|(xml)|(csv)$
1432+
Executable \.(exe)|(bat)|(cmd)|(sh)$
1433+
Graphics \.(jpg)|(png)|(gif)|(bmp)|(jpeg)$
1434+
Media \.(mp3)|(m4v)|(wav)|(au)|(flac)|(mp4)$
1435+
Archive \.(zip)|(rar)|(tar)|(gzip)$
1436+
TopContainer
1437+
ChildContainer
1438+
```
1439+
1440+
The map includes ANSI settings for different file types.
1441+
You won't see the ANSI value in the output.
1442+
The module will add a custom table view called `ansi` which you can use to display file results colorized in PowerShell 7.
1443+
1444+
![](images/ansi-file-format.png)
1445+
1446+
The mapping file is user customizable.
1447+
Copy the `psansifilemap.json` file from the module's root directory to $HOME.
1448+
When you import this module, if the file is found, it will be imported and used as `psansifilemap`, otherwise the module's file will be used.
1449+
1450+
The file will look like this:
1451+
1452+
```json
1453+
[
1454+
{
1455+
"Description": "PowerShell",
1456+
"Pattern": "\\.ps(d|m)?1$",
1457+
"Ansi": "\u001b[38;2;252;127;12m"
1458+
},
1459+
{
1460+
"Description": "Text",
1461+
"Pattern": "\\.(txt)|(md)|(log)$",
1462+
"Ansi": "\u001b[38;2;58;120;255m"
1463+
},
1464+
{
1465+
"Description": "DataFile",
1466+
"Pattern": "\\.(json)|(xml)|(csv)$",
1467+
"Ansi": "\u001b[38;2;249;241;165m"
1468+
},
1469+
{
1470+
"Description": "Executable",
1471+
"Pattern": "\\.(exe)|(bat)|(cmd)|(sh)$",
1472+
"Ansi": "\u001b[38;2;197;15;31m"
1473+
},
1474+
{
1475+
"Description": "Graphics",
1476+
"Pattern": "\\.(jpg)|(png)|(gif)|(bmp)|(jpeg)$",
1477+
"Ansi": "\u001b[38;2;255;0;255m"
1478+
},
1479+
{
1480+
"Description": "Media",
1481+
"Pattern": "\\.(mp3)|(m4v)|(wav)|(au)|(flac)|(mp4)$",
1482+
"Ansi": "\u001b[38;2;255;199;6m"
1483+
},
1484+
{
1485+
"Description": "Archive",
1486+
"Pattern": "\\.(zip)|(rar)|(tar)|(gzip)$",
1487+
"Ansi": "\u001b[38;2;118;38;113m"
1488+
},
1489+
{
1490+
"Description": "TopContainer",
1491+
"Pattern": "",
1492+
"Ansi": "\u001b[38;2;0;255;255m"
1493+
},
1494+
{
1495+
"Description": "ChildContainer",
1496+
"Pattern": "",
1497+
"Ansi": "\u001b[38;2;255;255;0m"
1498+
}
1499+
]
1500+
```
1501+
1502+
You can create or modify file groups.
1503+
The Pattern value should be a regular expression pattern to match on the filename.
1504+
Don't forget you will need to escape characters for the json format.
1505+
The Ansi value will be an ANSI escape sequence.
1506+
You can use `\u001b` for the \``e` character.
1507+
13921508
## Related Modules
13931509

13941510
If you find this module useful, you might also want to look at my tools for [creating and managing custom type extensions](https://github.com/jdhitsolutions/PSTypeExtensionTools), [managing scheduled jobs](https://github.com/jdhitsolutions/ScheduledJobTools) and [running remote commands outside of PowerShell Remoting](https://github.com/jdhitsolutions/PSRemoteOperations)
@@ -1397,4 +1513,4 @@ If you find this module useful, you might also want to look at my tools for [cre
13971513

13981514
Where possible these commands have been tested with PowerShell 7, but not every platform. If you encounter problems, have suggestions or other feedback, please post an issue. It is assumed you will __not__ be running this commands on any edition of PowerShell Core or any beta releases of PowerShell 7.
13991515

1400-
Last Updated *2020-03-02 17:43:53Z UTC*
1516+
Last Updated *2020-03-12 15:22:43Z UTC*

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Change Log for PSScriptTools
22

3+
## v2.21.0
4+
5+
+ Updated `Set-ConsoleTitle` and `Set-ConsoleColor` to display a warning if not in a console session. (Issue #75)
6+
+ Added `Get-GitSize` and format file `gitsize.format.ps1xml`
7+
+ Added a default ANSI color map file `psansimap.json`.
8+
+ Modified module to use a copy of `psansimap.json` in $HOME if detected. Otherwise, use the module's version.
9+
+ Create a global variable called `PSAnsiFileMap` from importing the `psansimap.json` file.
10+
+ Updated `Show-Tree` to use an ansi color map. (Issue #69)
11+
+ Added `FileSystem-ansi.format.ps1xml` which adds a custom view called `ansi`. This colorizes files based on `$PSAnsiMap`.
12+
+ Updated `Show-Tree` to resolve child paths using `-LiteralPath`.
13+
+ Updated `README.md`
14+
315
## v2.20.0
416

517
+ Restructured `Get-FileSizeInfo` to better handle Windows PowerShell. (Issue #70)

docs/Get-GitSize.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
external help file: PSScriptTools-help.xml
3+
Module Name: psscripttools
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Get-GitSize
9+
10+
## SYNOPSIS
11+
12+
Get the size of .git folder.
13+
14+
## SYNTAX
15+
16+
```yaml
17+
Get-GitSize [[-Path] <String>] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
22+
When using git, it creates a hidden folder for change tracking.
23+
Because the file is hidden it is easy to overlook how large it might become.
24+
The command uses a formatting file to display a default view.
25+
There is an additonal table view called MB that you can use.
26+
27+
## EXAMPLES
28+
29+
### EXAMPLE 1
30+
31+
```powershell
32+
PS C:\Scripts\PiedPiper> Get-GitSize
33+
34+
Path Files SizeKB
35+
---- ----- ------
36+
C:\scripts\PiedPiper 751 6859.9834
37+
```
38+
39+
Get the size of the .git folder from the current path.
40+
41+
### EXAMPLE 2
42+
43+
```powershell
44+
PS C:\> Get-ChildItem c:\scripts -Directory | Get-GitSize | Sort-Object -property Size -descending | Select-Object -first 5 -property Computername,Name,Files,Size
45+
46+
Computername Name Files Size
47+
------------ ---- ----- ----
48+
WIN10DSK2 PSAutoLab 526 193760657
49+
WIN10DSK2 DevOps-Courses 29 53298180
50+
WIN10DSK2 PSScriptTools 751 7024623
51+
WIN10DSK2 PSGUI 32 6705894
52+
WIN10DSK2 DscWorkshop 24 5590511
53+
```
54+
55+
Get the directories under C:\Scripts that have a .git folder and sort on the Size property in descending order.
56+
Then select the first 5 directories and use the specified properties.
57+
58+
### EXAMPLE 3
59+
60+
```powershell
61+
PS S:\PSReleaseTools> Get-GitSize | Format-Table -view mb
62+
63+
Path Files SizeMB
64+
---- ----- ------
65+
C:\scripts\PSReleaseTools 440 3.0588
66+
```
67+
68+
Get the git folder size and format using the MB table view.
69+
70+
## PARAMETERS
71+
72+
### -Path
73+
74+
The path to the parent folder, not the .git folder.
75+
76+
```yaml
77+
Type: String
78+
Parameter Sets: (All)
79+
Aliases: pspath
80+
81+
Required: False
82+
Position: 1
83+
Default value: current location
84+
Accept pipeline input: True (ByPropertyName, ByValue)
85+
Accept wildcard characters: False
86+
```
87+
88+
### CommonParameters
89+
90+
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).
91+
92+
## INPUTS
93+
94+
### [System.String]
95+
96+
## OUTPUTS
97+
98+
### gitSize
99+
100+
## NOTES
101+
102+
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/
103+
104+
This is a variation of code posted at https://gist.github.com/jdhitsolutions/cbdc7118f24ba551a0bb325664415649
105+
106+
## RELATED LINKS
107+
108+
[Get-ChildItem]()
109+
110+
[Measure-Object]()

docs/Set-ConsoleColor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Set-ConsoleColor [[-Foreground] <ConsoleColor>] [[-Background] <ConsoleColor>] [
2020

2121
## DESCRIPTION
2222

23-
You can use this command to modify the PowerShell console's foreground and/or background color. Note that if you are running the PSReadline module, that module has commands, like Set-PSReadLineOption, that you can use to modify your console.
23+
You can use this command to modify the PowerShell console's foreground and/or background color. Note that if you are running the PSReadline module, that module has commands, like Set-PSReadLineOption, that you can use to modify your console. This command is intended for use in a traditional PowerShell console. It will not work in consoles that are part of the PowerShell ISE or Visual Studio Code.
2424

2525
## EXAMPLES
2626

docs/Set-ConsoleTitle.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Set-ConsoleTitle [-Title] <String> [-WhatIf] [-Confirm] [<CommonParameters>]
2020
## DESCRIPTION
2121

2222
Use this command to modify the text displayed in the title bar of your PowerShell console window.
23+
This command is intended for use in a traditional PowerShell console. It will not work in consoles that are part of the PowerShell ISE or Visual Studio Code. It should work in a PowerShell session running in Windows Terminal.
2324

2425
## EXAMPLES
2526

docs/Show-Tree.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Shows the specified path as a graphical tree in the console. This is intended as
3333

3434
By default, the output will only show directory or equivalent structures. But you can opt to include items well as item details by using the ShowProperty parameter. Specify a comma separated list of properties or use * to view them all.
3535

36-
It should work cross-platform. If you are running PowerShell 7, there is a dynamic parameter, -InColor, that will write ANSI-colored output to the pipeline. The color scheme is designed for the file system.
36+
It should work cross-platform. If you are running PowerShell 7, there is a dynamic parameter, -InColor, that will write ANSI-colored output to the pipeline. The color scheme is designed for the file system. This parameter has an alias of -ansi.
3737

3838
Note: This is an update to an older function in my library. I seem to recall I found the original code somewhere online, perhaps from someone like Lee Holmes. Sadly, I neglected to record the source.
3939

@@ -152,7 +152,7 @@ C:\work\Alpha\
152152
...
153153
```
154154

155-
Show a tree listing with files including a few properties. This example is using parameter and command aliases.
155+
Show a tree listing with files including a few user specified properties. This example is using parameter and command aliases.
156156

157157
## PARAMETERS
158158

0 commit comments

Comments
 (0)