lib/yac.rb in yac-1.1.3 vs lib/yac.rb in yac-1.1.4
- old
+ new
@@ -29,15 +29,13 @@
when "edit" then edit(args[1,args.size])
when /^(help|-h|yac|--help)$/ then help
when "sh" then shell(args[1,args.size])
when "rm" then rm(args[1,args.size])
when "mv" then rename(args[1,args.size])
- when /^version|-v$/ then
- load File.join(File.dirname(__FILE__), "..", "yac.gemspec");colorful("yac, version: " + VER,"notice")
else show(args)
end
- rescue
+ #rescue
end
def init
FileUtils.mkdir_p(CONFIG['root'])
{"main" => @main_path,"private" => @pri_path}.each do |name,path|
@@ -188,20 +186,20 @@
return result.empty? ? (colorful("Nothing Found About < #{args} >","warn")) :
(colorful("The Results About < #{args} > To #{msg || "Operate"} :","notice");full_path(choose_one(result)))
end
def search_content(args)
- args.sub!(/^"(.*)"/,'\1') #Remove the " for input Regex
- result = `cd "#{@pri_path}" && grep -n -i -P '#{args}' -R *.ch 2>/dev/null`.to_a
- result.concat(`cd "#{@main_path}" && grep -n -i -P '#{args}' -R *.ch 2>/dev/null | sed 's/^/@/g'`.to_a)
+ result = `find "#{@pri_path}" -iname '*.ch' -not -iwholename '*.git*' -exec grep -HniP '#{args}' '{}' \\;`.to_a
+ result.concat(`find "#{@main_path}" -iname '*.ch' -not -iwholename '*.git*' -exec grep -HniP '#{args}' '{}' \\; | sed 's/^/@/g'`.to_a)
all_result = []
result.each do |x|
stuff = x.split(':',3)
- colorful(stuff[0],"filename",false)
+ filename = stuff[0].sub(/(@?).*\/(?:main|private)\/(.*)/,'\1'+'\2')
+ colorful(filename,"filename",false)
colorful(stuff[1],"line_number",false)
format_section(empha(stuff[2],nil,/((#{args}))/i),true)
- all_result.concat(stuff[0].to_a)
+ all_result.concat(filename.to_a)
end
all_result.uniq!
loop do
colorful("All files Contain #{args.strip},Choose one to show","notice")
file = full_path(choose_one(all_result))
@@ -219,10 +217,10 @@
file = @pri_path + args
end
return file.strip
end
- def confirm(*msg)
+ def confirm(*msg)control
colorful("#{msg.to_s}\nAre You Sure (Y/N) (q to quit):","notice",false)
return STDIN.gets.to_s =~ /n|q/i ? false : true
end
def choose_one(stuff)