-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.ps1
More file actions
164 lines (140 loc) · 4.32 KB
/
profile.ps1
File metadata and controls
164 lines (140 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Personal profile for Windows Powershell Desktop Edition, a basic one.
# Fix for older Windows versions
#requires -Version 3.0
if ($host.Name -eq 'ConsoleHost'){
$readline = @{
EditMode = "Emacs"
HistorySearchCursorMovesToEnd = $true
ContinuationPrompt = ">>"
BellStyle = "None"
PredictionSource = "HistoryAndPlugin"
PredictionViewStyle = "InLineView"
}
}
if ((Get-Module -Name Psreadline).Version -gt 2.1){
Set-PSReadLineOption @readline
}
# See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_prompts?view=powershell-7.2
function prompt {
# The at sign creates an array in case only one history item exists.
$history = @(Get-History)
if($history.Count -gt 0)
{
$lastItem = $history[$history.Count - 1]
$lastId = $lastItem.Id
}
$nextCommand = $lastId + 1
$currentDirectory = Get-Location
$time = Get-Date -Format "yyyy-MM-dd HH:mm"
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $identity
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
$context = $(if (Test-Path variable:/PSDebugContext) { "[DBG]" }
elseif($principal.IsInRole($adminRole)) { "[ADMIN]" }
else { '' })
$ipaddress = Get-NetIPAddress -AddressFamily IPv4| ? InterfaceAlias -notmatch "Loopback"
$ipaddress = $ipaddress.ipaddress -join " "
$promptLine = @(
"${time} [PS:${PSEdition}] - ${nextCommand}"
"- ${env:USERNAME}@${env:COMPUTERNAME}:[${ipaddress}]"
"${currentDirectory}`n${context} >"
)
$promptline = $promptLine -join " "
Write-Host $promptLine -ForeGroundColor Green -BackGroundColor Black -NoNewLine
return " "
}
function ls {
Get-ChildItem $args -Attributes H,!H,A,!A,S,!S
}
function ll {
[cmdletbinding()]
Param (
$Path
)
Get-ChildItem $Path -Attributes H,!H,A,!A,S,!S
}
function lla {
[cmdletbinding()]
Param (
$Path
)
Get-ChildItem $Path -Attributes H,!H,A,!A,S,!S,C,!C,E,!E
}
function lls {
[cmdletbinding()]
Param (
$Path
)
Get-ChildItem $Path -Attributes H,!H,A,!A,S,!S|Sort-Object Length
}
function llt {
[cmdletbinding()]
Param (
$Path
)
Get-ChildItem $Path -Attributes H,!H,A,!A,S,!S| Sort-Object lastwritetime
}
# Alias for help-command
function gh([string]$help) {
$ErrorActionPreference = "Ignore"
Get-Help -Name $help -Online
}
Function src {
. $Profile
}
Function Test-Administrator {
[cmdletbinding()]
param()
# Check for admin rights
$wid = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp = New-Object System.Security.Principal.WindowsPrincipal($wid)
$adm = [System.Security.Principal.WindowsBuiltInRole]::Administrator
$prp.IsInRole($adm)
}
# PSReadLine usually needs an update
Function Update-PSReadLine {
if (Test-Administrator){
Save-Module -Name PSReadLine -Path "C:\Program Files\WindowsPowerShell\Modules" -Force
}
else {
Start-Process powershell.exe -ArgumentList '-NoProfile Save-Module -Name PSReadLine -Path "C:\Program Files\WindowsPowerShell\Modules" -Force' -Verb RunAs
}
}
# Setup colors and change size on older terminals
Function Set-PSConsole {
# Set colors
$host.ui.RawUI.ForegroundColor = "White"
$host.ui.RawUI.BackgroundColor = "Black"
$colors = @{
ErrorBackgroundColor = "Black"
WarningBackgroundColor = "Black"
VerboseBackgroundColor = "Black"
ErrorForegroundColor = "Red"
WarningForegroundColor = "DarkYellow"
VerboseForegroundColor = "Yellow"
}
$colors.GetEnumerator()| foreach-object {
$host.Privatedata.$($_.key) = $_.value
}
# Setup the buffer
$buffer = $host.ui.RawUI.BufferSize
$buffer.width = 120
$buffer.height = 9999
$host.UI.RawUI.Set_BufferSize($buffer)
# Setup Windowsize based on actual size
$maxWS = $host.UI.RawUI.Get_MaxWindowSize()
$ws = $host.ui.RawUI.WindowSize
if($maxws.width -ge 85){
$ws.width = 85
}
else {
$ws.width = $maxws.width
}
if($maxws.height -ge 42){
$ws.height = 42
}
else {
$ws.height = $maxws.height
}
$host.ui.RawUI.Set_WindowSize($ws)
}