Last active
April 11, 2024 19:30
-
-
Save kwsp/2a3310f4b8902dd044d5e115bc221a50 to your computer and use it in GitHub Desktop.
Person PowerShell config to restore some unix sanity. This complements the unix utilities provided by Git for Windows.
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
Set-PSReadlineOption -EditMode Emacs | |
Set-Alias vim nvim | |
Set-Alias python3 python | |
# Some unix shell hacks | |
Function which([string]$Name) { Get-Command $Name } | |
Function open($Name) { start $name } | |
Function l() {ls -Force} | |
# Git shortcuts from zsh git plugin | |
Function gst { git status } | |
Function gba { git branch -a } | |
Function glol { git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' } | |
Function glols { git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat } | |
Function gp { git push } | |
Function gl { git pull } | |
Function Format-FileSize() { | |
Param ([int64]$size) | |
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)} | |
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)} | |
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)} | |
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)} | |
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)} | |
Else {""} | |
} | |
# Emulate `du -sh | sort -rh` on Unix, but format more like `ls -lah` | |
Function dush { | |
Get-ChildItem -Force | | |
Select-Object Name, @{Name="Size";Expression={ | |
if ($_.PSIsContainer) { | |
(Get-ChildItem $_.FullName -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum | |
} else { | |
$_.Length | |
} | |
}}, Mode, LastWriteTime | | |
Sort-Object Size -Descending | | |
ForEach-Object { | |
$size = $_.Size | |
$size = Format-FileSize($_.size) | |
"{0,10} {1,8} {2} {3}" -f $size, $_.Mode, $_.LastWriteTime.ToString("yyyy-MM-dd HH:mm"), $_.Name | |
} | |
} | |
# VCPKG installed with Visual Studio needs a baseline git commit tag in the manifest file. | |
Function vcpkg_baseline { | |
# Create an empty manifest file if doesn't exist | |
if (!(Test-Path vcpkg.json -PathType Leaf) -and !(Test-Path vcpkg-configuration.json -PathType Leaf)) { | |
echo "{}" | Set-Content vcpkg.json -Encoding utf8 | |
} | |
vcpkg x-update-baseline --add-initial-baseline | |
} | |
# conda activate | |
Function ca($name) { conda activate $name } | |
Function time() { | |
$command = $args -join ' ' | |
Measure-Command { Invoke-Expression $command | Out-Default } | |
} | |
# Edit the powershell profile | |
Function ed { vim "$env:USERPROFILE\Documents\WindowsPowerShell\Profile.ps1" } | |
# Launch the Visual Studio 2022 Developer PowerShell | |
Function vs { | |
If (Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1") { | |
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 -HostArch amd64 -SkipAutomaticLocation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment