Created
February 14, 2024 09:29
-
-
Save evdokimovm/338b1615b5d84180c9027c409c6759b2 to your computer and use it in GitHub Desktop.
My PowerShell 7 Microsoft.PowerShell_profile.ps1 profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\amro.omp.json" | Invoke-Expression | |
Import-Module Terminal-Icons | |
Import-Module PSReadLine | |
New-Alias code code-insiders | |
New-Alias curl C:\curl-7.81.0-win64-mingw\bin\curl.exe | |
Remove-Alias md | |
function md { | |
param ( | |
[string]$Path, | |
[switch]$go, | |
[switch]$code | |
) | |
New-Item -Path $Path -ItemType Directory | Out-Null | |
$fullPath = (Resolve-Path $Path).Path | |
if ($go) { | |
cd -Path $fullPath | |
} | |
if ($code) { | |
code $fullPath | |
} | |
} | |
function touch { | |
param( | |
[string]$Path, | |
[switch]$code | |
) | |
New-Item -ItemType File -Path $Path | Out-Null | |
if ($code) { | |
code $Path | |
} | |
} | |
Set-PSReadLineOption -PredictionSource History | |
Set-PSReadLineOption -PredictionViewStyle ListView | |
function Find-Binary($binary) { | |
$location = where.exe $binary 2>$null | |
Write-Output $location | |
} | |
New-Alias wi Find-Binary | |
Function List-Name { | |
Get-ChildItem | Select-Object Name | |
} | |
function Whole-History { | |
cat (Get-PSReadlineOption).HistorySavePath | |
} | |
New-Alias wh Whole-History | |
function ralias { | |
param( | |
[Parameter(Mandatory=$true, Position=0)] | |
[string]$Command | |
) | |
$aliases = Get-Alias -Definition $Command -ErrorAction SilentlyContinue | |
if ($aliases) { | |
Write-Output $aliases | |
} else { | |
Write-Host "No aliases found for the command '$Command'" -ForegroundColor "Red" | |
} | |
} | |
function gfs { | |
Get-ChildItem -Directory | ForEach-Object { | |
$size = Get-ChildItem $_.FullName -Recurse | Measure-Object -Property Length -Sum | |
Write-Host "$($_.Name) - $($("{0:F3}" -f ($size.Sum / 1MB))) MB" | |
} | |
} | |
function Get-Hash { | |
param ( | |
[Parameter(Mandatory=$true, Position=0)] | |
[ValidateScript({Test-Path $_ -PathType Leaf})] | |
[string]$FilePath, | |
[string]$Algorithm = "MD5" | |
) | |
Get-FileHash $FilePath -Algorithm $Algorithm | Select-Object -ExpandProperty Hash | |
} | |
function Rename-FileToHash { | |
param ( | |
[Parameter(Mandatory=$true, Position=0, ValueFromRemainingArguments=$true)] | |
# [ValidateScript({Test-Path $_ -PathType Leaf})] | |
[string[]]$FilePaths, | |
[string]$Algorithm = "MD5" | |
) | |
foreach ($FilePath in $FilePaths) { | |
if (-not (Test-Path $FilePath -PathType Leaf)) { | |
Write-Error "File '$FilePath' does not exist." | |
continue | |
} | |
$md5 = Get-Hash $FilePath -Algorithm $Algorithm | |
$extension = [System.IO.Path]::GetExtension($FilePath) | |
$newFilePath = Join-Path (Split-Path $FilePath) "$md5$extension" | |
Rename-Item $FilePath $newFilePath | |
} | |
} | |
function Rename-AllFilesToHash { | |
param( | |
[string]$Path, | |
[switch]$Recurse, | |
[string]$Algorithm = "MD5" | |
) | |
$files = Get-ChildItem $Path -Recurse:$Recurse | Where-Object {! $_.PSIsContainer} | |
foreach ($file in $files) { | |
Rename-FileToHash -FilePath $file.FullName -Algorithm $Algorithm | |
} | |
} | |
function Search-SubstringInFiles { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true, Position = 0)] | |
[string] $Substring, | |
[Parameter(Mandatory = $false, Position = 1)] | |
[switch] $Recurse, | |
[Parameter(Mandatory = $false, Position = 2)] | |
[string] $DirectoryPath = './*' | |
) | |
$files = Get-ChildItem -Path $DirectoryPath -Include ("*.txt", "*.css", "*.html", "*.js") -Recurse:$Recurse | |
foreach ($file in $files) { | |
$fileContent = Get-Content -Path $file.FullName -Raw | |
if ($fileContent -like "*$Substring*") { | |
Write-Host "Substring found in file: $($file.FullName)" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment