diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index aea5fea..89d7f93 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -272,14 +272,17 @@ string, specify field index expressions between the braces (See \fBFIELD INDEX EXPRESSION\fR for the details). .RS -e.g. \fBfzf --preview="head -$LINES {}"\fR +e.g. \fBfzf --preview='head -$LINES {}'\fR \fBls -l | fzf --preview="echo user={3} when={-4..-2}; cat {-1}" --header-lines=1\fR +fzf overrides \fB$LINES\fR and \fB$COLUMNS\fR so that they represent the exact +size of the preview window. + A placeholder expression starting with \fB+\fR flag will be replaced to the space-separated list of the selected lines (or the current line if no selection was made) individually quoted. -e.g. \fBfzf --multi --preview="head -10 {+}"\fR +e.g. \fBfzf --multi --preview='head -10 {+}'\fR \fBgit log --oneline | fzf --multi --preview 'git show {+1}'\fR Also, \fB{q}\fR is replaced to the current query string. diff --git a/src/terminal.go b/src/terminal.go index bc1c2ae..2da2e4c 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1368,6 +1368,12 @@ func (t *Terminal) Loop() { command := replacePlaceholder(t.preview.command, t.ansi, t.delimiter, false, string(t.input), request) cmd := util.ExecCommand(command) + if t.pwindow != nil { + env := os.Environ() + env = append(env, fmt.Sprintf("LINES=%d", t.pwindow.Height())) + env = append(env, fmt.Sprintf("COLUMNS=%d", t.pwindow.Width())) + cmd.Env = env + } out, _ := cmd.CombinedOutput() t.reqBox.Set(reqPreviewDisplay, string(out)) } else { diff --git a/test/test_go.rb b/test/test_go.rb index ec495c6..b3dc1c0 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -1319,12 +1319,12 @@ class TestGoFZF < TestBase end def test_preview_hidden - tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter + tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-\\$LINES-\\$COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter tmux.until { |lines| lines[-1] == '>' } tmux.send_keys '?' - tmux.until { |lines| lines[-2].include?(' {1-1}') } + tmux.until { |lines| lines[-2].match?(/ {1-1-1-[0-9]+}/) } tmux.send_keys '555' - tmux.until { |lines| lines[-2].include?(' {555-555}') } + tmux.until { |lines| lines[-2].match?(/ {555-555-1-[0-9]+}/) } tmux.send_keys '?' tmux.until { |lines| lines[-1] == '> 555' } end