rschmitt/heatseeker

wiki à la fzf-wiki?

FrancescElies opened this issue · 0 comments

Hi,

would you be interested in writing a wiki with examples that one could copy paste into it's profile? Something like Examples · junegunn/fzf Wiki

At the moment I slightly modified your example from readme and shamlessly took some bits from kelleyma49/PSFzf: A PowerShell wrapper around the fuzzy finder fzf

This way everyone could improve this snippets and benefit from other people's improvements.

examples (click me)

$ps = $null
try {
    # On Windows 10, PSReadLine ships with PowerShell
    $ps = [Microsoft.PowerShell.PSConsoleReadline]
} catch [Exception] {
    # Otherwise, it can be installed from the PowerShell Gallery:
    # https://github.com/lzybkr/PSReadLine#installation
    Import-Module PSReadLine
    $ps = [PSConsoleUtilities.PSConsoleReadLine]
}

# cargo install fd heatseeker huniq
write-host "ctrl+t -> fuzzy select file respecting gitignore"
Set-PSReadlineKeyHandler `
  -Chord 'Ctrl+t' `
  -BriefDescription "InsertHeatseekerPathInCommandLine" `
  -LongDescription "Run Heatseeker in the PWD, appending any selected paths to the current command (respectig gitignore)" `
  -ScriptBlock {
      $choices = $(fd -H | hs)
      $ps::Insert($choices -join " ")
  }
write-host "ctrl+t -> fuzzy select any file"
Set-PSReadlineKeyHandler `
  -Chord 'Ctrl+shift+t' `
  -BriefDescription "InsertHeatseekerPathInCommandLine" `
  -LongDescription "Run Heatseeker in the PWD, appending any selected paths to the current command without respecting '.gitignore', '.ignore', '.fdignore'" `
  -ScriptBlock {
      $choices = $(fd -HI | hs)
      $ps::Insert($choices -join " ")
  }

write-host "ctrl+k -> fuzzy kill process"
Set-PSReadlineKeyHandler `
  -Chord 'Ctrl+k -> fuzzy kill process' `
  -BriefDescription "InsertHeatseekerPathInCommandLine" `
  -LongDescription "Fuzzy kill process" `
  -ScriptBlock {
      $result = Get-Process | Where-Object { ![string]::IsNullOrEmpty($_.ProcessName) } | ForEach-Object { "{0,-8} {1}" -f $_.Id,$_.ProcessName } | hs
      $id = $result -replace "([0-9]+)(.*)",'$1'
      Stop-Process $id -Verbose
  }


write-host "ctrl+r -> fuzzy reverse history"
Set-PSReadlineKeyHandler `
  -Chord 'Ctrl+shift+r' `
  -BriefDescription "InsertHeatseekerPathInCommandLine" `
  -LongDescription "Run Heatseeker on pwershell History" `
  -ScriptBlock {
      $choices = $(Get-Content (Get-PSReadLineOption).HistorySavePath | huniq | hs)
      $ps::Insert($choices -join " ")
  }