Module: VER::Methods::Selection

Defined in:
lib/ver/methods/selection.rb

Class Method Summary collapse

Class Method Details

.pipe(buffer) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ver/methods/selection.rb', line 6

def pipe(buffer)
  paths = ENV['PATH'].split(':').map{|path| Pathname(path).expand_path }

  buffer.ask 'Pipe command: ' do |answer, action|
    case action
    when :complete
      current = answer.split.last
      paths.map{|path|
        (path/"*#{current}*").glob.select{|file|
          begin
            file = File.readlink(file) if File.symlink?(file)
            stat = File.stat(file)
            stat.file? && stat.executable?
          rescue Errno::ENOENT
          end
        }
      }.flatten.compact
    when :attempt
      buffer.at_sel.pipe!(answer)
      buffer.at_sel.finish
      :abort
    end
  end
end