Skip to content
Myr

Improve -0 and -1 as suggested in #36

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Make -0 and -1 work without -q - Change exit status to 0 when exiting with -0

authored by Junegunn Choi · committed by Junegunn Choi · parent 22d3929 · Browse files · 3 files+41 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+41 added−11 removed

  • tests:+31 added−1 removed
  • other:+10 added−10 removed

3 files+41 added−11 removed

modified:test/test_fzf.rb+31 added-1 removed
588 unmodified lines
589 $stdout = STDOUT590 end591 end592593 def test_select_1_without_query594 stream = stream_for "Hello World"595 output = StringIO.new596597 begin598 $stdout = output599 FZF.new(%w[--select-1], stream).start600 rescue SystemExit => e601 assert_equal 0, e.status602 assert_equal 'Hello World', output.string.chomp603 ensure604 $stdout = STDOUT605 end606 end607608 def test_select_1_ambiguity609 stream = stream_for "Hello\nWorld"610 begin611 Timeout::timeout(3) do
13 unmodified lines
625 begin626 $stdout = output627 FZF.new(%w[--query=zz --exit-0], stream).start628 rescue SystemExit => e614 assert_equal 1, e.status629 assert_equal 0, e.status630 assert_equal '', output.string631 ensure632 $stdout = STDOUT633 end634 end635636 def test_exit_0_without_query637 stream = stream_for ""638 output = StringIO.new639640 begin641 $stdout = output642 FZF.new(%w[--exit-0], stream).start643 rescue SystemExit => e644 assert_equal 0, e.status645 assert_equal '', output.string646 ensure647 $stdout = STDOUT648 end649 end650end651
modified:fzf+8 added-8 removed
5 unmodified lines
6# / /_/_ / / /_7# / __/ / /_/ __/8# /_/ /___/_/ Fuzzy finder for your shell9#10# Version: 0.8.3 (April 2, 2014)10# Version: 0.8.3 (April 3, 2014)11#12# Author: Junegunn Choi13# URL: https://github.com/junegunn/fzf14# License: MIT
178 unmodified lines
193 start_reader.join194 filter_list @new195 else196 start_reader197 emit(:key) { q = @query.get; [q, q.length] } unless @query.empty?198 if !@query.empty? && (@select1 || @exit0)197 emit(:key) { q = @query.get; [q, q.length] } unless empty = @query.empty?198 if @select1 || @exit0199 start_search do |loaded, matches|200 len = matches.length200 len = empty ? @count.get : matches.length201 if loaded202 if @select1 && len == 1203 puts matches.first.first203 puts empty ? matches.first : matches.first.first204 exit 0205 elsif @exit0 && len == 0206 exit 1206 exit 0207 end208 end209210 if loaded || len > 1
64 unmodified lines
275 --black Use black background276277 Scripting278 -q, --query=STR Start the finder with the given query279 -1, --select-1 (with --query) Automatically select the only match280 -0, --exit-0 (with --query) Exit when there's no match279 -1, --select-1 Automatically select the only match280 -0, --exit-0 Exit immediately when there's no match281 -f, --filter=STR Filter mode. Do not start interactive finder.282283 Environment variables284 FZF_DEFAULT_COMMAND Default command to use when input is tty
993 unmodified lines
modified:README.md+2 added-2 removed
70 unmodified lines
71 --black Use black background7273 Scripting74 -q, --query=STR Start the finder with the given query75 -1, --select-1 (with --query) Automatically select the only match76 -0, --exit-0 (with --query) Exit when there's no match75 -1, --select-1 Automatically select the only match76 -0, --exit-0 Exit immediately when there's no match77 -f, --filter=STR Filter mode. Do not start interactive finder.7879 Environment variables80 FZF_DEFAULT_COMMAND Default command to use when input is tty
357 unmodified lines