added commit,diff,xgrep

This commit is contained in:
rkiel
2015-05-31 16:44:56 -04:00
parent 94fb96ad2d
commit ce7f66e2fe
3 changed files with 73 additions and 0 deletions

9
bin/commit Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env ruby
raise "USAGE: commit [word....]" unless ARGV.size > 0
comment = ARGV.reject { |x| x == '-m' }.join(' ')
command = "git commit -m \"#{comment}\""
exec command

7
bin/diff Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
args = ARGV.join(' ')
command = "git diff -w #{args}"
exec command

57
bin/xgrep Executable file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env ruby
ands = [ ]
ors = [ ]
nots = [ ]
current = ands
paths = %w{Rakefile app config db lib spec}
debug = false
options = %w{-E -I}
ARGV.each do |x|
case x
when "-d","--debug" then debug = true
when "-i","--ignore" then options << "--ignore-case"
when "-l","--names" then options << "--name-only"
when "--clean" then options << "--no-color"
when "--core" then paths -= ["spec"]
when "--spec" then paths = ["spec"]
when "--model" then paths = ["app/models"]
when "--view" then paths = ["app/views"]
when "--controller" then paths = ["app/controllers"]
when "--lib" then paths = ["lib"]
when "--config" then paths = ["config"]
when "--db" then paths = ["db"]
when /^-+(and|or|not)$/ then current << $1
when "and" then current = ands
when "or" then current = ors
when "not" then current = nots
else current << x
end
end
ands = ands.map { |x| "-e \"#{x}\"" }
ors = ors.map { |x| "-e \"#{x}\"" }
nots = nots.map { |x| "-e \"#{x}\"" }
if ors.size == 1
ands << ors.first
elsif ors.size > 1
ands << "\\( #{ors.join(' --or ')} \\)"
end
ands << "--not \\( #{nots.join(' --or ')} \\)" unless nots.empty?
ands = ands.join(" --and ")
command = "git grep #{options.join(' ')} #{ands} -- #{paths.sort.join(' ')}"
if debug
puts
puts command
end
puts
exec command