Class: Codeowners::Cli::FilesFromFZFSearch
- Inherits:
-
SuggestionStrategy
- Object
- SuggestionStrategy
- Codeowners::Cli::FilesFromFZFSearch
- 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
-
#pick_suggestions ⇒ Object
Open ‘fzf` with #query to suggest a list of matching files.
-
#query ⇒ Object
Returns shortcut of the current folders => ‘some/folder/with/file.txt’ to ‘some/fowi/file.txt’.
Methods inherited from SuggestionStrategy
Constructor Details
This class inherits a constructor from Codeowners::Cli::SuggestionStrategy
Instance Method Details
#pick_suggestions ⇒ Object
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 |
#query ⇒ Object
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 |