Last active
March 14, 2025 02:19
-
-
Save YuanLiou/20b3229396f8d929ecb3976259888dcd to your computer and use it in GitHub Desktop.
Ray's PowerShell settings 1.0.1
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 | |
oh-my-posh init pwsh --config "~/.config/ohmyposh/omp_theme.toml" | Invoke-Expression | |
# Custom Modules | |
Enable-PoshTooltips | |
Import-Module posh-git | |
Install-Module -Name posh-alias | |
Import-Module Terminal-Icons | |
# Enable Auto complete | |
# Shows navigable menu of all options when hitting Tab | |
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete | |
# Autocompletion for arrow keys | |
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward | |
# Alias | |
Set-Alias yd youtube-dl | |
Set-Alias vim nvim | |
Set-Alias ll ls | |
Set-Alias grep findstr | |
Set-Alias tig 'C:\Users\RayYuan\scoop\shims\tig.exe' | |
Set-Alias less 'C:\Users\RayYuan\scoop\shims\less.exe' | |
Set-Alias cb swagit | |
# Set-Alias l Get-ChildItem | |
Add-Alias l 'lsd -hA --group-dirs first' | |
Add-Alias ex 'eza --icons -a --group-directories-first' | |
# Utilities | |
Set-PSReadLineOption -PredictionSource History | |
function which($command) { | |
Get-Command -Name $command -ErrorAction SilentlyContinue | | |
Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue | |
} | |
# Useful shortcuts for traversing directories | |
function cd... { cd ..\.. } | |
function cd.... { cd ..\..\.. } | |
# Compute file hashes - useful for checking successful downloads | |
function md5 { Get-FileHash -Algorithm MD5 $args } | |
function sha1 { Get-FileHash -Algorithm SHA1 $args } | |
function sha256 { Get-FileHash -Algorithm SHA256 $args } | |
# Quick shortcut to start notepad | |
function n { notepad $args } | |
# Functions | |
# OptimizeVideo: optimizeVideo -inputFile "path/to/video" | |
function optimizeVideo { | |
param ( | |
[string]$inputFile | |
) | |
$outputFile = ($inputFile + ".mp4") | |
ffmpeg -i $inputFile -vcodec h264 -acodec mp2 $outputFile | |
} | |
# Video2gif: video2gif -inputFile "path/to/video.mp4" -scale 320 -fps 10 | |
function video2gif { | |
param ( | |
[string]$inputFile, | |
[int]$scale = 320, | |
[int]$fps = 10 | |
) | |
$paletteFile = "$inputFile.png" | |
ffmpeg -y -i $inputFile -vf "fps=$fps,scale=${scale}:-1:flags=lanczos,palettegen" $paletteFile | |
ffmpeg -i $inputFile -i $paletteFile -filter_complex "fps=$fps,scale=${scale}:-1:flags=lanczos[x];[x][1:v]paletteuse" ($inputFile + ".gif") | |
Remove-Item $paletteFile | |
} | |
# Adb device chooser, install fzf first | |
function Invoke-Adb { | |
param( | |
[Parameter(ValueFromRemainingArguments=$true)] | |
$args | |
) | |
# Execute the actual command | |
$totalLines = (& adb devices).Count | |
$totalDeviceConnected = $totalLines - 2 | |
if (-not ($args -match "-s") -and $totalDeviceConnected -gt 1) { | |
# Get the list of connected devices | |
$devices = (& adb devices | Select-String "device$" | ForEach-Object { $_.ToString().Split()[0] }) | |
$devicesText = "" | |
# Loop through each device | |
foreach ($device in $devices) { | |
# Get the market name property | |
$market_name = & adb -s $device shell getprop ro.product.vendor.marketname | |
# Check if market name is empty | |
if ([string]::IsNullOrWhiteSpace($market_name)) { | |
# Get the model property if market name is empty | |
$market_name = & adb -s $device shell getprop ro.product.model | |
} | |
$devicesText += "$device - $market_name`n" | |
} | |
# Prompt user to select a device | |
$selection = $devicesText.Trim() | fzf | |
$deviceId = $selection.Split(' - ')[0] | |
Write-Host "📱 Device Selected: " -NoNewline | |
Write-Host $selection -ForegroundColor Green | |
# Execute adb command on the selected device | |
& adb -s $deviceId $args | |
} | |
else { | |
# Execute the command without device selection | |
& adb $args | |
} | |
} | |
# Set an alias for the Invoke-Adb | |
Set-Alias -Name fadb -Value Invoke-Adb | |
# Zoxide | |
Invoke-Expression (& { (zoxide init powershell | Out-String) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment