Skip to content

Commit 7ffffda

Browse files
committed
split out more files
1 parent 550aa68 commit 7ffffda

File tree

4 files changed

+101
-99
lines changed

4 files changed

+101
-99
lines changed

Microsoft.PowerShell_profile.ps1

+18-99
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

2-
<#
3-
.SYNOPSIS
4-
Set the prompt to a colorized string customized by elevation
5-
#>
2+
# override the prompt function
63
function prompt {
74
$saveCode = $LASTEXITCODE
85
if (Confirm-Elevated) {
@@ -18,119 +15,41 @@ function prompt {
1815
}
1916

2017

21-
#=======================================================================================
2218
# Aliases
23-
#---------------------------------------------------------------------------------------
2419

2520
New-Alias ep Invoke-EditProfile
2621
New-Alias su Invoke-SuperUser
2722
New-Alias vs Invoke-VsDevCmd
2823
New-Alias cc Show-ColorizedContent
2924

25+
. $PSScriptRoot\Modules\Scripts\Set-OutDefaultOverride.ps1
26+
Set-Alias ls Get-ChildItemColorized -Force -Option AllScope
27+
28+
function Invoke-Wilma { & 'C:\Program Files\Tools\WiLMa\WinLayoutManager.exe' }
29+
New-Alias wilma Invoke-Wilma
30+
3031
# Docker helpers
3132
New-Alias doc Invoke-DockerClean
3233
New-Alias dos Invoke-DockerShow
3334

35+
# OK, Go!
3436

35-
#=======================================================================================
36-
# Get-ColorDir (ls)
37-
#---------------------------------------------------------------------------------------
38-
39-
New-CommandWrapper Out-Default -Process {
40-
$nocase = ([Text.RegularExpressions.RegexOptions]::IgnoreCase)
41-
$compressed = New-Object Text.RegularExpressions.Regex('\.(zip|tar|gz|iso)$', $nocase)
42-
$executable = New-Object Text.RegularExpressions.Regex('\.(exe|bat|cmd|msi|ps1|psm1)$', $nocase)
43-
44-
if (($_ -is [IO.DirectoryInfo]) -or ($_ -is [IO.FileInfo])) {
45-
if (-not ($notfirst)) {
46-
$parent = [IO.Path]::GetDirectoryName($_.FullName)
47-
Write-Host "`n Directory: $parent`n"
48-
Write-Host "Mode Last Write Time Length Name"
49-
Write-Host "---- --------------- ------ ----"
50-
$notfirst = $true
51-
}
52-
53-
if ($_ -is [IO.DirectoryInfo]) {
54-
Write-Host ("{0} {1} " -f $_.mode, ([String]::Format("{0,10} {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t")))) -NoNewline
55-
Write-Host $_.name -ForegroundColor "Blue"
56-
}
57-
else {
58-
if ($compressed.IsMatch($_.Name)) {
59-
$color = "Magenta"
60-
}
61-
elseif ($executable.IsMatch($_.Name)) {
62-
$color = "DarkGreen"
63-
}
64-
else {
65-
$color = "Gray"
66-
}
67-
Write-Host ("{0} {1} {2,10} " -f $_.mode, ([String]::Format("{0,10} {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t"))), $_.length) -NoNewline
68-
Write-Host $_.name -ForegroundColor $color
69-
}
70-
71-
$_ = $null
72-
}
73-
} -end {
74-
Write-Host
75-
}
76-
77-
function Get-DirSize {
78-
param ($dir,
79-
[System.Management.Automation.SwitchParameter] $la)
80-
81-
$bytes = 0
82-
$count = 0
83-
84-
Get-Childitem $dir -force:$la | Foreach-Object `
85-
{
86-
if ($_ -is [IO.FileInfo]) {
87-
$bytes += $_.Length
88-
$count++
89-
}
90-
}
91-
92-
Write-Host "`n " -NoNewline
93-
94-
if ($bytes -ge 1KB -and $bytes -lt 1MB) {
95-
Write-Host ("" + [Math]::Round(($bytes / 1KB), 2) + " KB") -NoNewLine
96-
}
97-
elseif ($bytes -ge 1MB -and $bytes -lt 1GB) {
98-
Write-Host ("" + [Math]::Round(($bytes / 1MB), 2) + " MB") -NoNewLine
99-
}
100-
elseif ($bytes -ge 1GB) {
101-
Write-Host ("" + [Math]::Round(($bytes / 1GB), 2) + " GB") -NoNewLine
102-
}
103-
else {
104-
Write-Host ("" + $bytes + " bytes") -NoNewLine
105-
}
106-
Write-Host " in $count files"
107-
}
108-
109-
function Get-ColorDir {
110-
param ($dir,[System.Management.Automation.SwitchParameter] $la)
111-
Get-Childitem $dir -force:$la
112-
Get-DirSize $dir -la:$la
37+
# run vsdevcmd.bat if $env:vsdev is set; this is done by conemu task definition
38+
if ($env:vsdev -eq '1') {
39+
Invoke-VsDevCmd
11340
}
11441

115-
Remove-Item alias:dir
116-
Remove-Item alias:ls
117-
Set-Alias dir Get-ColorDir
118-
Set-Alias ls Get-ColorDir
119-
120-
#=======================================================================================
121-
# OK, Go!
122-
12342
# Chocolatey profile (added by Chocolatey installer)
12443
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
12544
if (Test-Path($ChocolateyProfile)) {
12645
Import-Module "$ChocolateyProfile"
12746
}
12847

129-
# run vsdevcmd.bat if $env:vsdev is set; this is done by conemu task definition
130-
if ($env:vsdev -eq '1') {
131-
Invoke-VsDevCmd
132-
}
133-
13448
# Win-X-I and Win-X-A will open in %userprofile% and %systemrootm%\system32 respectively
135-
# instead set location to root of current drive
136-
Set-Location \
49+
# instead set location to a reasonable place
50+
if (Test-Path 'D:\Code') { Set-Location 'D:\Code'; }
51+
elseif (Test-Path 'D:\Development') { Set-Location 'D:\Development'; }
52+
elseif (Test-Path 'D:\Dev') { Set-Location 'D:\Dev'; }
53+
elseif (Test-Path 'C:\Development') { Set-Location 'C:\Development'; }
54+
elseif (Test-Path 'C:\Dev') { Set-Location 'C:\Dev'; }
55+
else { Set-Location '\'; }
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<#
2+
.SYNOPSIS
3+
Display the current directory listing with total size.
4+
#>
5+
param (
6+
$dir,
7+
[System.Management.Automation.SwitchParameter] $la)
8+
9+
Get-Childitem $dir -force:$la
10+
Get-DirSize $dir -la:$la
11+

Modules/Scripts/Get-DirSize.ps1

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<#
2+
.SYNOPSIS
3+
Report the size of all items in the specified folder.
4+
#>
5+
param (
6+
$dir,
7+
[System.Management.Automation.SwitchParameter] $la)
8+
9+
$bytes = 0
10+
$count = 0
11+
12+
Get-Childitem $dir -force:$la | Foreach-Object `
13+
{
14+
if ($_ -is [IO.FileInfo]) {
15+
$bytes += $_.Length
16+
$count++
17+
}
18+
}
19+
20+
Write-Host "`n " -NoNewline
21+
22+
if ($bytes -ge 1KB -and $bytes -lt 1MB) {
23+
Write-Host("" + [Math]::Round(($bytes / 1KB), 2) + " KB") -NoNewLine
24+
}
25+
elseif ($bytes -ge 1MB -and $bytes -lt 1GB) {
26+
Write-Host("" + [Math]::Round(($bytes / 1MB), 2) + " MB") -NoNewLine
27+
}
28+
elseif ($bytes -ge 1GB) {
29+
Write-Host("" + [Math]::Round(($bytes / 1GB), 2) + " GB") -NoNewLine
30+
}
31+
else {
32+
Write-Host("" + $bytes + " bytes") -NoNewLine
33+
}
34+
Write-Host " in $count files"
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
New-CommandWrapper Out-Default -Process {
3+
$nocase = ([Text.RegularExpressions.RegexOptions]::IgnoreCase)
4+
$compressed = New-Object Text.RegularExpressions.Regex('\.(zip|tar|gz|iso)$', $nocase)
5+
$executable = New-Object Text.RegularExpressions.Regex('\.(exe|bat|cmd|msi|ps1|psm1)$', $nocase)
6+
7+
if (($_ -is [IO.DirectoryInfo]) -or ($_ -is [IO.FileInfo])) {
8+
if (-not ($notfirst)) {
9+
$parent = [IO.Path]::GetDirectoryName($_.FullName)
10+
Write-Host "`n Directory: $parent`n"
11+
Write-Host "Mode Last Write Time Length Name"
12+
Write-Host "---- --------------- ------ ----"
13+
$notfirst = $true
14+
}
15+
16+
if ($_ -is [IO.DirectoryInfo]) {
17+
Write-Host ("{0} {1} " -f $_.mode, ([String]::Format("{0,10} {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t")))) -NoNewline
18+
Write-Host $_.name -ForegroundColor "Blue"
19+
}
20+
else {
21+
if ($compressed.IsMatch($_.Name)) {
22+
$color = "Magenta"
23+
}
24+
elseif ($executable.IsMatch($_.Name)) {
25+
$color = "DarkGreen"
26+
}
27+
else {
28+
$color = "Gray"
29+
}
30+
Write-Host ("{0} {1} {2,10} " -f $_.mode, ([String]::Format("{0,10} {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t"))), $_.length) -NoNewline
31+
Write-Host $_.name -ForegroundColor $color
32+
}
33+
34+
$_ = $null
35+
}
36+
} -end {
37+
Write-Host
38+
}

0 commit comments

Comments
 (0)