Last active
August 29, 2015 14:00
-
-
Save dux/11080083 to your computer and use it in GitHub Desktop.
grep -r CLI response prettifier and open file inteface # http://i.imgur.com/qpNl0KQ.png
This file contains hidden or 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
#!/usr/bin/ruby | |
find = ARGV.join(' ') | |
unless find =~ /\w/ | |
print "WHAT: Finds text via grep -r, trims long reponses, pretty print and open file interface\n" | |
print "USAGE: ./finds [text to find in realtive path without quotes]\n" | |
print "EXAMPLE: ./finds def avatar\n" | |
print "@dux 2014\n" | |
exit | |
end | |
command = %[grep -r "#{find}" .] | |
data = `#{command}` | |
print " #{command}\n ---\n" | |
@found = [] | |
cnt = 0 | |
for line in data.chomp.split("\n") | |
file, desc = line.split(': ', 2) | |
print "#{(cnt += 1).to_s.rjust(2)}. #{file.ljust(40)} #{desc[0,35]}\n" | |
@found.push file | |
end | |
print "Num to open in browser or ENTER for exit: " | |
num = STDIN.gets.chomp.to_i | |
exit if num == 0 | |
# use any editor you want | |
`vi #{@found[num.to_i-1]}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment