Skip to content
Myr

test_shell_integration.rb

This file

Path

test/test_shell_integration.rb

1,329 lines · 41.4 KiB · Ruby

Last changed by

[nushell] Quote paths inserted by CTRL-T (#4919)Junegunn Choibefore adoptionfe04475

History of this file

Take it

The walk stopped after 200 commits: lines older than 76efddd point at it.

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 1–102why, one step back
1# frozen_string_literal: true
23require_relative 'lib/common'45# Testing shell integration6module TestShell7 attr_reader :tmux89 def setup10 @tmux = Tmux.new(shell)11 tmux.prepare12 end1314 def teardown15 @tmux.kill16 end1718 def set_var(name, val)19 tmux.prepare20 tmux.send_keys "export #{name}='#{val}'", :Enter21 tmux.prepare22 end2324 def unset_var(name)25 tmux.prepare26 tmux.send_keys "unset #{name}", :Enter27 tmux.prepare28 end2930 def trigger31 '**'32 end3334 def test_ctrl_t35 set_var('FZF_CTRL_T_COMMAND', 'seq 100')3637 tmux.prepare38 tmux.send_keys 'C-t'39 tmux.until { |lines| assert_equal 100, lines.match_count }40 tmux.send_keys :Tab, :Tab, :Tab41 tmux.until { |lines| assert lines.any_include?(' (3)') }42 tmux.send_keys :Enter43 tmux.until { |lines| assert lines.any_include?('1 2 3') }44 tmux.send_keys 'C-c'45 end4647 def test_ctrl_t_unicode48 writelines(['fzf-unicode 테스트1', 'fzf-unicode 테스트2'])49 set_var('FZF_CTRL_T_COMMAND', "cat #{tempname}")5051 tmux.prepare52 tmux.send_keys 'echo ', 'C-t'53 tmux.until { |lines| assert_equal 2, lines.match_count }54 tmux.send_keys 'fzf-unicode'55 tmux.until { |lines| assert_equal 2, lines.match_count }5657 tmux.send_keys '1'58 tmux.until { |lines| assert_equal 1, lines.match_count }59 tmux.send_keys :Tab60 tmux.until { |lines| assert_equal 1, lines.select_count }6162 tmux.send_keys :BSpace63 tmux.until { |lines| assert_equal 2, lines.match_count }6465 tmux.send_keys '2'66 tmux.until { |lines| assert_equal 1, lines.match_count }67 tmux.send_keys :Tab68 tmux.until { |lines| assert_equal 2, lines.select_count }6970 tmux.send_keys :Enter71 tmux.until { |lines| assert_match(/echo .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines.join) }72 tmux.send_keys :Enter73 tmux.until { |lines| assert_equal 'fzf-unicode 테스트1 fzf-unicode 테스트2', lines[-1] }74 end7576 def test_alt_c77 tmux.prepare78 tmux.send_keys :Escape, :c79 lines = tmux.until { |lines| assert_operator lines.match_count, :>, 0 }80 expected = lines.reverse.find { |l| l.start_with?('> ') }[2..].chomp('/')81 tmux.send_keys :Enter82 tmux.prepare83 tmux.send_keys :pwd, :Enter84 tmux.until { |lines| assert lines[-1]&.end_with?(expected) }85 end8687 def test_alt_c_command88 set_var('FZF_ALT_C_COMMAND', 'echo /tmp')8990 tmux.prepare91 tmux.send_keys 'cd /', :Enter9293 tmux.prepare94 tmux.send_keys :Escape, :c95 tmux.until { |lines| assert_equal 1, lines.match_count }96 tmux.send_keys :Enter9798 tmux.prepare99 tmux.send_keys :pwd, :Enter100 tmux.until { |lines| assert_equal '/tmp', lines[-1] }101 end102

test: ALT-C regression testsLangLangBartbefore adoptionabee152

lines 103–143why, one step back
103 def test_alt_c_symlink
104 base = '/tmp/fzf-test-alt-c-symlink'105 FileUtils.rm_rf(base)106 FileUtils.mkdir_p("#{base}/real/subdir")107 FileUtils.ln_s("#{base}/real", "#{base}/link")108109 tmux.prepare110 tmux.send_keys "cd #{base}/link", :Enter111 tmux.prepare112 tmux.send_keys :Escape, :c113 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }114 tmux.send_keys 'subdir'115 tmux.until { |lines| assert_equal 1, lines.match_count }116 tmux.send_keys :Enter117 tmux.prepare118 tmux.send_keys :pwd, :Enter119 tmux.until { |lines| assert_equal "#{base}/link/subdir", lines[-1] }120 ensure121 FileUtils.rm_rf(base)122 end123124 def test_alt_c_absolute_cmd125 base = '/tmp/fzf-test-alt-c-absolute'126 FileUtils.rm_rf(base)127 FileUtils.mkdir_p(base)128129 set_var('FZF_ALT_C_COMMAND', "echo #{base}")130131 tmux.prepare132 tmux.send_keys 'cd /tmp', :Enter133 tmux.prepare134 tmux.send_keys :Escape, :c135 tmux.until { |lines| assert_equal 1, lines.match_count }136 tmux.send_keys :Enter137 tmux.prepare138 tmux.send_keys :pwd, :Enter139 tmux.until { |lines| assert_equal base, lines[-1] }140 ensure141 FileUtils.rm_rf(base)142 end143

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 144–883why, one step back
144 def test_ctrl_r
145 tmux.prepare146 tmux.send_keys 'echo 1st', :Enter147 tmux.prepare148 tmux.send_keys 'echo 2nd', :Enter149 tmux.prepare150 tmux.send_keys 'echo 3d', :Enter151 tmux.prepare152 3.times do153 tmux.send_keys 'echo 3rd', :Enter154 tmux.prepare155 end156 tmux.send_keys 'echo 4th', :Enter157 tmux.prepare158 tmux.send_keys 'C-r'159 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }160 tmux.send_keys 'e3d'161 # Duplicates removed: 3d (1) + 3rd (1) => 2 matches162 tmux.until { |lines| assert_equal 2, lines.match_count }163 tmux.until { |lines| assert lines[-3]&.end_with?(' echo 3d') }164 tmux.send_keys 'C-r'165 tmux.until { |lines| assert lines[-3]&.end_with?(' echo 3rd') }166 tmux.send_keys :Enter167 tmux.until { |lines| assert_equal 'echo 3rd', lines[-1] }168 tmux.send_keys :Enter169 tmux.until { |lines| assert_equal '3rd', lines[-1] }170 end171172 def test_ctrl_r_multiline173 # NOTE: Current bash implementation shows an extra new line if there's174 # only entry in the history175 tmux.send_keys ':', :Enter176 tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter177 tmux.until { |lines| assert_equal %w[foo bar], lines[-2..] }178 tmux.prepare179 tmux.send_keys 'C-r'180 tmux.until { |lines| assert_equal '>', lines[-1] }181 tmux.send_keys 'foo bar'182 tmux.until { |lines| assert_includes lines[-4], '"foo' } if shell == :bash183 tmux.until { |lines| assert lines[-3]&.match?(/bar"␊?/) }184 tmux.send_keys :Enter185 tmux.until { |lines| assert lines[-1]&.match?(/bar"␊?/) }186 tmux.send_keys :Enter187 tmux.until { |lines| assert_equal %w[foo bar], lines[-2..] }188 end189190 def test_ctrl_r_abort191 skip("doesn't restore the original line when search is aborted pre Bash 4") if shell == :bash && `#{Shell.bash} --version`[/(?<= version )\d+/].to_i < 4192 %w[foo ' "].each do |query|193 tmux.prepare194 tmux.send_keys :Enter, query195 tmux.until { |lines| assert lines[-1]&.start_with?(query) }196 tmux.send_keys 'C-r'197 tmux.until { |lines| assert_equal "> #{query}", lines[-1] }198 tmux.send_keys 'C-g'199 tmux.until { |lines| assert lines[-1]&.start_with?(query) }200 end201 end202end203204module CompletionTest205 def test_file_completion206 FileUtils.mkdir_p('/tmp/fzf-test')207 FileUtils.mkdir_p('/tmp/fzf test')208 (1..100).each { |i| FileUtils.touch("/tmp/fzf-test/#{i}") }209 ['no~such~user', '/tmp/fzf test/foobar'].each do |f|210 FileUtils.touch(File.expand_path(f))211 end212 tmux.prepare213 if shell == :fish214 tmux.send_keys 'cat /tmp/fzf-test/10', 'C-t'215 else216 tmux.send_keys "cat /tmp/fzf-test/10#{trigger}", :Tab217 end218 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }219 tmux.send_keys ' !d'220 tmux.until { |lines| assert_equal 2, lines.match_count }221 tmux.send_keys :Tab, :Tab222 tmux.until { |lines| assert_equal 2, lines.select_count }223 tmux.send_keys :Enter224 tmux.until(true) do |lines|225 assert_equal 'cat /tmp/fzf-test/10 /tmp/fzf-test/100', lines[-1]226 end227228 # ~USERNAME**<TAB>229 user = `whoami`.chomp230 tmux.send_keys 'C-u'231 if shell == :fish232 tmux.send_keys "cat ~#{user}", 'C-t'233 else234 tmux.send_keys "cat ~#{user}#{trigger}", :Tab235 end236 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }237 tmux.send_keys "/#{user}"238 tmux.until { |lines| assert(lines.any? { |l| l.end_with?("/#{user}") }) }239 tmux.send_keys :Enter240 tmux.until(true) do |lines|241 assert_match %r{cat .*/#{user}}, lines[-1]242 end243244 # ~INVALID_USERNAME**<TAB>245 tmux.send_keys 'C-u'246 if shell == :fish247 tmux.send_keys 'cat ~such', 'C-t'248 else249 tmux.send_keys "cat ~such#{trigger}", :Tab250 end251 tmux.until(true) { |lines| assert lines.any_include?('no~such~user') }252 tmux.send_keys :Enter253 tmux.until(true) do |lines|254 if shell == :fish255 # Fish's string escape quotes filenames with ~ to prevent tilde expansion256 assert_equal 'cat no\\~such\\~user', lines[-1]257 else258 assert_equal 'cat no~such~user', lines[-1]259 end260 end261262 # /tmp/fzf\ test**<TAB>263 tmux.send_keys 'C-u'264 if shell == :fish265 tmux.send_keys 'cat /tmp/fzf\\ test/', 'C-t'266 else267 tmux.send_keys "cat /tmp/fzf\\ test/#{trigger}", :Tab268 end269 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }270 tmux.send_keys 'foobar$'271 tmux.until do |lines|272 assert_equal 1, lines.match_count273 assert lines.any_include?('> /tmp/fzf test/foobar')274 end275 tmux.send_keys :Enter276 tmux.until(true) { |lines| assert_equal 'cat /tmp/fzf\ test/foobar', lines[-1] }277278 # Should include hidden files279 (1..100).each { |i| FileUtils.touch("/tmp/fzf-test/.hidden-#{i}") }280 tmux.send_keys 'C-u'281 if shell == :fish282 tmux.send_keys 'cat /tmp/fzf-test/hidden', 'C-t'283 else284 tmux.send_keys "cat /tmp/fzf-test/hidden#{trigger}", :Tab285 end286 tmux.until(true) do |lines|287 assert_equal 100, lines.match_count288 assert lines.any_include?('/tmp/fzf-test/.hidden-')289 end290 tmux.send_keys :Enter291 ensure292 ['/tmp/fzf-test', '/tmp/fzf test', '~/.fzf-home', 'no~such~user'].each do |f|293 FileUtils.rm_rf(File.expand_path(f))294 end295 end296297 def test_file_completion_root298 if shell == :fish299 tmux.send_keys 'ls /', 'C-t'300 else301 tmux.send_keys "ls /#{trigger}", :Tab302 end303 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }304 tmux.send_keys :Enter305 end306307 def test_dir_completion308 FileUtils.mkdir_p('/tmp/fzf-test-dir')309 (1..100).each do |idx|310 FileUtils.mkdir_p("/tmp/fzf-test-dir/d#{idx}")311 end312 FileUtils.touch('/tmp/fzf-test-dir/d55/xxx')313 tmux.prepare314 if shell == :fish315 tmux.send_keys 'cd /tmp/fzf-test-dir/', 'C-t'316 else317 tmux.send_keys "cd /tmp/fzf-test-dir/#{trigger}", :Tab318 end319 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }320 # Tab selects items in C-t's --multi mode, so skip for fish321 tmux.send_keys :Tab, :Tab unless shell == :fish # Tab does not work here322 tmux.send_keys '55/$'323 tmux.until do |lines|324 assert_equal 1, lines.match_count325 assert_includes lines, '> 55/$'326 assert_includes lines, '> /tmp/fzf-test-dir/d55/'327 end328 tmux.send_keys :Enter329 tmux.until(true) { |lines| assert_equal 'cd /tmp/fzf-test-dir/d55/', lines[-1] }330 # C-t appends a trailing space after the result331 tmux.send_keys :BSpace if shell == :fish332 tmux.send_keys :xx333 tmux.until { |lines| assert_equal 'cd /tmp/fzf-test-dir/d55/xx', lines[-1] }334335 # Should not match regular files (bash-only)336 if instance_of?(TestBash)337 tmux.send_keys :Tab338 tmux.until { |lines| assert_equal 'cd /tmp/fzf-test-dir/d55/xx', lines[-1] }339 end340341 # Fail back to plusdirs342 tmux.send_keys :BSpace, :BSpace, :BSpace343 tmux.until { |lines| assert_equal 'cd /tmp/fzf-test-dir/d55', lines[-1] }344 tmux.send_keys :Tab345 tmux.until { |lines| assert_equal 'cd /tmp/fzf-test-dir/d55/', lines[-1] }346 ensure347 FileUtils.rm_rf('/tmp/fzf-test-dir')348 end349350 def test_process_completion351 skip('fish background job format differs') if shell == :fish352353 begin354 tmux.send_keys 'sleep 12345 &', :Enter355 lines = tmux.until { |lines| assert lines[-1]&.start_with?('[1] ') }356 pid = lines[-1]&.split&.last357 tmux.prepare358 tmux.send_keys 'C-L'359 tmux.send_keys "kill #{trigger}", :Tab360 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }361 tmux.send_keys 'sleep12345'362 tmux.until { |lines| assert lines.any_include?('sleep 12345') }363 tmux.send_keys :Enter364 tmux.until(true) { |lines| assert_equal "kill #{pid}", lines[-1] }365 ensure366 if pid367 begin368 Process.kill('KILL', pid.to_i)369 rescue StandardError370 nil371 end372 end373 end374 end375376 def test_custom_completion377 skip('fish does not use _fzf_compgen_path; path completion is via ctrl-t') if shell == :fish378 tmux.send_keys '_fzf_compgen_path() { echo "$1"; seq 10; }', :Enter379 tmux.prepare380 tmux.send_keys "ls /tmp/#{trigger}", :Tab381 tmux.until { |lines| assert_equal 11, lines.match_count }382 tmux.send_keys :Tab, :Tab, :Tab383 tmux.until { |lines| assert_equal 3, lines.select_count }384 tmux.send_keys :Enter385 tmux.until(true) { |lines| assert_equal 'ls /tmp 1 2', lines[-1] }386 end387388 def test_unset_completion389 skip('fish has native completion for set and unset variables') if shell == :fish390 tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter391 tmux.prepare392393 # Using tmux394 tmux.send_keys "unset FZFFOOBR#{trigger}", :Tab395 tmux.until { |lines| assert_equal 1, lines.match_count }396 tmux.send_keys :Enter397 tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }398 tmux.send_keys 'C-c'399400 # FZF_TMUX=1401 new_shell402 tmux.focus403 tmux.send_keys "unset FZFFOOBR#{trigger}", :Tab404 tmux.until { |lines| assert_equal 1, lines.match_count }405 tmux.send_keys :Enter406 tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }407 end408409 def test_completion_in_command_sequence410 if shell == :fish411 FileUtils.mkdir_p('/tmp/fzf-test-seq')412 FileUtils.touch('/tmp/fzf-test-seq/fzffoobar')413 tmux.prepare414 # Fish uses Shift-Tab for fzf completion (no trigger system)415 command = 'echo foo; QUX=THUD ls /tmp/fzf-test-seq/fzffoobr'416 expected = 'echo foo; QUX=THUD ls /tmp/fzf-test-seq/fzffoobar'417 tmux.send_keys command, :BTab418 tmux.until { |lines| assert_equal 1, lines.match_count }419 tmux.send_keys :Enter420 tmux.until { |lines| assert_equal expected, lines[-1] }421 else422 tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter423 tmux.prepare424425 triggers = ['**', '~~', '++', 'ff', '/']426 triggers.push('&', '[', ';', '`') if instance_of?(TestZsh)427428 triggers.each do |trigger|429 set_var('FZF_COMPLETION_TRIGGER', trigger)430 command = "echo foo; QUX=THUD unset FZFFOOBR#{trigger}"431 expected = 'echo foo; QUX=THUD unset FZFFOOBAR'432 tmux.send_keys command.sub(/(;|`)$/, '\\\\\1'), :Tab433 tmux.until { |lines| assert_equal 1, lines.match_count }434 tmux.send_keys :Enter435 tmux.until { |lines| assert_equal expected, lines[-1] }436 end437 end438 ensure439 FileUtils.rm_rf('/tmp/fzf-test-seq') if shell == :fish440 end441442 def test_file_completion_unicode443 FileUtils.mkdir_p('/tmp/fzf-test')444 # Shell-agnostic file creation445 File.write('/tmp/fzf-test/fzf-unicode 테스트1', "test3\n")446 File.write('/tmp/fzf-test/fzf-unicode 테스트2', "test4\n")447 tmux.send_keys 'cd /tmp/fzf-test', :Enter448 tmux.prepare449 if shell == :fish450 tmux.send_keys 'cat fzf-unicode', 'C-t'451 else452 tmux.send_keys "cat fzf-unicode#{trigger}", :Tab453 end454 tmux.until { |lines| assert_equal 2, lines.match_count }455456 tmux.send_keys '1'457 tmux.until { |lines| assert_equal 1, lines.match_count }458 tmux.send_keys :Tab459 tmux.until { |lines| assert_equal 1, lines.select_count }460461 tmux.send_keys :BSpace462 tmux.until { |lines| assert_equal 2, lines.match_count }463464 tmux.send_keys '2'465 tmux.until { |lines| assert_equal 1, lines.select_count }466 tmux.send_keys :Tab467 tmux.until { |lines| assert_equal 2, lines.select_count }468469 tmux.send_keys :Enter470 tmux.until(true) { |lines| assert_match(/cat .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines[-1]) }471 tmux.send_keys :Enter472 tmux.until { |lines| assert_equal %w[test3 test4], lines[-2..] }473 end474475 def test_custom_completion_api476 skip('bash-specific _comprun/declare syntax') if shell == :fish477478 begin479 tmux.send_keys 'eval "_fzf$(declare -f _comprun)"', :Enter480 %w[f g].each do |command|481 tmux.prepare482 tmux.send_keys "#{command} b#{trigger}", :Tab483 tmux.until do |lines|484 assert_equal 2, lines.item_count485 assert_equal 1, lines.match_count486 assert lines.any_include?("prompt-#{command}")487 assert lines.any_include?("preview-#{command}-bar")488 end489 tmux.send_keys :Enter490 tmux.until { |lines| assert_equal "#{command} #{command}barbar", lines[-1] }491 tmux.send_keys 'C-u'492 end493 ensure494 tmux.prepare495 tmux.send_keys 'unset -f _fzf_comprun', :Enter496 end497 end498499 def test_ssh_completion500 skip('fish uses native ssh completion') if shell == :fish501 (1..5).each { |i| FileUtils.touch("/tmp/fzf-test-ssh-#{i}") }502503 tmux.send_keys "ssh jg@localhost#{trigger}", :Tab504 tmux.until do |lines|505 assert_operator lines.match_count, :>=, 1506 end507508 tmux.send_keys :Enter509 tmux.until { |lines| assert lines.any_include?('ssh jg@localhost') }510 tmux.send_keys " -i /tmp/fzf-test-ssh#{trigger}", :Tab511 tmux.until do |lines|512 assert_operator lines.match_count, :>=, 5513 assert_equal 0, lines.select_count514 end515 tmux.send_keys :Tab, :Tab, :Tab516 tmux.until do |lines|517 assert_equal 3, lines.select_count518 end519 tmux.send_keys :Enter520 tmux.until { |lines| assert lines.any_include?('ssh jg@localhost -i /tmp/fzf-test-ssh-') }521522 tmux.send_keys "localhost#{trigger}", :Tab523 tmux.until do |lines|524 assert_operator lines.match_count, :>=, 1525 end526 end527528 def test_option_equals_long_option529 FileUtils.mkdir_p('/tmp/fzf-test-opt-eq-long')530 FileUtils.touch('/tmp/fzf-test-opt-eq-long/SECURITY.md')531 tmux.prepare532 tmux.send_keys 'cd /tmp/fzf-test-opt-eq-long', :Enter533 tmux.prepare534 if shell == :fish535 tmux.send_keys 'some-command --opt=SECURI', 'C-t'536 else537 tmux.send_keys "some-command --opt=SECURI#{trigger}", :Tab538 end539540 case shell541 when :bash542 tmux.until do |lines|543 assert_equal 1, lines.match_count544 assert_includes lines, '> SECURI'545 end546 tmux.send_keys :Enter547 tmux.until(true) { |lines| assert_equal 'some-command --opt=SECURITY.md', lines[-1] }548 when :fish549 tmux.until do |lines|550 assert_equal 1, lines.match_count551 assert lines.any_include?('SECURITY.md')552 end553 tmux.send_keys :Enter554 tmux.until(true) { |lines| assert_equal 'some-command --opt=SECURITY.md', lines[-1] }555 when :zsh556 tmux.until do |lines|557 assert_equal 0, lines.match_count558 assert_includes lines, '> --opt=SECURI'559 end560 end561 ensure562 FileUtils.rm_rf('/tmp/fzf-test-opt-eq-long')563 end564565 def test_option_equals_long_option_after_double_dash566 FileUtils.mkdir_p('/tmp/fzf-test-opt-eq-long-ddash')567 FileUtils.touch('/tmp/fzf-test-opt-eq-long-ddash/SECURITY.md')568 tmux.prepare569 tmux.send_keys 'cd /tmp/fzf-test-opt-eq-long-ddash', :Enter570 tmux.prepare571 if shell == :fish572 tmux.send_keys 'some-command -- --opt=SECURI', 'C-t'573 else574 tmux.send_keys "some-command -- --opt=SECURI#{trigger}", :Tab575 end576577 case shell578 when :bash579 tmux.until do |lines|580 assert_equal 1, lines.match_count581 assert_includes lines, '> SECURI'582 end583 tmux.send_keys :Enter584 tmux.until(true) { |lines| assert_equal 'some-command -- --opt=SECURITY.md', lines[-1] }585 when :fish, :zsh586 tmux.until do |lines|587 assert_equal 0, lines.match_count588 assert_includes lines, '> --opt=SECURI'589 end590 end591 ensure592 FileUtils.rm_rf('/tmp/fzf-test-opt-eq-long-ddash')593 end594595 def test_option_equals_short_option596 FileUtils.mkdir_p('/tmp/fzf-test-opt-eq-short')597 FileUtils.touch('/tmp/fzf-test-opt-eq-short/SECURITY.md')598 tmux.prepare599 tmux.send_keys 'cd /tmp/fzf-test-opt-eq-short', :Enter600 tmux.prepare601 if shell == :fish602 tmux.send_keys 'some-command -o=SECURI', 'C-t'603 else604 tmux.send_keys "some-command -o=SECURI#{trigger}", :Tab605 end606607 case shell608 when :bash, :fish609 tmux.until do |lines|610 assert_equal 1, lines.match_count611 assert lines.any_include?('> SECURITY.md')612 end613 tmux.send_keys :Enter614 tmux.until(true) { |lines| assert_equal 'some-command -o=SECURITY.md', lines[-1] }615 when :zsh616 tmux.until do |lines|617 assert_equal 0, lines.match_count618 assert_includes lines, '> -o=SECURI'619 end620 end621 ensure622 FileUtils.rm_rf('/tmp/fzf-test-opt-eq-short')623 end624625 def test_option_equals_short_option_after_double_dash626 FileUtils.mkdir_p('/tmp/fzf-test-opt-eq-short-ddash')627 FileUtils.touch('/tmp/fzf-test-opt-eq-short-ddash/SECURITY.md')628 tmux.prepare629 tmux.send_keys 'cd /tmp/fzf-test-opt-eq-short-ddash', :Enter630 tmux.prepare631 if shell == :fish632 tmux.send_keys 'some-command -- -o=SECURI', 'C-t'633 else634 tmux.send_keys "some-command -- -o=SECURI#{trigger}", :Tab635 end636637 case shell638 when :bash639 tmux.until do |lines|640 assert_equal 1, lines.match_count641 assert_includes lines, '> SECURITY.md'642 end643 tmux.send_keys :Enter644 tmux.until(true) { |lines| assert_equal 'some-command -- -o=SECURITY.md', lines[-1] }645 when :fish, :zsh646 tmux.until do |lines|647 assert_equal 0, lines.match_count648 assert_includes lines, '> -o=SECURI'649 end650 end651 ensure652 FileUtils.rm_rf('/tmp/fzf-test-opt-eq-short-ddash')653 end654655 def test_option_no_equals_long_option656 FileUtils.mkdir_p('/tmp/fzf-test-opt-no-eq-long')657 FileUtils.touch('/tmp/fzf-test-opt-no-eq-long/SECURITY.md')658 tmux.prepare659 tmux.send_keys 'cd /tmp/fzf-test-opt-no-eq-long', :Enter660 tmux.prepare661 if shell == :fish662 tmux.send_keys 'some-command --optSECURI', 'C-t'663 else664 tmux.send_keys "some-command --optSECURI#{trigger}", :Tab665 end666667 tmux.until do |lines|668 assert_equal 0, lines.match_count669 assert_includes lines, '> --optSECURI'670 end671 ensure672 FileUtils.rm_rf('/tmp/fzf-test-opt-no-eq-long')673 end674675 def test_option_no_equals_long_option_after_double_dash676 FileUtils.mkdir_p('/tmp/fzf-test-opt-no-eq-long-ddash')677 FileUtils.touch('/tmp/fzf-test-opt-no-eq-long-ddash/SECURITY.md')678 tmux.prepare679 tmux.send_keys 'cd /tmp/fzf-test-opt-no-eq-long-ddash', :Enter680 tmux.prepare681 if shell == :fish682 tmux.send_keys 'some-command -- --optSECURI', 'C-t'683 else684 tmux.send_keys "some-command -- --optSECURI#{trigger}", :Tab685 end686687 tmux.until do |lines|688 assert_equal 0, lines.match_count689 assert_includes lines, '> --optSECURI'690 end691 ensure692 FileUtils.rm_rf('/tmp/fzf-test-opt-no-eq-long-ddash')693 end694695 def test_option_no_equals_short_option696 FileUtils.mkdir_p('/tmp/fzf-test-opt-no-eq-short')697 FileUtils.touch('/tmp/fzf-test-opt-no-eq-short/SECURITY.md')698 tmux.prepare699 tmux.send_keys 'cd /tmp/fzf-test-opt-no-eq-short', :Enter700 tmux.prepare701 if shell == :fish702 tmux.send_keys 'some-command -oSECURI', 'C-t'703 else704 tmux.send_keys "some-command -oSECURI#{trigger}", :Tab705 end706707 case shell708 when :bash, :zsh709 tmux.until do |lines|710 assert_equal 0, lines.match_count711 assert_includes lines, '> -oSECURI'712 end713 when :fish714 tmux.until do |lines|715 assert_equal 1, lines.match_count716 assert lines.any_include?('> SECURITY.md')717 end718 tmux.send_keys :Enter719 tmux.until(true) { |lines| assert_equal 'some-command -oSECURITY.md', lines[-1] }720 end721 ensure722 FileUtils.rm_rf('/tmp/fzf-test-opt-no-eq-short')723 end724725 def test_option_no_equals_short_option_after_double_dash726 FileUtils.mkdir_p('/tmp/fzf-test-opt-no-eq-short-ddash')727 FileUtils.touch('/tmp/fzf-test-opt-no-eq-short-ddash/SECURITY.md')728 tmux.prepare729 tmux.send_keys 'cd /tmp/fzf-test-opt-no-eq-short-ddash', :Enter730 tmux.prepare731 if shell == :fish732 tmux.send_keys 'some-command -- -oSECURI', 'C-t'733 else734 tmux.send_keys "some-command -- -oSECURI#{trigger}", :Tab735 end736737 tmux.until do |lines|738 assert_equal 0, lines.match_count739 assert_includes lines, '> -oSECURI'740 end741 ensure742 FileUtils.rm_rf('/tmp/fzf-test-opt-no-eq-short-ddash')743 end744745 def test_filename_with_newline746 FileUtils.mkdir_p('/tmp/fzf-test-newline')747 FileUtils.touch("/tmp/fzf-test-newline/xyz\nwith\nnewlines")748 tmux.prepare749 tmux.send_keys 'cd /tmp/fzf-test-newline', :Enter750 tmux.prepare751 if shell == :fish752 tmux.send_keys 'cat xyz', 'C-t'753 else754 tmux.send_keys "cat xyz#{trigger}", :Tab755 end756757 case shell758 when :fish759 tmux.until do |lines|760 assert_equal 1, lines.match_count761 assert_includes lines, '> xyz'762 end763 tmux.send_keys :Enter764 # fish escapes newlines in filenames765 tmux.until(true) { |lines| assert_equal 'cat xyz\\nwith\\nnewlines', lines[-1] }766 when :bash, :zsh767 tmux.until do |lines|768 assert_equal 1, lines.match_count769 assert_includes lines, '> xyz'770 end771 tmux.send_keys :Enter772 # bash and zsh replace newlines with spaces in filenames773 tmux.until(true) { |lines| assert_equal 'cat xyz with newlines', lines[-1] }774 end775 ensure776 FileUtils.rm_rf('/tmp/fzf-test-newline')777 end778779 def test_path_with_special_chars780 FileUtils.mkdir_p('/tmp/fzf-test-[special]')781 FileUtils.touch('/tmp/fzf-test-[special]/xyz123')782 tmux.prepare783 if shell == :fish784 tmux.send_keys 'ls /tmp/fzf-test-\[special\]/xyz', 'C-t'785 else786 tmux.send_keys "ls /tmp/fzf-test-\\[special\\]/xyz#{trigger}", :Tab787 end788 tmux.until { |lines| assert_equal 1, lines.match_count }789 tmux.send_keys :Enter790 tmux.until(true) { |lines| assert_equal 'ls /tmp/fzf-test-\\[special\\]/xyz123', lines[-1] }791 ensure792 FileUtils.rm_rf('/tmp/fzf-test-[special]')793 end794795 def test_query_with_dollar_anchor796 FileUtils.mkdir_p('/tmp/fzf-test-dollar-anchor')797 FileUtils.touch('/tmp/fzf-test-dollar-anchor/file.txt')798 FileUtils.touch('/tmp/fzf-test-dollar-anchor/filetxt.md')799 tmux.prepare800 tmux.send_keys 'cd /tmp/fzf-test-dollar-anchor', :Enter801 tmux.prepare802 if shell == :fish803 tmux.send_keys 'ls txt$', 'C-t'804 else805 tmux.send_keys "ls txt$#{trigger}", :Tab806 end807 tmux.until do |lines|808 assert_equal 1, lines.match_count809 assert_includes lines, '> txt$'810 end811 tmux.send_keys :Enter812 tmux.until(true) { |lines| assert_equal 'ls file.txt', lines[-1] }813 ensure814 FileUtils.rm_rf('/tmp/fzf-test-dollar-anchor')815 end816817 def test_single_flag_completion818 FileUtils.mkdir_p('/tmp/fzf-test-single-flag')819 FileUtils.touch('/tmp/fzf-test-single-flag/-testfile.txt')820 tmux.prepare821 tmux.send_keys 'cd /tmp/fzf-test-single-flag', :Enter822 tmux.prepare823 if shell == :fish824 tmux.send_keys 'ls -', 'C-t'825 else826 tmux.send_keys "ls -#{trigger}", :Tab827 end828829 tmux.until do |lines|830 assert_equal 1, lines.match_count831 assert_includes lines, '> -'832 end833 tmux.send_keys :Enter834 tmux.until(true) { |lines| assert_equal 'ls -testfile.txt', lines[-1] }835 ensure836 FileUtils.rm_rf('/tmp/fzf-test-single-flag')837 end838839 def test_double_flag_completion840 FileUtils.mkdir_p('/tmp/fzf-test-double-flag')841 FileUtils.touch('/tmp/fzf-test-double-flag/--testfile.txt')842 tmux.prepare843 tmux.send_keys 'cd /tmp/fzf-test-double-flag', :Enter844 tmux.prepare845 if shell == :fish846 tmux.send_keys 'ls --', 'C-t'847 else848 tmux.send_keys "ls --#{trigger}", :Tab849 end850851 tmux.until do |lines|852 assert_equal 1, lines.match_count853 assert_includes lines, '> --'854 end855 tmux.send_keys :Enter856 tmux.until(true) { |lines| assert_equal 'ls --testfile.txt', lines[-1] }857 ensure858 FileUtils.rm_rf('/tmp/fzf-test-double-flag')859 end860end861862class TestBash < TestBase863 include TestShell864 include CompletionTest865866 def shell867 :bash868 end869870 def new_shell871 tmux.prepare872 tmux.send_keys "FZF_TMUX=1 #{Shell.bash}", :Enter873 tmux.prepare874 end875876 def test_ctrl_r_delete877 tmux.prepare878 tmux.send_keys 'echo to-keep', :Enter879 tmux.prepare880 tmux.send_keys 'echo to-delete-1', :Enter881 tmux.prepare882 tmux.send_keys 'echo to-delete-2', :Enter883 tmux.prepare

bash: CTRL-R now supports multi-select and batch deletionJunegunn Choibefore adoptiona00df93

lines 884–885why, one step back
884 tmux.send_keys 'echo to-delete-3', :Enter
885 tmux.prepare

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 886–888why, one step back
886 tmux.send_keys 'echo another-keeper', :Enter
887 tmux.prepare888

bash: CTRL-R now supports multi-select and batch deletionJunegunn Choibefore adoptiona00df93

line 889why, one step back
889 # Open Ctrl-R and delete one entry

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 890–892why, one step back
890 tmux.send_keys 'C-r'
891 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }892 tmux.send_keys 'to-delete'

bash: CTRL-R now supports multi-select and batch deletionJunegunn Choibefore adoptiona00df93

lines 893–894why, one step back
893 tmux.until { |lines| assert_equal 3, lines.match_count }
894 tmux.send_keys 'S-Delete'

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 895why, one step back
895 tmux.until { |lines| assert_equal 2, lines.match_count }

bash: CTRL-R now supports multi-select and batch deletionJunegunn Choibefore adoptiona00df93

lines 896–899why, one step back
896
897 # Multi-select remaining two and delete them at once898 tmux.send_keys :BTab, :BTab899 tmux.until { |lines| assert_includes lines[-2], '(2)' }

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 900–901why, one step back
900 tmux.send_keys 'S-Delete'
901 tmux.until { |lines| assert_equal 0, lines.match_count }

bash: CTRL-R now supports multi-select and batch deletionJunegunn Choibefore adoptiona00df93

line 902why, one step back
902

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 903–967why, one step back
903 # Exit without selecting
904 tmux.send_keys :Escape905 tmux.prepare906907 # Verify deleted entries are gone from history908 tmux.send_keys 'C-r'909 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }910 tmux.send_keys 'to-delete'911 tmux.until { |lines| assert_equal 0, lines.match_count }912 tmux.send_keys :Escape913 tmux.prepare914915 # Verify kept entries are still there916 tmux.send_keys 'C-r'917 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }918 tmux.send_keys 'to-keep'919 tmux.until { |lines| assert_equal 1, lines.match_count }920 tmux.send_keys :Enter921 tmux.until { |lines| assert_equal 'echo to-keep', lines[-1] }922 tmux.send_keys 'C-c'923 end924925 def test_dynamic_completion_loader926 tmux.paste 'touch /tmp/foo; _fzf_completion_loader=1'927 tmux.paste '_completion_loader() { complete -o default fake; }'928 tmux.paste 'complete -F _fzf_path_completion -o default -o bashdefault fake'929 tmux.send_keys "fake /tmp/foo#{trigger}", :Tab930 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }931 tmux.send_keys 'C-c'932933 tmux.prepare934 tmux.send_keys 'fake /tmp/foo'935 tmux.send_keys :Tab, 'C-u'936937 tmux.prepare938 tmux.send_keys "fake /tmp/foo#{trigger}", :Tab939 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }940 end941end942943class TestZsh < TestBase944 include TestShell945 include CompletionTest946947 def shell948 :zsh949 end950951 def new_shell952 tmux.send_keys "FZF_TMUX=1 #{Shell.zsh}", :Enter953 tmux.prepare954 end955956 def test_complete_quoted_command957 tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter958 ['unset', '\unset', "'unset'"].each do |command|959 tmux.prepare960 tmux.send_keys "#{command} FZFFOOBR#{trigger}", :Tab961 tmux.until { |lines| assert_equal 1, lines.match_count }962 tmux.send_keys :Enter963 tmux.until { |lines| assert_equal "#{command} FZFFOOBAR", lines[-1] }964 tmux.send_keys 'C-c'965 end966 end967

test(zsh): verify chpwd fires once in alt-c widgetLangLangBartbefore adoptionca51a57

lines 968–975why, one step back
968 # Duplicate 'chpwd' calls overcount visits => skews rank tracking tools (e.g. 'zoxide')
969 def test_alt_c_chpwd_hook_once970 tmux.send_keys "chpwd() { echo 'chpwd hook fired' >&2 }", :Enter971 tmux.prepare972 tmux.send_keys :Escape, :c973 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }974 tmux.send_keys :Enter975 tmux.until do |lines|

Parenthesize an assert_equal argument in the zsh chpwd testJunegunn Choibefore adoption715d26f

line 976why, one step back
976 assert_equal(1, lines.count { |l| l.include?('chpwd hook fired') })

test(zsh): verify chpwd fires once in alt-c widgetLangLangBartbefore adoptionca51a57

lines 977–979why, one step back
977 end
978 end979

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 980–1013why, one step back
980 # Helper function to run test with Perl and again with Awk
981 def self.test_perl_and_awk(name, &block)982 define_method(:"test_#{name}") do983 instance_eval(&block)984 end985986 define_method(:"test_#{name}_awk") do987 tmux.send_keys "unset 'commands[perl]'", :Enter988 tmux.prepare989 # Verify perl is actually unset (0 = not found)990 tmux.send_keys 'echo ${+commands[perl]}', :Enter991 tmux.until { |lines| assert_equal '0', lines[-1] }992 tmux.prepare993 instance_eval(&block)994 end995 end996997 def prepare_ctrl_r_test998 tmux.send_keys ':', :Enter999 tmux.send_keys 'echo match-collision', :Enter1000 tmux.prepare1001 tmux.send_keys 'echo "line 1', :Enter, '2 line 2"', :Enter1002 tmux.prepare1003 tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter1004 tmux.prepare1005 tmux.send_keys 'echo "bar', :Enter, 'foo"', :Enter1006 tmux.prepare1007 tmux.send_keys 'echo "trailing_space "', :Enter1008 tmux.prepare1009 tmux.send_keys 'cat <<EOF | wc -c', :Enter, 'qux thud', :Enter, 'EOF', :Enter1010 tmux.prepare1011 tmux.send_keys 'C-l', 'C-r'1012 end1013

test(zsh): check capture for fzf exit status in widgetLangLangBartbefore adoption7129f9e

lines 1014–1027why, one step back
1014 test_perl_and_awk 'ctrl_r_exit_code' do
1015 exit_file = "#{tempname}-exit"1016 # Wrapper captures status, as widgets return values don't propagate to "$?"1017 # A non-zero status causes the shell to beep when the widget exits (man zshzle)1018 tmux.send_keys %(f() { zle fzf-history-widget; echo $? > #{exit_file}; zle reset-prompt } && zle -N f && bindkey "^R" f), :Enter1019 prepare_ctrl_r_test1020 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }1021 tmux.send_keys 'C-g' # abort1022 tmux.send_keys "cat #{exit_file}", :Enter1023 tmux.until { |lines| assert_equal '130', lines[-1] }1024 ensure1025 FileUtils.rm_f(exit_file)1026 end1027

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 1028–1172why, one step back
1028 test_perl_and_awk 'ctrl_r_accept_or_print_query' do
1029 set_var('FZF_CTRL_R_OPTS', '--bind enter:accept-or-print-query')1030 prepare_ctrl_r_test1031 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }1032 tmux.send_keys '1 foobar'1033 tmux.until { |lines| assert_equal 0, lines.match_count }1034 tmux.send_keys :Enter1035 tmux.until { |lines| assert_equal '1 foobar', lines[-1] }1036 end10371038 test_perl_and_awk 'ctrl_r_multiline_index_collision' do1039 tmux.send_keys 'setopt sh_glob', :Enter1040 # Leading number in multi-line history content is not confused with index1041 prepare_ctrl_r_test1042 tmux.send_keys "'line 1"1043 tmux.until { |lines| assert_equal 1, lines.match_count }1044 tmux.send_keys :Enter1045 tmux.until do |lines|1046 assert_equal ['echo "line 1', '2 line 2"'], lines[-2..]1047 end1048 end10491050 test_perl_and_awk 'ctrl_r_multi_selection' do1051 prepare_ctrl_r_test1052 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }1053 tmux.send_keys :BTab, :BTab, :BTab1054 tmux.until { |lines| assert_includes lines[-2], '(3)' }1055 tmux.send_keys :Enter1056 tmux.until do |lines|1057 assert_equal ['cat <<EOF | wc -c', 'qux thud', 'EOF', 'echo "trailing_space "', 'echo "bar', 'foo"'], lines[-6..]1058 end1059 end10601061 test_perl_and_awk 'ctrl_r_no_multi_selection' do1062 set_var('FZF_CTRL_R_OPTS', '--no-multi')1063 prepare_ctrl_r_test1064 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }1065 tmux.send_keys :BTab, :BTab, :BTab1066 tmux.until { |lines| refute_includes lines[-2], '(3)' }1067 tmux.send_keys :Enter1068 tmux.until do |lines|1069 assert_equal ['cat <<EOF | wc -c', 'qux thud', 'EOF'], lines[-3..]1070 end1071 end10721073 # NOTE: 'Perl/$history' won't see foreign cmds immediately, unlike 'awk/fc'.1074 # Perl passes only because another cmd runs between mocking and triggering C-r1075 # https://github.com/junegunn/fzf/issues/40611076 # https://zsh.org/mla/users/2024/msg00692.html1077 test_perl_and_awk 'ctrl_r_foreign_commands' do1078 histfile = "#{tempname}-foreign-hist"1079 tmux.send_keys "HISTFILE=#{histfile}", :Enter1080 tmux.prepare1081 # SHARE_HISTORY picks up foreign commands; marked with * in fc1082 tmux.send_keys 'setopt SHARE_HISTORY', :Enter1083 tmux.prepare1084 tmux.send_keys 'fzf_cmd_local', :Enter1085 tmux.prepare1086 # Mock foreign command (for testing only; don't edit your HISTFILE this way)1087 tmux.send_keys "echo ': 0:0;fzf_cmd_foreign' >> $HISTFILE", :Enter1088 tmux.prepare1089 # Verify fc shows foreign command with asterisk1090 tmux.send_keys 'fc -rl -1', :Enter1091 tmux.until { |lines| assert(lines.any? { |l| l.match?(/^\s*\d+\* fzf_cmd_foreign/) }) }1092 tmux.prepare1093 # Test ctrl-r correctly extracts the foreign command1094 tmux.send_keys 'C-r'1095 tmux.until { |lines| assert_operator lines.match_count, :>, 0 }1096 tmux.send_keys '^fzf_cmd_'1097 tmux.until { |lines| assert_equal 2, lines.match_count }1098 tmux.send_keys :BTab, :BTab1099 tmux.until { |lines| assert_includes lines[-2], '(2)' }1100 tmux.send_keys :Enter1101 tmux.until do |lines|1102 assert_equal %w[fzf_cmd_foreign fzf_cmd_local], lines[-2..]1103 end1104 ensure1105 FileUtils.rm_f(histfile)1106 end1107end11081109class TestFish < TestBase1110 include TestShell1111 include CompletionTest11121113 def shell1114 :fish1115 end11161117 def trigger1118 '++'1119 end11201121 def new_shell1122 tmux.send_keys 'env FZF_TMUX=1 XDG_CONFIG_HOME=/tmp/fzf-fish fish', :Enter1123 tmux.send_keys 'function fish_prompt; end; clear', :Enter1124 tmux.until { |lines| assert_empty lines }1125 end11261127 def set_var(name, val)1128 tmux.prepare1129 tmux.send_keys "set -g #{name} '#{val}'", :Enter1130 tmux.prepare1131 end11321133 def test_ctrl_r_multi1134 tmux.send_keys ':', :Enter1135 tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter1136 tmux.prepare1137 tmux.send_keys 'echo "bar', :Enter, 'foo"', :Enter1138 tmux.prepare1139 tmux.send_keys 'C-l', 'C-r'1140 offset = -61141 block = <<~BLOCK1142 echo "foo1143 bar"1144 echo "bar1145 foo"1146 BLOCK1147 if shell == :fish1148 offset = -41149 block = <<~FISH1150 echo "foo␊bar"1151 echo "bar␊foo"1152 FISH1153 end1154 tmux.until do |lines|1155 block.lines.each_with_index do |line, idx|1156 assert_includes lines[idx + offset], line.chomp1157 end1158 end1159 tmux.send_keys :BTab, :BTab1160 tmux.until { |lines| assert_includes lines[-2], '(2)' }1161 tmux.send_keys :Enter1162 block = <<~BLOCK1163 echo "bar1164 foo"1165 echo "foo1166 bar"1167 BLOCK1168 tmux.until do |lines|1169 assert_equal block.lines.map(&:chomp), lines1170 end1171 end1172end

shell: nushell integration scripts (#4630)Simon Désaulniersbefore adoption290b18d

lines 1173–1275why, one step back
1173
1174class TestNushell < TestBase1175 include TestShell11761177 def teardown1178 @tmux&.kill1179 end11801181 def shell1182 :nushell1183 end11841185 def set_var(name, val)1186 tmux.prepare1187 tmux.send_keys "$env.#{name} = '#{val}'", :Enter1188 tmux.prepare1189 end11901191 def unset_var(name)1192 tmux.prepare1193 tmux.send_keys "hide-env -i #{name}", :Enter1194 tmux.prepare1195 end11961197 def new_shell1198 tmux.send_keys 'FZF_TMUX=1 nu', :Enter1199 tmux.prepare1200 end12011202 # Override: Nushell's builtin `echo` outputs structured data, so we need1203 # `^echo` (external echo) for plain text output on the command line.1204 def test_ctrl_t_unicode1205 writelines(['fzf-unicode 테스트1', 'fzf-unicode 테스트2'])1206 set_var('FZF_CTRL_T_COMMAND', "cat #{tempname}")12071208 tmux.prepare1209 tmux.send_keys '^echo ', 'C-t'1210 tmux.until { |lines| assert_equal 2, lines.match_count }1211 tmux.send_keys 'fzf-unicode'1212 tmux.until { |lines| assert_equal 2, lines.match_count }12131214 tmux.send_keys '1'1215 tmux.until { |lines| assert_equal 1, lines.match_count }1216 tmux.send_keys :Tab1217 tmux.until { |lines| assert_equal 1, lines.select_count }12181219 tmux.send_keys :BSpace1220 tmux.until { |lines| assert_equal 2, lines.match_count }12211222 tmux.send_keys '2'1223 tmux.until { |lines| assert_equal 1, lines.match_count }1224 tmux.send_keys :Tab1225 tmux.until { |lines| assert_equal 2, lines.select_count }12261227 tmux.send_keys :Enter1228 tmux.until { |lines| assert_match(/\^echo .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines.join) }1229 tmux.send_keys :Enter1230 tmux.until { |lines| assert_equal 'fzf-unicode 테스트1 fzf-unicode 테스트2', lines[-1] }1231 end12321233 # Override: Nushell's external completer replaces the entire token,1234 # so we use assert_includes instead of assert_equal for the result.1235 # ~USERNAME expansion and backslash-escaped spaces are not applicable.1236 def test_file_completion1237 FileUtils.mkdir_p('/tmp/fzf-test')1238 (1..100).each { |i| FileUtils.touch("/tmp/fzf-test/#{i}") }1239 tmux.prepare12401241 # Multi-selection1242 tmux.send_keys "cat /tmp/fzf-test/10#{trigger}", :Tab1243 tmux.until { |lines| assert_equal 2, lines.match_count }1244 tmux.send_keys :Tab, :Tab1245 tmux.until { |lines| assert_equal 2, lines.select_count }1246 tmux.send_keys :Enter1247 tmux.until(true) do |lines|1248 assert_includes lines[-1].to_s, '/tmp/fzf-test/10'1249 assert_includes lines[-1].to_s, '/tmp/fzf-test/100'1250 end12511252 # Single selection1253 tmux.prepare1254 tmux.send_keys "cat /tmp/fzf-test/10#{trigger}", :Tab1255 tmux.until { |lines| assert_equal 2, lines.match_count }1256 tmux.send_keys '0'1257 tmux.until { |lines| assert_equal 1, lines.match_count }1258 tmux.send_keys :Enter1259 tmux.until(true) do |lines|1260 assert_includes lines[-1].to_s, '/tmp/fzf-test/100'1261 end12621263 # Should include hidden files1264 (1..100).each { |i| FileUtils.touch("/tmp/fzf-test/.hidden-#{i}") }1265 tmux.prepare1266 tmux.send_keys "cat /tmp/fzf-test/hidden#{trigger}", :Tab1267 tmux.until(true) do |lines|1268 assert_equal 100, lines.match_count1269 assert lines.any_include?('/tmp/fzf-test/.hidden-')1270 end1271 tmux.send_keys :Enter1272 ensure1273 FileUtils.rm_rf('/tmp/fzf-test')1274 end1275

[nushell] Quote paths inserted by CTRL-T (#4919)Junegunn Choibefore adoptionfe04475

lines 1276–1312why, one step back
1276 # Override: paths are inserted as Nushell string literals, so the
1277 # selections appear quoted on the command line.1278 def test_ctrl_t1279 set_var('FZF_CTRL_T_COMMAND', 'seq 100')12801281 tmux.prepare1282 tmux.send_keys 'C-t'1283 tmux.until { |lines| assert_equal 100, lines.match_count }1284 tmux.send_keys :Tab, :Tab, :Tab1285 tmux.until { |lines| assert lines.any_include?(' (3)') }1286 tmux.send_keys :Enter1287 tmux.until { |lines| assert lines.any_include?('"1" "2" "3"') }1288 tmux.send_keys 'C-c'1289 end12901291 # A path is inserted as a Nushell string literal, so that syntax in a file1292 # name is not evaluated and each path stays a single argument.1293 def test_ctrl_t_quoting1294 marker = "#{tempname}-marker"1295 FileUtils.rm_f(marker)1296 writelines(["fzf-inject$(touch #{marker}).txt", 'fzf-inject space.txt'])1297 set_var('FZF_CTRL_T_COMMAND', "cat #{tempname}")12981299 tmux.prepare1300 tmux.send_keys '^printf "%s\n" ', 'C-t'1301 tmux.until { |lines| assert_equal 2, lines.match_count }1302 tmux.send_keys :Tab, :Tab1303 tmux.until { |lines| assert_equal 2, lines.select_count }1304 tmux.send_keys :Enter1305 tmux.until { |lines| assert_includes lines[-1].to_s, '"fzf-inject$(touch' }1306 tmux.send_keys :Enter1307 tmux.until do |lines|1308 assert_equal ["fzf-inject$(touch #{marker}).txt", 'fzf-inject space.txt'], lines[-2..]1309 end1310 refute_path_exists marker1311 end1312

shell: nushell integration scripts (#4630)Simon Désaulniersbefore adoption290b18d

lines 1313–1329why, one step back
1313 # Nushell does not support multiline command recall the same way
1314 # as bash/zsh/fish, so test_ctrl_r_multiline is omitted.13151316 # Override: only test with 'foo' -- single and double quotes cause1317 # issues in Nushell's line editor.1318 def test_ctrl_r_abort1319 %w[foo].each do |query|1320 tmux.prepare1321 tmux.send_keys :Enter, query1322 tmux.until { |lines| assert lines[-1]&.start_with?(query) }1323 tmux.send_keys 'C-r'1324 tmux.until { |lines| assert_equal "> #{query}", lines[-1] }1325 tmux.send_keys 'C-g'1326 tmux.until { |lines| assert lines[-1]&.start_with?(query) }1327 end1328 end1329end