mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-22 21:05:09 +00:00
Add FZF_DEFAULT_OPTS and update command-line options
This commit is contained in:
parent
13cb198b5c
commit
3723829b0a
11
README.md
11
README.md
@ -51,14 +51,19 @@ Usage
|
||||
```
|
||||
usage: fzf [options]
|
||||
|
||||
Options
|
||||
-m, --multi Enable multi-select
|
||||
-x, --extended Extended-search mode
|
||||
-q, --query=STR Initial query
|
||||
-s, --sort=MAX Maximum number of matched items to sort. Default: 1000
|
||||
-s, --sort=MAX Maximum number of matched items to sort (default: 1000)
|
||||
+s, --no-sort Do not sort the result. Keep the sequence unchanged.
|
||||
-i Case-insensitive match (default: smart-case match)
|
||||
+i Case-sensitive match
|
||||
+c, --no-color Disable colors
|
||||
|
||||
Environment variables
|
||||
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
||||
FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000")
|
||||
```
|
||||
|
||||
fzf will launch curses-based finder, read the list from STDIN, and write the
|
||||
@ -315,10 +320,10 @@ is less than the limit which is by default 1000, in order to avoid the cost of
|
||||
sorting a large list and limit the response time of the query.
|
||||
|
||||
This limit can be adjusted with `-s` option, or with the environment variable
|
||||
`FZF_DEFAULT_SORT`.
|
||||
`FZF_DEFAULT_OPTS`.
|
||||
|
||||
```sh
|
||||
export FZF_DEFAULT_SORT=10000
|
||||
export FZF_DEFAULT_OPTS="--sort 20000"
|
||||
```
|
||||
|
||||
License
|
||||
|
32
fzf
32
fzf
@ -7,7 +7,7 @@
|
||||
# / __/ / /_/ __/
|
||||
# /_/ /___/_/ Fuzzy finder for your shell
|
||||
#
|
||||
# Version: 0.6.1 (December 28, 2013)
|
||||
# Version: 0.6.2-devel (January 22, 2014)
|
||||
#
|
||||
# Author: Junegunn Choi
|
||||
# URL: https://github.com/junegunn/fzf
|
||||
@ -42,7 +42,7 @@ require 'set'
|
||||
|
||||
class FZF
|
||||
C = Curses
|
||||
attr_reader :rxflag, :sort, :color, :multi, :query
|
||||
attr_reader :rxflag, :sort, :color, :multi, :query, :extended
|
||||
|
||||
class AtomicVar
|
||||
def initialize value
|
||||
@ -72,19 +72,28 @@ class FZF
|
||||
@sort = ENV.fetch('FZF_DEFAULT_SORT', 1000).to_i
|
||||
@color = true
|
||||
@multi = false
|
||||
@xmode = false
|
||||
@extended = false
|
||||
|
||||
argv = argv.dup
|
||||
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 '-x', '--extended' then @xmode = true
|
||||
when '+m', '--no-multi' then @multi = false
|
||||
when '-x', '--extended' then @extended = true
|
||||
when '+x', '--no-extended' then @extended = false
|
||||
when '-i' then @rxflag = Regexp::IGNORECASE
|
||||
when '+i' then @rxflag = 0
|
||||
when '+s', '--no-sort' then @sort = nil
|
||||
when '-c', '--color' then @color = true
|
||||
when '+c', '--no-color' then @color = false
|
||||
when '+s', '--no-sort' then @sort = nil
|
||||
when '-q', '--query'
|
||||
usage 1, 'query string required' unless query = argv.shift
|
||||
@query = AtomicVar.new query.dup
|
||||
@ -145,14 +154,19 @@ class FZF
|
||||
$stderr.puts message if message
|
||||
$stderr.puts %[usage: fzf [options]
|
||||
|
||||
Options
|
||||
-m, --multi Enable multi-select
|
||||
-x, --extended Extended-search mode
|
||||
-q, --query=STR Initial query
|
||||
-s, --sort=MAX Maximum number of matched items to sort. Default: 1000
|
||||
-s, --sort=MAX Maximum number of matched items to sort (default: 1000)
|
||||
+s, --no-sort Do not sort the result. Keep the sequence unchanged.
|
||||
-i Case-insensitive match (default: smart-case match)
|
||||
+i Case-sensitive match
|
||||
+c, --no-color Disable colors]
|
||||
+c, --no-color Disable colors
|
||||
|
||||
Environment variables
|
||||
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
||||
FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000")] + $/ + $/
|
||||
exit x
|
||||
end
|
||||
|
||||
@ -526,7 +540,7 @@ class FZF
|
||||
end
|
||||
|
||||
def start_search
|
||||
matcher = (@xmode ? ExtendedFuzzyMatcher : FuzzyMatcher).new @rxflag
|
||||
matcher = (@extended ? ExtendedFuzzyMatcher : FuzzyMatcher).new @rxflag
|
||||
searcher = Thread.new {
|
||||
lists = []
|
||||
events = {}
|
||||
|
@ -1,7 +1,7 @@
|
||||
# coding: utf-8
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = 'fzf'
|
||||
spec.version = '0.6.1'
|
||||
spec.version = '0.6.2'
|
||||
spec.authors = ['Junegunn Choi']
|
||||
spec.email = ['junegunn.c@gmail.com']
|
||||
spec.description = %q{Fuzzy finder for your shell}
|
||||
|
@ -7,43 +7,74 @@ ENV['FZF_EXECUTABLE'] = '0'
|
||||
load 'fzf'
|
||||
|
||||
class TestFZF < MiniTest::Unit::TestCase
|
||||
|
||||
def setup
|
||||
ENV.delete 'FZF_DEFAULT_SORT'
|
||||
ENV.delete 'FZF_DEFAULT_OPTS'
|
||||
ENV.delete 'FZF_DEFAULT_COMMAND'
|
||||
end
|
||||
|
||||
def test_default_options
|
||||
fzf = FZF.new []
|
||||
assert_equal 1000, fzf.sort
|
||||
assert_equal false, fzf.multi
|
||||
assert_equal true, fzf.color
|
||||
assert_equal nil, fzf.rxflag
|
||||
|
||||
begin
|
||||
ENV['FZF_DEFAULT_SORT'] = '1500'
|
||||
fzf = FZF.new []
|
||||
assert_equal 1500, fzf.sort
|
||||
ensure
|
||||
ENV.delete 'FZF_DEFAULT_SORT'
|
||||
end
|
||||
|
||||
def test_environment_variables
|
||||
# Deprecated
|
||||
ENV['FZF_DEFAULT_SORT'] = '20000'
|
||||
fzf = FZF.new []
|
||||
assert_equal 20000, fzf.sort
|
||||
|
||||
ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c'
|
||||
fzf = FZF.new []
|
||||
assert_equal 10000, fzf.sort
|
||||
assert_equal ' hello world ',
|
||||
fzf.query.get
|
||||
assert_equal true, fzf.extended
|
||||
assert_equal true, fzf.multi
|
||||
assert_equal false, fzf.color
|
||||
end
|
||||
|
||||
def test_option_parser
|
||||
# Long opts
|
||||
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello]
|
||||
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello --extended]
|
||||
assert_equal 2000, fzf.sort
|
||||
assert_equal true, fzf.multi
|
||||
assert_equal false, fzf.color
|
||||
assert_equal 0, fzf.rxflag
|
||||
assert_equal 'hello', fzf.query.get
|
||||
assert_equal true, fzf.extended
|
||||
|
||||
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello
|
||||
--no-sort -i --color --no-multi]
|
||||
assert_equal nil, fzf.sort
|
||||
assert_equal false, fzf.multi
|
||||
assert_equal true, fzf.color
|
||||
assert_equal 1, fzf.rxflag
|
||||
assert_equal 'hello', fzf.query.get
|
||||
assert_equal false, fzf.extended
|
||||
|
||||
# Short opts
|
||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello]
|
||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x]
|
||||
assert_equal 2000, fzf.sort
|
||||
assert_equal true, fzf.multi
|
||||
assert_equal false, fzf.color
|
||||
assert_equal 0, fzf.rxflag
|
||||
assert_equal 'hello', fzf.query.get
|
||||
assert_equal true, fzf.extended
|
||||
|
||||
# Left-to-right
|
||||
fzf = FZF.new %w[-qhello -s 2000 --no-sort -q world]
|
||||
assert_equal nil, fzf.sort
|
||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x
|
||||
-s 3000 -c +m -i -q world +x]
|
||||
assert_equal 3000, fzf.sort
|
||||
assert_equal false, fzf.multi
|
||||
assert_equal true, fzf.color
|
||||
assert_equal 1, fzf.rxflag
|
||||
assert_equal 'world', fzf.query.get
|
||||
assert_equal false, fzf.extended
|
||||
|
||||
fzf = FZF.new %w[--query hello +s -s 2000 --query=world]
|
||||
assert_equal 2000, fzf.sort
|
||||
|
Loading…
Reference in New Issue
Block a user