Skip to content
Myr

Export FZF_PREVIEW_LINES and FZF_PREVIEW_COLUMNS to preview process

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

fzf will still override LINES and COLUMNS as before but they may not hold the correct values depending on the default shell. Close #1314

authored by Junegunn Choi · committed by Junegunn Choi · parent 6c32148 · Browse files · 3 files+12 added−6 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+12 added−6 removed

  • tests:+1 added−1 removed
  • other:+11 added−5 removed

3 files+12 added−6 removed

modified:man/man1/fzf.1+5 added-2 removed
286 unmodified lines
287.RS288e.g. \fBfzf --preview='head -$LINES {}'\fR289 \fBls -l | fzf --preview="echo user={3} when={-4..-2}; cat {-1}" --header-lines=1\fR290291fzf overrides \fB$LINES\fR and \fB$COLUMNS\fR so that they represent the exact292size of the preview window.291fzf exports \fB$FZF_PREVIEW_LINES\fR and \fB$FZF_PREVIEW_COLUMNS\fR so that292they represent the exact size of the preview window. (It also overrides293\fB$LINES\fR and \fB$COLUMNS\fR with the same values but they can be reset294by the default shell, so prefer to refer to the ones with \fBFZF_PREVIEW_\fR295prefix.)296297A placeholder expression starting with \fB+\fR flag will be replaced to the298space-separated list of the selected lines (or the current line if no selection299was made) individually quoted.
338 unmodified lines
modified:src/terminal.go+6 added-3 removed
611 unmodified lines
612 if !t.preview.wrap && t.tui.DoesAutoWrap() {613 pwidth += 1614 }615 t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, tui.BorderNone)616 os.Setenv("FZF_PREVIEW_HEIGHT", strconv.Itoa(h-2))616 }617 switch t.preview.position {618 case posUp:619 pheight := calculateSize(height, t.preview.size, minHeight, 3)
870 unmodified lines
1490 t.ansi, t.delimiter, false, string(t.input), request)1491 cmd := util.ExecCommand(command, true)1492 if t.pwindow != nil {1493 env := os.Environ()1495 env = append(env, fmt.Sprintf("LINES=%d", t.pwindow.Height()))1496 env = append(env, fmt.Sprintf("COLUMNS=%d", t.pwindow.Width()))1494 lines := fmt.Sprintf("LINES=%d", t.pwindow.Height())1495 columns := fmt.Sprintf("COLUMNS=%d", t.pwindow.Width())1496 env = append(env, lines)1497 env = append(env, "FZF_PREVIEW_"+lines)1498 env = append(env, columns)1499 env = append(env, "FZF_PREVIEW_"+columns)1500 cmd.Env = env1501 }1502 var out bytes.Buffer1503 cmd.Stdout = &out
555 unmodified lines
modified:test/test_go.rb+1 added-1 removed
1369 unmodified lines
1370 tmux.until { |lines| lines[1].include?(' {5-1 3 4}') }1371 end13721373 def test_preview_hidden1374 tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-\\$LINES-\\$COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter1374 tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-\\$FZF_PREVIEW_LINES-\\$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter1375 tmux.until { |lines| lines[-1] == '>' }1376 tmux.send_keys '?'1377 tmux.until { |lines| lines[-2] =~ / {1-1-1-[0-9]+}/ }1378 tmux.send_keys '555'
536 unmodified lines