### Prompt Invoke-Expression (&starship init powershell) ### Aliases Set-Alias -Name "c" -Value "code" Set-Alias -Name "e" -Value "explorer" Set-Alias -Name "~" -Value "Enter-Home" Set-Alias -Name "which" -Value "Find-Command" Set-Alias -Name "scpy" -Value "Start-Scrcpy" ### Modules if ($host.Name -eq 'ConsoleHost') { Import-Module PSReadLine } # PSReadLine keybindings Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # PSReadLine options Set-PSReadLineOption -BellStyle None Set-PSReadLineOption -EditMode Windows Set-PSReadLineOption -HistoryNoDuplicates Set-PSReadLineOption -PredictionSource History # Set-PSReadLineOption -PredictionViewStyle ListView Set-PSReadLineOption -HistorySearchCursorMovesToEnd ### Custom Functions function Enter-Home { Set-Location ~ } function Find-Command { Param( [Parameter(Position = 0, Mandatory)][string[]]$Names, [Parameter()][Switch][Alias('r')]$Raw ) foreach ($Name in $Names) { if (!$Raw) { Write-Host "" } $Commands = Get-Command $Name -all -ErrorAction:Ignore if (!$Commands) { $Commands = [psobject]@{ Name = $Name; } } foreach ($Command in $Commands) { if ($Raw) { if ($Command.Path -or $Command.Source) { Write-Output ($Command.Path ?? $Command.Source) } elseif ($Command.ResolvedCommand) { Write-Output $Command.ResolvedCommand } else { Write-Output "(???)" } } else { if ($Command.CommandType) { Write-Host "[$($Command.CommandType)] " -NoNewline -ForegroundColor Green } else { Write-Host "[Missing] " -NoNewline -ForegroundColor Red } Write-Host "$($Command.Name ?? $Name) " -NoNewline if ($Command.Path -or $Command.Source) { Write-Host "($($Command.Path ? $Command.Path : $Command.Source))" -ForegroundColor DarkGray } elseif ($Command.ResolvedCommand) { Write-Host "($($Command.ResolvedCommand))" -ForegroundColor DarkGray } else { Write-Host "(???)" -ForegroundColor DarkGray } } } } } function Start-Scrcpy { Param( [Parameter(Position = 0)][string][Alias('s')]$Serial, [Parameter()][Switch][Alias('l')]$ListDevices, [Parameter()][Switch][Alias('r')]$Record, [Parameter()][Switch][Alias('n')]$NoControl, [Parameter()][Switch][Alias('t')]$AlwaysOnTop ) if ($ListDevices) { adb devices -l return } [string[]]$Arguments = "--lock-video-orientation" if ($Serial) { $Arguments += "--serial=$($Serial)" } if ($Record) { $Date = Get-Date -Format "dd-MM-yyyy_HH-mm-ss-fff" if ($Date) { $Arguments += "--record=$($env:USERPROFILE)\Videos\Captures\scrcpy-recording_$($Date).mkv" } else { Write-Host "Failed to get date" -ForegroundColor Red } } if ($NoControl) { $Arguments += "--no-control" } else { $Arguments += "--turn-screen-off", "--stay-awake", "--show-touches" } if ($AlwaysOnTop) { $Arguments += "--always-on-top" } Start-Process -FilePath "scrcpy" -ArgumentList $Arguments -ErrorVariable $ScrcpyError if ($ScrcpyError) { Write-Host "Failed to start scrcpy" -ForegroundColor Red } }