Created
November 16, 2025 13:23
-
-
Save somedeveloper00/3b8b80129be78282aee6eebd0fafefdd to your computer and use it in GitHub Desktop.
A pwsh profile with handy shortcuts
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
| # Check if PSReadLine is installed and install it if necessary | |
| if (-not (Get-Module -ListAvailable -Name PSReadLine)) { | |
| $install = Read-Host "PSReadLine module is not installed. Do you want to install it? (Y/N)" | |
| if ($install -eq "Y" -or $install -eq "y") { | |
| Install-Module -Name PSReadLine -Force -SkipPublisherCheck -Scope CurrentUser | |
| Write-Host "installed PSReadLine module automatically 👍" | |
| } | |
| else { | |
| return | |
| } | |
| } | |
| function Invoke-Git-Commit { | |
| $msg = Read-Host "commit message" | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git commit -m `"" + $msg + "`"") | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Status { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git status") | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Log { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git log -n 20 --oneline --graph --reflog --all") | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Checkout { | |
| $hash = Read-Host "commit hash or branch name" | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git checkout " + $hash) | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Restore { | |
| $restore = Read-Host "what to restore" | |
| $staged = Read-Host "revert staged[Y/n(default)]" | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| if ($staged -eq "Y" -or $staged -eq "y") { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git restore --staged " + $restore) | |
| } | |
| else { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git restore " + $restore) | |
| } | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Add { | |
| $all = Read-Host "add all? [Y/n(default)]" | |
| if ($all -eq "y" -or $all -eq "Y") { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git add *") | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| else { | |
| $args = Read-Host "what to add" | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git add " + $args) | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| } | |
| function Invoke-Git-Clean { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git clean -df") | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Push { | |
| $prompt = Read-Host "use force? [Y/n(default)]" | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| if ($prompt -eq "Y" -or $prompt -eq "y") { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git push --force") | |
| } | |
| else { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git push") | |
| } | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Pull { | |
| $prompt = Read-Host "use force? [Y/n(default)]" | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| if ($prompt -eq "Y" -or $prompt -eq "y") { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git pull --force") | |
| } | |
| else { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git pull") | |
| } | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Diff { | |
| $prompt = Read-Host "additional arguments" | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git diff " + $prompt) | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Invoke-Git-Fetch { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("git fetch --all --tags") | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| function Get-Spotify-Music-Name { | |
| $clip = Get-Clipboard | |
| # Iterate all processes containing "spotify" in the executable path | |
| Get-Process | ForEach-Object { | |
| try { | |
| $exePath = $_.Path | |
| if ($exePath -and $exePath -like "*spotify*") { | |
| $hwnd = $_.MainWindowHandle | |
| if ($hwnd -ne 0 -and [Win32]::IsWindowVisible($hwnd)) { | |
| $length = [Win32]::GetWindowTextLength($hwnd) + 1 | |
| $sb = New-Object System.Text.StringBuilder $length | |
| [Win32]::GetWindowText($hwnd, $sb, $sb.Capacity) | Out-Null | |
| $windowTitle = $sb.ToString() | |
| if ($windowTitle -notlike "*Spotify*") { | |
| $clip = $windowTitle | |
| return $clip | |
| } | |
| } | |
| } | |
| } | |
| catch { | |
| # Ignore processes without a Path property | |
| } | |
| } | |
| return $clip | |
| } | |
| function Invoke-Download-Spotify-Music { | |
| $music = Get-Spotify-Music-Name | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert("cd ~/music; spotdl --dont-filter-results `"" + $music + "`"") | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } | |
| # Spotify Downloader | |
| Add-Type @" | |
| using System; | |
| using System.Text; | |
| using System.Runtime.InteropServices; | |
| public class Win32 { | |
| [DllImport("user32.dll")] | |
| [return: MarshalAs(UnmanagedType.Bool)] | |
| public static extern bool IsWindowVisible(IntPtr hWnd); | |
| [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] | |
| public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); | |
| [DllImport("user32.dll", SetLastError = true)] | |
| public static extern int GetWindowTextLength(IntPtr hWnd); | |
| } | |
| "@ | |
| Set-PSReadLineKeyHandler -Chord Alt+p -ScriptBlock { Invoke-Git-Push } | |
| Set-PSReadLineKeyHandler -Chord Alt+d -ScriptBlock { Invoke-Git-Diff } | |
| Set-PSReadLineKeyHandler -Chord Alt+a -ScriptBlock { Invoke-Git-Add } | |
| Set-PSReadLineKeyHandler -Chord Alt+Ctrl+p -ScriptBlock { Invoke-Git-Pull } | |
| Set-PSReadLineKeyHandler -Chord Alt+s -ScriptBlock { Invoke-Git-Status } | |
| Set-PSReadLineKeyHandler -Chord Alt+l -ScriptBlock { Invoke-Git-Log } | |
| Set-PSReadLineKeyHandler -Chord Alt+c -ScriptBlock { Invoke-Git-Commit } | |
| Set-PSReadLineKeyHandler -Chord Alt+Ctrl+c -ScriptBlock { Invoke-Git-Checkout } | |
| Set-PSReadLineKeyHandler -Chord Alt+r -ScriptBlock { Invoke-Git-Restore } | |
| Set-PSReadLineKeyHandler -Chord Alt+Ctrl+r -ScriptBlock { Invoke-Git-Clean } | |
| Set-PSReadLineKeyHandler -Chord Alt+f -ScriptBlock { Invoke-Git-Fetch } | |
| Set-PSReadLineKeyHandler -Chord Alt+Ctrl+s -ScriptBlock { Invoke-Download-Spotify-Music } | |
| Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { | |
| param($wordToComplete, $commandAst, $cursorPosition) | |
| [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new() | |
| $Local:word = $wordToComplete.Replace('"', '""') | |
| $Local:ast = $commandAst.ToString().Replace('"', '""') | |
| winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object { | |
| [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment