Created
February 11, 2024 12:12
-
-
Save aloni636/f5dc5f962626cbe94a29f1cd4562e0ab to your computer and use it in GitHub Desktop.
Windows PS1 Profile
This file contains 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
# file location: $HOME\Documents\PowerShell\Profile.ps1 | |
# ref: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4#profile-types-and-locations | |
# aliases | |
New-Alias -Name Unzip -Value Expand-Archive | |
New-Alias -Name Which -Value Get-Command | |
function Get-Size { | |
param ( | |
[Parameter(Position = 0, Mandatory = $true)] | |
[string]$Path | |
) | |
"{0:N2} GB" -f ((Get-ChildItem $Path -Recurse -File | Measure-Object -property length -sum).sum / 1Gb) | |
} | |
New-Alias -name Du -value Get-Size | |
function .. { | |
Set-Location -Path .. | |
} | |
# does not work as all params should be passed to Get-ChildItem | |
# Remove-Item -Path Alias:ls # function definitions don't override aliases when conflicting | |
# function ls { | |
# Get-ChildItem -Name $args | |
# } | |
# function ll { | |
# Get-ChildItem | |
# } | |
function Activate-Venv { | |
param ( | |
[Parameter(Position = 0, Mandatory = $true)] | |
[string]$VenvPath = ("$(Get-Location)\venv") | |
) | |
. "$VenvPath\Scripts\Activate.ps1" | |
} | |
New-Alias -name Venv -value Activate-Venv | |
function Get-FileSystemTree { | |
param( | |
[Parameter(Position = 0, Mandatory = $false)] | |
[string]$Path = (Get-Location), | |
[Parameter(Position = 1, Mandatory = $false)] | |
[int]$IndentLevel = 0 | |
) | |
$Indent = ' ' * $IndentLevel | |
$items = Get-ChildItem -Directory -Path $Path | Where-Object { $_.Name -ne ".git" } | |
foreach ($item in $items) { | |
Write-Output "$Indent$item" | |
Get-FileSystemTree -Path $item.FullName -IndentLevel ($IndentLevel + 4) | |
} | |
} | |
New-Alias -name Tree -value Get-FileSystemTree | |
function New-Link($target, $name) { | |
New-Item -ItemType Junction -Path $name -Target $target | |
} | |
New-Alias -Name ln -Value New-Link | |
# config | |
# Import-Module posh-git | |
Invoke-Expression -Command $(gh completion -s powershell | Out-String) | |
# Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete | |
Set-PSReadLineKeyHandler -Chord "Ctrl-w" -Function BackwardKillWord |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment