Skip to content

Instantly share code, notes, and snippets.

@dux
Last active August 29, 2015 14:00
Show Gist options
  • Save dux/11080083 to your computer and use it in GitHub Desktop.
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
#!/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