Created
November 2, 2022 05:50
-
-
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
This file contains 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
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