Skip to content

Instantly share code, notes, and snippets.

@hopsoft
Last active March 29, 2024 18:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hopsoft/d8ec55a4dea4e2be926460564a16eaed to your computer and use it in GitHub Desktop.
Save hopsoft/d8ec55a4dea4e2be926460564a16eaed to your computer and use it in GitHub Desktop.
stdin → fzf with preview

stdin → fzf with preview

Dependencies

  • ruby
  • ripgrep
  • fzf

Setup

  1. Add the script below to your PATH
  2. Pipe anything from stdin to infzf
  3. Enjoy!

Usage

ps aux | infzf

CleanShot 2024-03-29 at 03 37 21@2x

#!/usr/bin/env ruby
require "tempfile"
Tempfile.create do |file|
file.write $stdin.read
file.flush
preview = "rg --pretty --fixed-strings --before-context=3 --after-context=6 {} #{file.path}"
`fzf --ansi --preview=\"#{preview}\" --preview-window=wrap,60% < #{file.path}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment