Module: D2::Helpers::Fzy

Defined in:
lib/d2/helpers/fzy.rb

Class Method Summary collapse

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

Parameters:

  • cmd (String)

    Command to run

  • query (String)

    Query to fuzzy match against

  • num_matches (Integer)

    number of matches to return (Default 1)

Returns:

  • (Array)

    all possible matches



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