lib/yac.rb in yac-1.2.1 vs lib/yac.rb in yac-1.3.0

- old
+ new

@@ -2,11 +2,11 @@ %w(git fileutils yaml format).each {|f| require f} module Yac include Format extend self - VERSION = '1.2.1' + VERSION = '1.3.0' YACRC = File.join("#{ENV['HOME']}",".yacrc") FileUtils.cp(File.join(File.dirname(__FILE__), "..","resources","yacrc"), YACRC) unless File.exist?(YACRC) CONFIG = YAML.load_file(File.join(ENV['HOME'],".yacrc")) @@ -32,11 +32,10 @@ when "-r" then rm(args[1,args.size]) when "-m" then mv(args[1,args.size]) when "-v" then colorful("Yac Version: #{Yac::VERSION}",'notice') else show(args) end - rescue end def init FileUtils.mkdir_p(CONFIG['root']) {"main" => @main_path,"private" => @pri_path}.each do |name,path| @@ -110,14 +109,14 @@ def shell(args) case args.to_s when /main/ colorful(" Welcome To The Main Yac Repository","notice") - system "cd \"#{@main_path}\"; sh" + system "cd '#{@main_path}'; sh" else colorful(" Welcome To The Private Yac Repository","notice") - system "cd \"#{@pri_path}\"; sh" + system "cd '#{@pri_path}'; sh" end end def mv(args) (colorful("Usage:\nyac mv [orign_name] [new_name]\n\nTry `yac -h` for more help","warn");exit) unless args.size == 2 @@ -171,35 +170,41 @@ end end def edit_single(args) file = search_name(args,"Edit") - edit_file(file) - @working_git.edit(file) + if file + edit_file(file) + @working_git.edit(file) + end end def search_name(args,msg = nil) path = (args =~ /^(@)/) ? [@main_path] : [@main_path , @pri_path] result = [] path.each do |x| - result.concat(`find "#{x}" -type f -iwholename '#{x}*#{args.gsub(/\//,'*/*').sub(/^@/,'').strip}*' -not -iwholename '*.git*'| sed 's/^.*\\/\\(private\\|main\\)\\//#{x=~/main/ ? '@':'' }/'`.to_a) + result.concat(`find "#{x}" -type f -iwholename '#{x}*#{args.gsub(/\//,'*/*').sub(/^@/,'').strip}*' -not -iwholename '*\/.git\/*'| sed 's/^.*\\/\\(private\\|main\\)\\//#{x=~/main/ ? '@':'' }/'`.to_a) end - return result.empty? ? (colorful("Nothing Found About < #{args} >","warn")) : - (colorful("The Results About < #{args} > To #{msg || "Operate"} :","notice");full_path(choose_one(result))) + if result.empty? + colorful("Nothing Found About < #{args} >","warn") + return false + else + colorful("The Results About < #{args} > To #{msg} :","notice") + return full_path(choose_one(result)) + end end def search_content(args) - 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) + 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) - filename = stuff[0].sub(/(@?).*\/(?:main|private)\/(.*)/,'\1'+'\2') - colorful(filename,"filename",false) + colorful(File.basename(stuff[0]).sub(/\..*/,''),"filename",false) colorful(stuff[1],"line_number",false) - format_section(empha(stuff[2],nil,/((#{args}))/i),true) - all_result.concat(filename.to_a) + format_section(stuff[2],/((#{args}))/i) + all_result << stuff[0].sub(/(@?).*\/(?:main|private)\/(.*)/,'\1'+'\2') end all_result.uniq! loop do colorful("All files Contain #{args.strip},Choose one to show","notice") file = full_path(choose_one(all_result))