Created
September 23, 2024 17:01
-
-
Save mushfiqweb/84d2d8b64ae2f9d1cb4e09c408d89a73 to your computer and use it in GitHub Desktop.
My Windows Terminal Setup with PowerShell
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
# Initialize Oh-My-Posh synchronously to ensure it loads before you start using the shell | |
oh-my-posh --init --shell pwsh --config C:/mushfiqwebOhMyPOSH.json | Invoke-Expression | |
# Lazy load modules function | |
function Import-Module-Lazy { | |
param ($ModuleName) | |
if (-not (Get-Module -Name $ModuleName)) { | |
Import-Module $ModuleName | |
} | |
} | |
# Import PSReadLine, posh-git, Terminal-Icons modules lazily (loaded when commands are called) | |
function gs { Import-Module-Lazy posh-git; git status } | |
function ga { Import-Module-Lazy posh-git; git add . } | |
function gfa { Import-Module-Lazy posh-git; git fetch --all } | |
function grman { Import-Module-Lazy posh-git; git rebase -i main } | |
function grmas { Import-Module-Lazy posh-git; git rebase -i master } | |
function grdev { Import-Module-Lazy posh-git; git rebase -i develop } | |
function gprman { Import-Module-Lazy posh-git; git pull origin main; git rebase -i main } | |
function gprmas { Import-Module-Lazy posh-git; git pull origin master; git rebase -i master } | |
function gprdev { Import-Module-Lazy posh-git; git pull origin develop; git rebase -i develop } | |
function gitc { Import-Module-Lazy posh-git; git commit -m @args } | |
function gac { Import-Module-Lazy posh-git; git add .; git commit -m @args } | |
function pushmas { Import-Module-Lazy posh-git; git push origin master } | |
function pushman { Import-Module-Lazy posh-git; git push origin main } | |
function pushdev { Import-Module-Lazy posh-git; git push origin develop } | |
function pullman { Import-Module-Lazy posh-git; git pull origin main } | |
function pullmas { Import-Module-Lazy posh-git; git pull origin main } | |
function pulldev { Import-Module-Lazy posh-git; git pull origin develop } | |
function pull { Import-Module-Lazy posh-git; git pull origin master } | |
function gl { Import-Module-Lazy posh-git; git log } | |
function glo { Import-Module-Lazy posh-git; git log --oneline } | |
function gch { Import-Module-Lazy posh-git; git checkout @args } | |
function gcn { Import-Module-Lazy posh-git; git checkout -b @args } | |
function gman { Import-Module-Lazy posh-git; git checkout main } | |
function gmas { Import-Module-Lazy posh-git; git checkout master } | |
function gdev { Import-Module-Lazy posh-git; git checkout develop } | |
function gb { Import-Module-Lazy posh-git; git branch @args } | |
function gd { Import-Module-Lazy posh-git; git diff } | |
function ns { npm start } | |
function shlo { shopify auth logout } | |
function ex { taskkill /f /im explorer.exe; start explorer.exe } | |
# Import the Chocolatey Profile for tab completion | |
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | |
if (Test-Path($ChocolateyProfile)) { | |
Import-Module "$ChocolateyProfile" | |
} | |
# Set PSReadLine options in a single call to reduce redundancy | |
Set-PSReadLineOption -PredictionSource History -PredictionViewStyle ListView -EditMode Windows -Colors @{ | |
Command = '#8181f7' | |
Number = 'DarkGray' | |
Member = 'White' | |
Operator = '#baf7c9' | |
Type = '#faa2eb' | |
Variable = 'DarkGreen' | |
Parameter = 'DarkGreen' | |
ContinuationPrompt = '#faa2eb' | |
Default = 'White' | |
} | |
# Custom keybindings | |
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | |
Set-PSReadLineKeyHandler -Chord Tab -Function MenuComplete | |
# DiskSpec function (not automatically run, but available when needed) | |
function DiskSpec { | |
Get-WmiObject Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 -and $_.DeviceID -eq 'C:' } | ForEach-Object { | |
$disk = $_ | |
$freeSpace = [math]::Round($disk.FreeSpace / 1GB, 2) | |
Write-Host "$($disk.DeviceID) ${freeSpace}GB" | |
} | |
} | |
# Function to kill process by port | |
function killport([parameter(mandatory)] [string] $uport) { | |
if ($upid = (Get-NetTCPConnection -LocalPort $uport -ErrorAction Ignore).OwningProcess) { | |
kill $upid | |
} | |
} | |
# Import the Microsoft.WinGet.CommandNotFound module | |
Import-Module -Name Microsoft.WinGet.CommandNotFound |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment