Class: Codeowners::Cli::FilesFromFZFSearch

Inherits:
SuggestionStrategy show all
Defined in:
lib/codeowners/cli/suggest_file_from_pattern.rb

Overview

Bring a list of suggestions using ‘fzf` from the current folder

Instance Method Summary collapse

Methods inherited from SuggestionStrategy

#initialize

Constructor Details

This class inherits a constructor from Codeowners::Cli::SuggestionStrategy

Instance Method Details

#pick_suggestionsObject

Open ‘fzf` with #query to suggest a list of matching files



47
48
49
50
# File 'lib/codeowners/cli/suggest_file_from_pattern.rb', line 47

def pick_suggestions
  `fzf --height 50% --reverse -q #{query.inspect}`
    .lines.first&.chomp
end

#queryObject

Returns shortcut of the current folders

> ‘some/folder/with/file.txt’ to ‘some/fowi/file.txt’



54
55
56
57
58
# File 'lib/codeowners/cli/suggest_file_from_pattern.rb', line 54

def query
  dir, _, file = @pattern.gsub(/[_\-\*]+/, '').rpartition '/'
  dir.gsub(%r{/(\w{,2})[^/]+}, '\1') + # map 2 chars per folder
    file.gsub(/\.\w+/, '')             # remove extension
end