Module: D2::Helpers::Fzy
- Defined in:
- lib/d2/helpers/fzy.rb
Class Method Summary collapse
-
.fuzzy_match(cmd, query:, num_matches: 1) ⇒ Array
Fuzzy matches the output of a command against a query.
Class Method Details
.fuzzy_match(cmd, query:, num_matches: 1) ⇒ Array
Fuzzy matches the output of a command against a query. Returns n matches of output, defaulting to 1
17 18 19 20 21 |
# File 'lib/d2/helpers/fzy.rb', line 17 def self.fuzzy_match(cmd, query:, num_matches: 1) lines = num_matches > 3 ? num_matches : 3 # Min lines is 3 in fzy out, _ = CLI::Kit::System.capture2e("#{cmd} | #{PATH} --lines=#{lines} --show-matches=#{query}") out.lines.take(num_matches) end |