m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-16 07:13:48 -05:00

[bash] Start C-r search with current command line (#1886)

Restore the original line when search is aborted. Add --query
"$READLINE_LINE" and fall back to the current behavior pre Bash 4.

Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit is contained in:
Jack Bates
2020-02-28 02:47:13 -07:00
committed by GitHub
parent 7bf1f2cc84
commit 7c447bbdc7
3 changed files with 64 additions and 54 deletions

View File

@@ -84,8 +84,6 @@ class Shell
end
class Tmux
TEMPNAME = '/tmp/fzf-test.txt'
attr_reader :win
def initialize(shell = :bash)
@@ -129,12 +127,7 @@ class Tmux
end
def capture(pane = 0)
File.unlink TEMPNAME while File.exist? TEMPNAME
wait do
go("capture-pane -t #{win}.#{pane} \\; save-buffer #{TEMPNAME} 2> /dev/null")
$CHILD_STATUS.exitstatus.zero?
end
File.read(TEMPNAME).split($INPUT_RECORD_SEPARATOR).reverse.drop_while(&:empty?).reverse
go("capture-pane -p -t #{win}.#{pane}")
end
def until(refresh = false, pane = 0)
@@ -1738,7 +1731,8 @@ end
module TestShell
def setup
super
@tmux = Tmux.new shell
tmux.prepare
end
def teardown
@@ -1855,6 +1849,16 @@ module TestShell
tmux.until { |lines| lines[-1] == '3rd' }
end
def test_ctrl_r_abort
skip "doesn't restore the original line when search is aborted pre Bash 4" if shell == :bash && /(?<= version )\d+/.match(`#{Shell.bash} --version`).to_s.to_i < 4
tmux.send_keys 'foo'
tmux.until { |lines| lines[-1].start_with? 'foo' }
tmux.send_keys 'C-r'
tmux.until { |lines| lines[-1].start_with? '>' }
tmux.send_keys 'C-g'
tmux.until { |lines| lines[-1].start_with? 'foo' }
end
def retries(times = 3)
(times - 1).times do
begin
@@ -2044,17 +2048,16 @@ class TestBash < TestBase
include TestShell
include CompletionTest
def shell
:bash
end
def new_shell
tmux.prepare
tmux.send_keys "FZF_TMUX=1 #{Shell.bash}", :Enter
tmux.prepare
end
def setup
super
@tmux = Tmux.new :bash
end
def test_dynamic_completion_loader
tmux.paste 'touch /tmp/foo; _fzf_completion_loader=1'
tmux.paste '_completion_loader() { complete -o default fake; }'
@@ -2077,20 +2080,23 @@ class TestZsh < TestBase
include TestShell
include CompletionTest
def shell
:zsh
end
def new_shell
tmux.send_keys "FZF_TMUX=1 #{Shell.zsh}", :Enter
tmux.prepare
end
def setup
super
@tmux = Tmux.new :zsh
end
end
class TestFish < TestBase
include TestShell
def shell
:fish
end
def new_shell
tmux.send_keys 'env FZF_TMUX=1 fish', :Enter
tmux.send_keys 'function fish_prompt; end; clear', :Enter
@@ -2102,11 +2108,6 @@ class TestFish < TestBase
tmux.send_keys "set -g #{name} '#{val}'", :Enter
tmux.prepare
end
def setup
super
@tmux = Tmux.new :fish
end
end
__END__