lib/yac.rb in yac-1.4.0 vs lib/yac.rb in yac-1.4.1
- old
+ new
@@ -3,11 +3,11 @@
module Yac
include Format
extend self
- VERSION = '1.4.0'
+ VERSION = '1.4.1'
@color = {
'head1' => "1;31",
'head2' => "1;36",
'head3' => "1;33",
@@ -195,19 +195,17 @@
return full_path(choose_one(result))
end
end
def search_content(args)
- # find -type f -exec sh -c 'file="{}";type=$(file $file);[[ $type =~ " text" ]] && echo $file' \; => Too slow
-
# If use @ as prefix , only search private repository
result = args.sub!(/^@/,'') ? [] : %x(
- find "#{@main_path}" -not -iwholename '*\/.git\/*' | grep -E '*\.[ch|yac|yml]'| xargs grep -HniP '#{args}' | sed 's/^/@/g'
+ find "#{@main_path}" -not -iwholename '*\/.git\/*' | xargs grep -HniP '#{args}' --binary-files=without-match | sed 's/^/@/g'
).to_a
result.concat %x(
- find "#{@pri_path}" -not -iwholename '*\/.git\/*' | grep -E '*\.[ch|yac|yml]'| xargs grep -HniP '#{args}'
+ find "#{@pri_path}" -not -iwholename '*\/.git\/*' | xargs grep -HniP '#{args}' --binary-files=without-match
).to_a
all_result = []
result.each do |x|
stuff = x.split(':',3)
@@ -230,11 +228,11 @@
return filename.strip
end
def confirm(*msg)
colorful("#{msg.to_s}\nAre You Sure (Y/N) (q:quit):","notice",false)
- return STDIN.gets.to_s =~ /n|q/i ? false : true
+ return (STDIN.gets || exit) =~ /n|q/i ? false : true
end
def choose_one(args)
return false unless args.size > 0
@@ -248,16 +246,16 @@
num = choose_range(args.size)
return num ? args[num-1].to_s.strip : false #return the filename
end
def trancate_filename(name)
- name.sub!(/\..*$/,'').sub!(/^@/,'')
+ name = name.sub(/\..*$/,'').sub(/^@/,'')
content = name.size > 22 ? '..' + name.reverse[0,20].reverse : name
end
def choose_range(size)
colorful("Please Input A Valid Number (1..#{size}) (q:quit): ","notice",false)
- num = STDIN.gets
+ num = STDIN.gets || exit
return false if num =~ /q/i
choosed_num = num.strip.empty? ? 1 : num.to_i
(1..size).member?(choosed_num) ? (return choosed_num) : choose_range(size)
end
end