#!/usr/bin/env ruby
# encoding: utf-8
#
# ____ ____
# / __/___ / __/
# / /_/_ / / /_
# / __/ / /_/ __/
# /_/ /___/_/ Fuzzy finder for your shell
#
# Version: 0.8.2 (March 30, 2014)
#
# Author: Junegunn Choi
# URL: https://github.com/junegunn/fzf
# License: MIT
#
# Copyright (c) 2014 Junegunn Choi
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'thread'
require 'curses'
require 'set'
unless String.method_defined? :force_encoding
class String
def force_encoding *arg
self
end
end
end
class FZF
C = Curses
attr_reader :rxflag, :sort, :nth, :color, :black, :ansi256,
:mouse, :multi, :query, :filter, :extended
class AtomicVar
def initialize value
@value = value
@mutex = Mutex.new
end
def get
@mutex.synchronize { @value }
end
def set value = nil
@mutex.synchronize do
@value = block_given? ? yield(@value) : value
end
end
def method_missing sym, *args, &blk
@mutex.synchronize { @value.send(sym, *args, &blk) }
end
end
def initialize argv, source = $stdin
@rxflag = nil
@sort = ENV.fetch('FZF_DEFAULT_SORT', 1000).to_i
@color = true
@ansi256 = true
@black = false
@multi = false
@mouse = true
@extended = nil
@filter = nil
@nth = nil
@delim = nil
argv =
if opts = ENV['FZF_DEFAULT_OPTS']
require 'shellwords'
Shellwords.shellwords(opts) + argv
else
argv.dup
end
while o = argv.shift
case o
when '--version' then version
when '-h', '--help' then usage 0
when '-m', '--multi' then @multi = true
when '+m', '--no-multi' then @multi = false
when '-x', '--extended' then @extended = :fuzzy
when '+x', '--no-extended' then @extended = nil
when '-i' then @rxflag = Regexp::IGNORECASE
when '+i' then @rxflag = 0
when '-c', '--color'<