Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created April 25, 2011 08:02
Show Gist options
  • Save wjlafrance/940265 to your computer and use it in GitHub Desktop.
Save wjlafrance/940265 to your computer and use it in GitHub Desktop.
tokenls
#! /usr/bin/ruby
#
# tokenls
# william lafrance
#
# i got tired of forgetting to do my todos
# you can list off a bunch of files to check
#
# to test for custom tokens:
# tokenls --tokens=these,are,a,list,of,tokens file1 file2 file3
#
$tokens = [/todo/, /to do/, /reminder/, /debug/, /dbg/];
def processFile(arg)
fileLine = 1
file = File.new(arg, "r")
while (line = file.gets)
$tokens.each do | token |
if line.downcase =~ token then
puts "#{arg}:#{fileLine}: #{line}"
end
end
fileLine = fileLine + 1
end
end
if ARGV.count == 0 then
puts "tokenls doesn't do much on its own";
end
if ARGV.count == 1 and ARGV[0] == "--present?" then
puts "yeah im here"
exit!
end
# let's do actual work now
files = ARGV
if ARGV.count >= 1 and ARGV[0] =~ /--tokens=/ then
newTokens = ARGV[0].slice(9, ARGV[0].length)
$tokens = [];
newTokens.split(",").each do | newToken |
$tokens = $tokens + [Regexp.new(newToken.downcase)]
end
files = files - [ARGV[0]]
end
files.each do | file |
processFile file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment