#!/usr/bin/env ruby require 'elib_mgmt/cli' require 'tty/prompt' require 'colorize' require 'openssl' if ARGV.length < 2 STDERR.puts " ".red exit(0) else pmt = TTY::Prompt.new pmt.puts "\n eLib Management Utilities version #{ElibMgmt::Cli::VERSION}\n\n" pmt.puts " Search files with specific keywords" root = ARGV.first root = File.expand_path(root) pmt.puts " Root to search : #{root}\n\n" kw = ARGV[1] kw = kw.split(",").map { |v| v.strip }.reject { |v| v.empty? } pmt.puts " Keyword to search : #{kw.join(", ")}\n\n" files = Dir.glob(File.join(root,"**/**")).reject { |f| File.directory?(f) } filter = ElibMgmt::Cli::FileFilter.new(root) loop do ttl = 0 found = { } kw.each do |k| res = filter.filter(k, "**/**") found[k] = res ttl += res.length end pmt.puts " Found #{ttl} file(s) \n\n".light_blue if TR::RTUtils.on_linux? or TR::RTUtils.on_mac? begin opened = [] loopWithNewKw = false loop do system("clear") if not opened.empty? pmt.puts("\n\n You've opened: ".light_blue) opened.each do |o| pmt.puts(" - #{o}".light_blue) end pmt.puts end sel = pmt.select("\n\n Please select one of the following to open : ".yellow, per_page: 10) do |m| m.choice " + I've done".yellow, :abort found.values.flatten.each do |f| m.choice " * #{f}", f end m.choice " + New keyword", :new m.choice " + I've done".yellow, :abort end case sel when :new newKw = pmt.ask(" Please provide a new keywords (separated by ',') : ", required: true) kw = newKw.split(",").map { |v| v.strip }.reject { |v| v.empty? } loopWithNewKw = true when :abort pmt.puts "\n\n Have a nice day\n\n".yellow loopWithNewKw = false break else if TR::RTUtils.on_linux? `xdg-open #{sel}` elsif TR::RTUtils.on_mac? `open #{sel}` else pmt.puts "\n\nNot sure how to open from this platform. Please nagivate to the file location at '#{sel}' and open from there\n\n".red end opened << sel end # pmt.select end # loop break if not loopWithNewKw rescue TTY::Reader::InputInterrupt pmt.puts "\n\n Have a nice day\n\n".yellow break end else found.each do |k,v| v.each do |f| pmt.puts " * #{f}" end end break end end end