Class: AIA::Fzf
Constant Summary collapse
- DEFAULT_PARAMETERS =
%w[ --tabstop=2 --header-first --prompt='Search term: ' --delimiter : --preview-window=down:50%:wrap ]
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #build_command ⇒ Object
-
#initialize(list:, directory:, query: '', subject: 'Prompt IDs', prompt: 'Select one:', extension: '.txt') ⇒ Fzf
constructor
A new instance of Fzf.
- #run ⇒ Object
Methods inherited from Tools
catalog, get_meta, inherited, load_tools, #meta, meta, search_for, setup_backend, validate_tools
Constructor Details
#initialize(list:, directory:, query: '', subject: 'Prompt IDs', prompt: 'Select one:', extension: '.txt') ⇒ Fzf
Returns a new instance of Fzf.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aia/tools/fzf.rb', line 27 def initialize( list:, # Array of Strings (basenames of files w/o extension) directory:, # Parent directory of the list items query: '', # String, the thing be searched for subject: 'Prompt IDs', # or 'Role Names' prompt: 'Select one:', extension: '.txt' ) @list = list @directory = directory @query = query @subject = subject @prompt = prompt @extension = extension build_command end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
25 26 27 |
# File 'lib/aia/tools/fzf.rb', line 25 def command @command end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
25 26 27 |
# File 'lib/aia/tools/fzf.rb', line 25 def directory @directory end |
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
25 26 27 |
# File 'lib/aia/tools/fzf.rb', line 25 def extension @extension end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
25 26 27 |
# File 'lib/aia/tools/fzf.rb', line 25 def list @list end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
25 26 27 |
# File 'lib/aia/tools/fzf.rb', line 25 def prompt @prompt end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
25 26 27 |
# File 'lib/aia/tools/fzf.rb', line 25 def query @query end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
25 26 27 |
# File 'lib/aia/tools/fzf.rb', line 25 def subject @subject end |
Instance Method Details
#build_command ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/aia/tools/fzf.rb', line 47 def build_command = DEFAULT_PARAMETERS.dup << "--header='#{subject} which contain: #{query}\\nPress ESC to cancel.'" << "--preview='cat #{directory}/{1}#{extension}'" << "--prompt=#{Shellwords.escape(prompt)}" fzf_command = "#{.name} #{.join(' ')}" @command = "cat #{tempfile_path} | #{fzf_command}" end |
#run ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/aia/tools/fzf.rb', line 59 def run puts "Executing: #{@command}" selected = `#{@command}` selected.strip.empty? ? nil : selected.strip ensure unlink_tempfile end |