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
Provenance
- Commit
02c01c8- Tree
743c8b9- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
22d3929
3 files changed+41 added−11 removed
modified:test/test_fzf.rb+31 added-1 removed
588 unmodified lines589 $stdout = STDOUT590 end591 end592 593+ def test_select_1_without_query594+ stream = stream_for "Hello World"595+ output = StringIO.new596+597+ 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+ end607+608 def test_select_1_ambiguity609 stream = stream_for "Hello\nWorld"610 begin611 Timeout::timeout(3) do13 unmodified lines625 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 end635+636+ def test_exit_0_without_query637+ stream = stream_for ""638+ output = StringIO.new639+640+ 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+ end650 end651 modified:fzf+8 added-8 removed
5 unmodified lines6 # / /_/_ / / /_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: MIT178 unmodified lines193 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 end209 210 if loaded || len > 164 unmodified lines275 --black Use black background276 277 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.282 283 Environment variables284 FZF_DEFAULT_COMMAND Default command to use when input is tty993 unmodified linesmodified:README.md+2 added-2 removed
70 unmodified lines71 --black Use black background72 73 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.78 79 Environment variables80 FZF_DEFAULT_COMMAND Default command to use when input is tty357 unmodified lines