Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created November 2, 2022 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/f665fccd1993710ba56958fd7a91b06e to your computer and use it in GitHub Desktop.
Save JoshCheek/f665fccd1993710ba56958fd7a91b06e to your computer and use it in GitHub Desktop.
Example of how you could create an interactive grep interface without a GUI
ruby -r io/console -e '
h, w = $stdout.winsize
options = ""
loop do
command = "grep -r #{options} ." # DO NOT INTERPOLATE INTO BASH SCRIPTS IN PROD!
results = `echo -n | #{command} | head -n #{h-3}`
print "\e[H\e[J\e[2B#{results}\e[H> #{command}\e[K\e[2D"
c = $stdin.getch
break puts "\e[H\e[J#{command}" if c == ?\C-c || c == "\r"
options += c # the basic-est of input processing
end'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment