Powershell et $PROFILE sur Windows
Découvrez l'alternative du .bashrc de Linux, pour Windows cette fois-ci afin de vous faciliter la vie.

Introduction
Le $PROFILE c'est le même type de fichier que .zshrc ou .bashrc
, il est fait pour pouvoir configurer un profil de terminal qui se chargera sur chaque nouvelle session. On va faire la même chose ici que dans l'article précédent qui lui était pour Linux.
Config Sympa du Fichier
Ouvrez-le
notepad $PROFILE
Si il existe pas :
New-Item -ItemType File -Path $PROFILE -Force
Puis :
# =====================================================
# PowerShell Profile — Edition Feignant Pro 3000™
# =====================================================
Set-Alias ll Get-ChildItem
Set-Alias la "Get-ChildItem -Force"
Set-Alias grep Select-String
Set-Alias cat Get-Content
Set-Alias .. Set-Location ..
Set-Alias ... { Set-Location ../.. }
Set-Alias update Update-Module
Set-Alias hist Get-History
Set-Alias clr Clear-Host
function reload {
"🔄 Reloading profile..." | Write-Host -ForegroundColor Cyan
. $PROFILE
}
function please {
Start-Process powershell -Verb RunAs -ArgumentList $args
}
function fuck {
if ($LASTEXITCODE -ne 0 -and $history.Count -gt 0) {
Write-Host " Retrying: $($history[-1].CommandLine)" -ForegroundColor Red
Invoke-Expression $history[-1].CommandLine
} else {
Write-Host " Rien à corriger" -ForegroundColor Green
}
}
function timer {
param([ScriptBlock]$code)
$sw = [System.Diagnostics.Stopwatch]::StartNew()
& $code
$sw.Stop()
Write-Host " Temps écoulé: $($sw.Elapsed.TotalSeconds) sec" -ForegroundColor Yellow
}
function cleanup {
Write-Host "Suppression des fichiers inutiles..." -ForegroundColor Cyan
Get-ChildItem -Recurse -Include *.pyc, .DS_Store, Thumbs.db -ErrorAction SilentlyContinue | Remove-Item -Force
Write-Host " Nettoyage terminé."
}
function mkcd {
param([string]$name)
New-Item -ItemType Directory -Path $name -Force | Out-Null
Set-Location -Path $name
}
function go {
param([string]$name)
$dir = Get-ChildItem -Directory -Recurse | Where-Object { $_.Name -like "*$name*" } | Select-Object -First 1
if ($dir) {
Set-Location $dir.FullName
} else {
Write-Host " Aucun dossier trouvé contenant '$name'" -ForegroundColor Red
}
}
function extract {
param([string]$archive)
if (-not (Test-Path $archive)) {
Write-Host " Fichier introuvable: $archive" -ForegroundColor Red
return
}
switch -Wildcard ($archive) {
"*.zip" { Expand-Archive -Path $archive -DestinationPath . }
"*.tar.gz" { tar -xzf $archive }
"*.tar.bz2" { tar -xjf $archive }
"*.rar" { & "C:\Program Files\WinRAR\UnRAR.exe" x $archive . }
default { Write-Host " Format non reconnu." -ForegroundColor DarkYellow }
}
}
# Prompt stylé
function global:prompt {
$user = [System.Environment]::UserName
$path = $(Get-Location)
$git = $(if (Test-Path .git) { "" + (git branch --show-current 2>$null) })
$ok = if ($?) { "✔" } else { "" }
"$user $ok [$path] $git> "
}
Write-Host " PowerShell prêt." -ForegroundColor Green
Write-Host " $(Get-Date -Format 'dddd dd MMM yyyy HH:mm')" -ForegroundColor DarkGray
Write-Host ""
function edit-profile {
code $PROFILE # utilise VS Code
}
Ensuite tu charges les modifications avec reload
puis tout est prêt.
Commentaires (0)
Aucun commentaire pour le moment. Soyez le premier à commenter !
Articles précédents

Simplifiez vous la vie sur Linux : Skel & .Bashrc
Apprendre à utiliser le /etc/skel et le .bashrc sur linux pour simplifier son environnement de travail Linux.

Le SEO BlackHat c'est quoi ?
Comprendre le SEO c'est bien, comprendre toutes les variantes c'est mieux, notamment celle du BlackHat ou SEO BH

Elevation de Privilège sur Linux
Découvrez comment les hackers élèvent leur privilèges sur les systèmes Linux pour devenir root.
Articles suivants

Faites des campagnes SMS avec Twilio
Utilisez Twilio pour automatiser l'envoi de vos SMS avec une facilité déconcertante.

Automatisez l'Envoi de vos E-Mails Quasi Gratuitement
Automatiser l'envoi des email via Node.js avec le module nodemailer. Ca va demander quelques connaissances de bases mais rien d'effrayant.