Skip to content
Myr

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

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

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

authored by Jack Bates · committed by GitHub · parent 7bf1f2c · Browse files · 3 files+64 added−54 removed
This commit

State

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

Trailers

  • Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>

Diff stats

3 files+64 added−54 removed

  • tests:+25 added−24 removed
  • other:+39 added−30 removed

3 files+64 added−54 removed

modified:shell/key-bindings.bash+38 added-29 removed
modified:test/test_go.rb+25 added-24 removed
82 unmodified lines
83 end84end8586class Tmux87 TEMPNAME = '/tmp/fzf-test.txt'8887 attr_reader :win8889 def initialize(shell = :bash)90 @win = go("new-window -d -P -F '#I' '#{Shell.send(shell)}'").first
35 unmodified lines
126 system('tmux', 'setb', str, ';', 'pasteb', '-t', win, ';', 'send-keys', '-t', win, 'Enter')127 end128129 def capture(pane = 0)132 File.unlink TEMPNAME while File.exist? TEMPNAME133 wait do134 go("capture-pane -t #{win}.#{pane} \\; save-buffer #{TEMPNAME} 2> /dev/null")135 $CHILD_STATUS.exitstatus.zero?136 end137 File.read(TEMPNAME).split($INPUT_RECORD_SEPARATOR).reverse.drop_while(&:empty?).reverse130 go("capture-pane -p -t #{win}.#{pane}")131 end132133 def until(refresh = false, pane = 0)134 lines = nil
1595 unmodified lines
1730end17311732module TestShell1733 def setup1741 super1734 @tmux = Tmux.new shell1735 tmux.prepare1736 end17371738 def teardown1739 @tmux.kill
108 unmodified lines
1848 tmux.send_keys :Enter1849 tmux.until { |lines| lines[-1] == '3rd' }1850 end18511852 def test_ctrl_r_abort1853 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 < 41854 tmux.send_keys 'foo'1855 tmux.until { |lines| lines[-1].start_with? 'foo' }1856 tmux.send_keys 'C-r'1857 tmux.until { |lines| lines[-1].start_with? '>' }1858 tmux.send_keys 'C-g'1859 tmux.until { |lines| lines[-1].start_with? 'foo' }1860 end18611862 def retries(times = 3)1863 (times - 1).times do1864 begin1865 return yield
181 unmodified lines
2047class TestBash < TestBase2048 include TestShell2049 include CompletionTest20502051 def shell2052 :bash2053 end20542055 def new_shell2056 tmux.prepare2057 tmux.send_keys "FZF_TMUX=1 #{Shell.bash}", :Enter2058 tmux.prepare2059 end20602053 def setup2054 super2055 @tmux = Tmux.new :bash2056 end20572061 def test_dynamic_completion_loader2062 tmux.paste 'touch /tmp/foo; _fzf_completion_loader=1'2063 tmux.paste '_completion_loader() { complete -o default fake; }'2064 tmux.paste 'complete -F _fzf_path_completion -o default -o bashdefault fake'
14 unmodified lines
2079class TestZsh < TestBase2080 include TestShell2081 include CompletionTest20822083 def shell2084 :zsh2085 end20862087 def new_shell2088 tmux.send_keys "FZF_TMUX=1 #{Shell.zsh}", :Enter2089 tmux.prepare2090 end20842085 def setup2086 super2087 @tmux = Tmux.new :zsh2088 end2091end20922093class TestFish < TestBase2094 include TestShell20952096 def shell2097 :fish2098 end20992100 def new_shell2101 tmux.send_keys 'env FZF_TMUX=1 fish', :Enter2102 tmux.send_keys 'function fish_prompt; end; clear', :Enter2103 tmux.until(&:empty?)
3 unmodified lines
2107 tmux.prepare2108 tmux.send_keys "set -g #{name} '#{val}'", :Enter2109 tmux.prepare2110 end21052106 def setup2107 super2108 @tmux = Tmux.new :fish2109 end2111end21122113__END__2114# Setup fzf
15 unmodified lines
modified:.travis.yml+1 added-1 removed