-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
230 lines (181 loc) · 6.94 KB
/
Copy pathMicrosoft.PowerShell_profile.ps1
File metadata and controls
230 lines (181 loc) · 6.94 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Si connexion SSH ou non interactif alors exit
if (-not $Host.UI -or -not $Host.UI.RawUI) {
return
}
# Si interactif
$Host.UI.RawUI.WindowTitle = "PS>_ $env:COMPUTERNAME"
# Variables globales
$ProfileRoot = Split-Path -Parent $PROFILE
# Fichier de log pour la synchronisation avec git
$LogFile = Join-Path $ProfileRoot "updater.log"
# Si le profil n'existe pas, on arrête tout
if (-not (Test-Path $ProfileRoot)) { return }
# Besoin pour l'utilisation de get-history
if (-not (Get-Module PSReadLine) -and (Get-Module -ListAvailable PSReadLine)) {
Import-Module PSReadLine
}
# Chargement des modules
$ModulePaths = @(
"$ProfileRoot/functions",
"$ProfileRoot/alias",
"$ProfileRoot/core",
"$ProfileRoot/install/functions",
"$ProfileRoot/install/apps",
"$ProfileRoot/install/services"
)
foreach ($path in $ModulePaths) {
if (Test-Path $path) {
Get-ChildItem $path -Filter '*.ps1' -File | ForEach-Object {
. $_.FullName
}
}
}
# Charger les secrets
Import-Secrets
# Informations utilisateur et machine
$userName = [System.Environment]::UserName
$machineName = [System.Environment]::MachineName
$IsSSH = $env:SSH_CONNECTION -or $env:SSH_CLIENT -or $env:SSH_TTY
$IsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator
)
$IsUpterm = $env:UPTERM_ADMIN_SOCKET
# Sélection aléatoire parmi une liste d'icônes
$allIconsPrompts = @('💎'; '🥊'; '💾'; '🍄'; '🍌'; '🔥'; '🪐'; '🏴☠️'; '👽'; '👻'; '💩'; '🐧'; '🎃'; '💊'; '🍬'; '🍭'; '🥝'; '🍍'; '🍓'; '🥜'; '🌵'; '🍀'; '🍁'; '🚀'; '🎈'; '⚽'; '⚔')
$IconPromptUser = $allIconsPrompts[(Get-Random -min 0 -max ($allIconsPrompts.Length))]
# Icône SSH
$IconPromptSSH = "📡"
# Utilise des icônes et des couleurs dynamiques selon les droits et la session
# Icône administrateur
$IconPromptAdmin = "⚡"
# Version de PowerShell
$PSVersion = $PSVersionTable.PSVersion.ToString()
# Chemin vers le script de mise à jour de ce profile
$Updater = Join-Path $ProfileRoot "scripts\updater.ps1"
# Sons de notification
$wav_Music = "C:\Windows\Media\Ring05.wav"
$wav_noti = "C:\Windows\Media\Windows Proximity Notification.wav"
#$wav_pass = "C:\Windows\Media\tada.wav"
$Today = Get-Date -Format yyyyMMdd
$SessionId = (Get-Process -Id $PID).SessionId
$MusicLock = "$ProfileRoot\pwsh_music_$Today`_S$SessionId.lock"
# Si pas de fichier lock, jouer le son d'introduction (1 fois / jour)
if (-not (Test-Path $MusicLock) -and -not $IsSSH -and (Test-Path $wav_Music)) {
try {
$player = [System.Media.SoundPlayer]::new($wav_Music)
$player.Play()
}
catch {}
New-Item -Path $MusicLock -ItemType File -Force | Out-Null
}
# Synthèse vocale en français, (1 fois / jour)
$VoiceLock = "$ProfileRoot\pwsh_voice_$Today`_S$SessionId.lock"
if (-not (Test-Path $VoiceLock) -and -not $IsSSH) {
try {
Add-Type -AssemblyName System.Speech -ErrorAction Stop
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.SelectVoice("Microsoft Hortense Desktop")
[void]$speak.SpeakAsync("Salut $userName. Bienvenue sur la machine $machineName.")
}
catch {}
New-Item -Path $VoiceLock -ItemType File -Force | Out-Null
}
# Configuration du prompt
# Initialisation par défaut
$global:lastProcessedId = 0
# Auto-update PROFILE (async)
if (-not (Assert-AppInstalled -Apps "pwsh")) {
installps
return
}
# Lance la mise à jour auto si .git exist
$hasUpdater = Test-Path $Updater
$isGitRepo = Test-Path "$ProfileRoot\.git"
if ($hasUpdater -and $isGitRepo) {
Start-Process "pwsh.exe" `
-ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$Updater`"" `
-WindowStyle Hidden `
-ErrorAction SilentlyContinue
}
# Chargement des alias groupés
My_Alias_Share_Group
My_Alias_SSH_Group
My_Alias_Tools_Group
My_Alias_Wol_Group
# Début de la configuration de la bannière
try {
# Récupération de l'adresse IPv4
$ip_host = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() |
Where-Object { $_.OperationalStatus -eq 'Up' -and $_.NetworkInterfaceType -ne 'Loopback' } |
ForEach-Object { $_.GetIPProperties().UnicastAddresses } |
Where-Object { $_.Address.AddressFamily -eq 'InterNetwork' } |
Select-Object -ExpandProperty Address |
Select-Object -ExpandProperty IPAddressToString -First 1
# Récupération de l'adresse MAC
$mac_address = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() |
Where-Object { $_.OperationalStatus -eq 'Up' -and $_.NetworkInterfaceType -ne 'Loopback' } |
Select-Object -First 1 |
ForEach-Object {
$bytes = $_.GetPhysicalAddress().GetAddressBytes()
($bytes | ForEach-Object { $_.ToString("X2") }) -join ":"
}
}
catch {
$ip_host = "N/A"
$mac_address = "N/A"
}
try {
# Récupération de l'IP publique
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ip_public = (Invoke-RestMethod https://ipinfo.io/ip).Trim()
}
catch {
$ip_public = "N/A"
}
try {
# Récupération des informations sur le stockage disque
$disk_free = (Get-PSDrive C).Free
$disk_used = (Get-PSDrive C).Used
$disk_free_gb = [math]::Round($disk_free / 1GB, 3)
$disk_used_gb = [math]::Round($disk_used / 1GB, 3)
}
catch {
$disk_free_gb = "N/A"
$disk_used_gb = "N/A"
}
# Configuration des couleurs
$C_Border = "Cyan"
$C_Title = "Magenta"
$C_Label = "White"
$C_Value = "Green"
$C_Dim = "DarkGray"
# Barres de progression
# Barre de progression stockage
if ($disk_free_gb.ToString() -match '^\d+,*\d*$' -and $disk_used_gb.ToString() -match '^\d+,*\d*$') {
$total = [math]::Round($disk_used_gb + $disk_free_gb, 0)
$percent = [math]::Round(($disk_used_gb / $total) * 100)
$barSize = 20
$filled = [math]::Round($percent / (100 / $barSize))
$bar = ("▓" * $filled).PadRight($barSize, "░")
}
else {
$bar = "░░▒▒▓▓████"
$percent = "N/A"
}
# barre de progréssion ready
function FX-ScanBarLight {
$bar = "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"
for ($i = 0; $i -lt $bar.Length; $i++) {
$tmp = $bar.ToCharArray()
$tmp[$i] = "█"
# Retour début de ligne
Write-Host "`r " -NoNewline
# Icône magenta
Write-Host "◣" -NoNewline -ForegroundColor $C_Title
# Texte + barre en bleu
Write-Host " READY_ $($tmp -join '')" -NoNewline -ForegroundColor $C_Border
Start-Sleep -Milliseconds 10
}
}
# Affichage de la bannière
Show-Banner