Created
July 13, 2024 16:13
-
-
Save mushfiqweb/a3aa67480bb1566b793660fec1058a43 to your computer and use it in GitHub Desktop.
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 --shell pwsh --config C:/mushfiqwebOhMyPOSH.json | Invoke-Expression | |
function Import-Module-With-Measure { | |
param ($ModuleName) | |
$import = Measure-Command { | |
Import-Module $ModuleName | |
} | |
Write-Host "$ModuleName took $($import.TotalMilliseconds) ms" | |
} | |
#Invoke-Expression (&starship init powershell) | |
#Import-Module-With-Measure PSReadLine | |
#Import-Module-With-Measure posh-git | |
#Import-Module-With-Measure Terminal-Icons | |
Import-Module PSReadLine | |
Import-Module posh-git | |
Import-Module Terminal-Icons | |
Set-PSReadLineOption -PredictionSource History | |
Set-PSReadLineOption -PredictionViewStyle ListView | |
Set-PSReadLineOption -EditMode Windows | |
$PSReadLineOptions = @{ | |
EditMode = "Emacs" | |
HistoryNoDuplicates = $true | |
HistorySearchCursorMovesToEnd = $true | |
Colors = @{ | |
"Command" = "#8181f7" | |
} | |
} | |
Set-PSReadLineOption @PSReadLineOptions | |
Set-PSReadLineOption -Colors @{ | |
Command = 'Magenta' | |
Number = 'DarkGray' | |
Member = 'White' | |
Operator = '#baf7c9' | |
Type = '#faa2eb' | |
Variable = 'DarkGreen' | |
Parameter = 'DarkGreen' | |
ContinuationPrompt = '#faa2eb' | |
Default = 'White' | |
} | |
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | |
Set-PSReadlineKeyHandler -Chord Tab -Function MenuComplete | |
# Import the Chocolatey Profile that contains the necessary code to enable | |
# tab-completions to function for `choco`. | |
# Be aware that if you are missing these lines from your profile, tab completion | |
# for `choco` will not function. | |
# See https://ch0.co/tab-completion for details. | |
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | |
if (Test-Path($ChocolateyProfile)) { | |
Import-Module "$ChocolateyProfile" | |
} | |
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-Output "$($disk.DeviceID) ${freeSpace}GB" | |
} | |
} | |
DiskSpec | |
function killport([parameter(mandatory)] [string] $uport){ | |
if($upid = (Get-NetTCPConnection -LocalPort $uport -ErrorAction Ignore).OwningProcess){kill $upid} | |
} | |
function gs{git status} | |
function ga{git add .} | |
function gfa{git fetch --all} | |
function grman{git rebase -i main} | |
function grmas{git rebase -i master} | |
function grdev{git rebase -i develop} | |
function gprman{git pull origin main;git rebase -i main;} | |
function gprmas{git pull origin master;git rebase -i master;} | |
function gprdev{git pull origin develop;git rebase -i develop;} | |
function gitc{ git commit -m @args } | |
function gac{git add .;git commit -m @args} | |
function pushmas{git push origin master} | |
function pushman{git push origin main} | |
function pushdev{git push origin develop} | |
function pullman{git pull origin main} | |
function pullmas{git pull origin main} | |
function pulldev{git pull origin develop} | |
function pull{git pull origin master} | |
function gl{git log} | |
function glo{git log --oneline} | |
function gch{git checkout @args} | |
function gcn{git checkout -b @args} | |
function gman{git checkout main} | |
function gmas{git checkout master} | |
function gdev{git checkout develop} | |
function gb{git branch @args} | |
function gs{git status} | |
function gd{git diff} | |
function ns{npm start} | |
#function shkonod{shopify theme dev --store=https://jp-halfsaints-dev.myshopify.com} | |
#function shwak{shopify theme dev --store=https://waksnap.myshopify.com} | |
#function shgo{shopify theme dev --store=https://wego-gocart-online.myshopify.com} | |
function shlo{shopify auth logout} | |
function ex{taskkill /f /im explorer.exe; start explorer.exe;} | |
function tman{ | |
# Add the required assembly for sending keystrokes | |
Add-Type -AssemblyName System.Windows.Forms | |
# Define the registry path | |
$registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager" | |
# Check if the registry path exists | |
if (-not (Test-Path $registryPath)) { | |
# Create the registry key if it doesn't exist | |
New-Item -Path $registryPath -Force | Out-Null | |
} | |
# Set the registry key to open Task Manager in the Performance tab | |
Set-ItemProperty -Path $registryPath -Name "StartUpTab" -Value 1 | |
# Start Task Manager | |
Start-Process "$env:WinDir\System32\Taskmgr.exe" | |
} | |
function SYSMON { | |
while ($true) { | |
$memory = Get-WmiObject Win32_OperatingSystem | |
$freeMemory = [math]::Round($memory.FreePhysicalMemory / 1MB, 2) | |
$totalMemory = [math]::Round($memory.TotalVisibleMemorySize / 1MB, 2) | |
$usedMemory = $totalMemory - $freeMemory | |
$usedMemoryPercentage = [math]::Round(($usedMemory / $totalMemory) * 100, 2) | |
Clear-Host | |
Write-Output "Total Memory: $totalMemory MB" | |
Write-Output "Used Memory: $usedMemory MB ($usedMemoryPercentage%)" | |
Write-Output "Free Memory: $freeMemory MB" | |
Start-Sleep -Seconds 1 | |
} | |
} | |
function CPU { | |
$cpuLoad = Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select-Object -ExpandProperty Average | |
Write-Output "CPU Load: $cpuLoad%" | |
Start-Sleep -Seconds 1 | |
} | |
function Get-NetworkUsage { | |
try { | |
$networkCounters = "\\Network Interface(*)\\Bytes Received/sec", "\\Network Interface(*)\\Bytes Sent/sec" | |
$counterList = Get-Counter -ListSet 'Network Interface' | |
if ($counterList.Paths -contains $networkCounters[0] -and $counterList.Paths -contains $networkCounters[1]) { | |
$samples = Get-Counter -Counter $networkCounters -SampleInterval 1 -MaxSamples 1 | |
if ($samples -and $samples.CounterSamples.Count -gt 1) { | |
$download = $samples.CounterSamples[0].CookedValue | |
$upload = $samples.CounterSamples[1].CookedValue | |
# Convert bytes to kilobytes | |
$downloadKbps = [math]::Round($download / 1KB, 2) | |
$uploadKbps = [math]::Round($upload / 1KB, 2) | |
Write-Output "Download Speed: $downloadKbps KB/s" | |
Write-Output "Upload Speed: $uploadKbps KB/s" | |
} else { | |
Write-Output "No data returned from performance counters." | |
} | |
} else { | |
Write-Output "The specified network counters do not exist on this system." | |
} | |
} catch { | |
Write-Error "An error occurred: $_" | |
} | |
} | |
function Monitor-NetworkUsage { | |
while ($true) { | |
Get-NetworkUsage | |
Start-Sleep -Seconds 5 | |
} | |
} | |
function Monitor-NetworkTraffic { | |
param ( | |
[string]$AdapterName | |
) | |
while ($true) { | |
$stats = Get-NetAdapterStatistics -Name $AdapterName | |
$receivedBytes = $stats.ReceivedBytes | |
$sentBytes = $stats.SentBytes | |
# Convert bytes to megabytes | |
$receivedMBps = [math]::Round($receivedBytes / 1MB, 2) | |
$sentMBps = [math]::Round($sentBytes / 1MB, 2) | |
Clear-Host | |
Write-Output "Download Speed: $receivedMBps MB/s" | |
Write-Output "Upload Speed: $sentMBps MB/s" | |
Start-Sleep -Seconds 5 | |
} | |
} | |
function DiskSpec2 { | |
Get-WmiObject Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 -and $_.DeviceID -eq 'C:' } | ForEach-Object { | |
$disk = $_ | |
$freeSpace = [math]::Round($disk.FreeSpace / 1GB, 2) | |
Write-Output "$($disk.DeviceID) ${freeSpace}GB" | |
} | |
} | |
function Start-WslTabs { | |
# Open Windows Terminal | |
#Start-Process wt | |
# Wait for Windows Terminal to start | |
Start-Sleep -Seconds 2 | |
# Run WSL Ubuntu in the first tab | |
wsl -d Ubuntu -- bash -c " DXP code . && echo 'Hello from the first tab!'" | |
# Open a new tab | |
wsl -d Ubuntu -- bash -c "CMS code . && echo 'Hello from the second tab!'" | |
} | |
# To use the function, provide the name of your network adapter: | |
# Monitor-NetworkTraffic -AdapterName "Wi-Fi" | |
function Push-GitOrigin { | |
param ( | |
[string]$BranchName | |
) | |
git push origin $BranchName | |
} | |
Set-Alias -Name gpo -Value Push-GitOrigin | |
function Pull-GitOrigin { | |
param ( | |
[string]$BranchName | |
) | |
git pull origin $BranchName | |
} | |
Set-Alias -Name gpull -Value Pull-GitOrigin | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment