Do not export $LINES and $COLUMNS for non-preview processes

Fix #4164
This commit is contained in:
Junegunn Choi 2025-01-08 10:00:57 +09:00
parent fa3f706e71
commit 6783417504
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -1012,6 +1012,14 @@ func (t *Terminal) deferActivation() bool {
} }
func (t *Terminal) environ() []string { func (t *Terminal) environ() []string {
return t.environImpl(false)
}
func (t *Terminal) environForPreview() []string {
return t.environImpl(true)
}
func (t *Terminal) environImpl(forPreview bool) []string {
env := os.Environ() env := os.Environ()
if t.listenPort != nil { if t.listenPort != nil {
env = append(env, fmt.Sprintf("FZF_PORT=%d", *t.listenPort)) env = append(env, fmt.Sprintf("FZF_PORT=%d", *t.listenPort))
@ -1037,9 +1045,11 @@ func (t *Terminal) environ() []string {
if pwindowSize.Lines > 0 { if pwindowSize.Lines > 0 {
lines := fmt.Sprintf("LINES=%d", pwindowSize.Lines) lines := fmt.Sprintf("LINES=%d", pwindowSize.Lines)
columns := fmt.Sprintf("COLUMNS=%d", pwindowSize.Columns) columns := fmt.Sprintf("COLUMNS=%d", pwindowSize.Columns)
env = append(env, lines) if forPreview {
env = append(env, lines)
env = append(env, columns)
}
env = append(env, "FZF_PREVIEW_"+lines) env = append(env, "FZF_PREVIEW_"+lines)
env = append(env, columns)
env = append(env, "FZF_PREVIEW_"+columns) env = append(env, "FZF_PREVIEW_"+columns)
env = append(env, fmt.Sprintf("FZF_PREVIEW_TOP=%d", t.tui.Top()+t.pwindow.Top())) env = append(env, fmt.Sprintf("FZF_PREVIEW_TOP=%d", t.tui.Top()+t.pwindow.Top()))
env = append(env, fmt.Sprintf("FZF_PREVIEW_LEFT=%d", t.pwindow.Left())) env = append(env, fmt.Sprintf("FZF_PREVIEW_LEFT=%d", t.pwindow.Left()))
@ -4132,7 +4142,7 @@ func (t *Terminal) Loop() error {
if len(command) > 0 && t.canPreview() { if len(command) > 0 && t.canPreview() {
_, list := t.buildPlusList(command, false) _, list := t.buildPlusList(command, false)
t.cancelPreview() t.cancelPreview()
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environ()}) t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environForPreview()})
} }
} }
@ -4524,7 +4534,7 @@ func (t *Terminal) Loop() error {
if valid { if valid {
t.cancelPreview() t.cancelPreview()
t.previewBox.Set(reqPreviewEnqueue, t.previewBox.Set(reqPreviewEnqueue,
previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environ()}) previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environForPreview()})
} }
} else { } else {
// Discard the preview content so that it won't accidentally appear // Discard the preview content so that it won't accidentally appear