Skip to content

Instantly share code, notes, and snippets.

@shahriar0247
Created August 7, 2025 14:04
Show Gist options
  • Select an option

  • Save shahriar0247/5e0fb9de91ccf58e8a88c8eb8cd37587 to your computer and use it in GitHub Desktop.

Select an option

Save shahriar0247/5e0fb9de91ccf58e8a88c8eb8cd37587 to your computer and use it in GitHub Desktop.
Highly Configured and Customized PowerShell Profile
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\peru.omp.json" | Invoke-Expression
Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineOption -BellStyle None
Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -Colors @{
"Command" = "#a6e22e"
"Parameter" = "#66d9ef"
"String" = "#e6db74"
"InlinePrediction" = "#75715e"
}
# 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"
}
# Utilities
function which ($command) {
Get-Command -Name $command -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
function Invoke-RegexHistorySearch {
[CmdletBinding()]
param()
$input = Read-Host "Enter regex for backward history search"
if ($input) {
# Search backward for the first command matching the regex pattern
$history = Get-History | Sort-Object Id -Descending
$match = $history | Where-Object { $_.CommandLine -match $input } | Select-Object -First 1
if ($match) {
[Console]::WriteLine("Matched command: $($match.CommandLine)")
# Put matched command on prompt
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($match.CommandLine)
}
else {
Write-Host "No match found"
}
}
}
# Set-PSReadLineKeyHandler -Key Ctrl+r -ScriptBlock { Invoke-RegexHistorySearch }
function Invoke-FzfHistorySearch {
# Get history commands, pipe to fzf for fuzzy interactive search
$history = Get-History | Select-Object -ExpandProperty CommandLine
$selected = $history | fzf.exe --tac --no-sort --reverse
if ($selected) {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($selected)
}
}
Set-PSReadLineKeyHandler -Key Ctrl+r -ScriptBlock { Invoke-FzfHistorySearch }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment