]> git.mdlowis.com Git - projs/tide.git/commitdiff
updated tide-fetch to use find command instead of Dir.glob for performance. Also...
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 20 Jul 2017 01:13:34 +0000 (21:13 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 20 Jul 2017 01:13:34 +0000 (21:13 -0400)
tide-fetch.rb

index 5fcfc6df695722f205beba9d4c0b6a13853b1623..d2f864f03c2b4398716ec92ab1559e7288241a9a 100755 (executable)
@@ -42,18 +42,13 @@ def open_with(app)
   spawn("#{app} #{$item}")
 end
 
-def find_files(file)
-  if file.match(/^\.?\//)
-    files = [file]
-  else
-    files = Dir.glob("**/#{file}").sort_by(&:length)
-  end
-  raise RuleError.new() if files.length == 0
-  files
-end
-
 def find_file(file)
-  find_files(file).first
+  file = file.gsub(/^~/, ENV["HOME"])
+  if not file.match(/^\.?\//)
+    file = `find . -path '*#{file}' -print -quit`.chomp
+  end
+  raise RuleError.new() if (file.length == 0 || (not File.exist?(file)))
+  file
 end
 
 def mimetype(regex)