Add environment variables: FZF_{BORDER,PREVIEW}_LABEL (#3693)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
The environment variable get the value of the preview label, even if it has been updated with an action. It can be useful to track the label of the preview and be able to switch between previews using only one binding.
authored by Matthieu Cneude · committed by GitHub · parent 8a74976 · Browse files · 4 files·+44 added−2 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
4 files+44 added−2 removed
- tests:+21 added−0 removed
- other:+23 added−2 removed
Provenance
- Commit
f625c5a- Tree
304dcb5- Author
Matthieu Cneude <Phantas0s@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
8a74976
4 files changed+44 added−2 removed
modified:man/man1/fzf.1+4 added
973 unmodified lines974 .BR FZF_QUERY " Current query string"975 .br976 .BR FZF_PROMPT " Prompt string"977 .br978+.BR FZF_PREVIEW_LABEL " Preview label string"979+.br980+.BR FZF_BORDER_LABEL " Border label string"981+.br982 .BR FZF_ACTION " The name of the last action performed"983 .br984 .BR FZF_PORT " Port number when --listen option is used"985 .br538 unmodified linesmodified:src/terminal.go+8 added-2 removed
850 unmodified lines851 }852 env = append(env, "FZF_QUERY="+string(t.input))853 env = append(env, "FZF_ACTION="+t.lastAction.Name())854 env = append(env, "FZF_PROMPT="+string(t.promptString))855+ env = append(env, "FZF_PREVIEW_LABEL="+t.previewLabelOpts.label)856+ env = append(env, "FZF_BORDER_LABEL="+t.borderLabelOpts.label)857 env = append(env, fmt.Sprintf("FZF_TOTAL_COUNT=%d", t.count))858 env = append(env, fmt.Sprintf("FZF_MATCH_COUNT=%d", t.merger.Length()))859 env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected)))860 env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))2616 unmodified lines3477 } else {3478 req(reqHeader)3479 }3480 case actChangeBorderLabel:3481+ t.borderLabelOpts.label = a.a3482 if t.border != nil {3483 t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(a.a, &tui.ColBorderLabel, false)3484 req(reqRedrawBorderLabel)3485 }3486 case actChangePreviewLabel:3487+ t.previewLabelOpts.label = a.a3488 if t.pborder != nil {3489 t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(a.a, &tui.ColPreviewLabel, false)3490 req(reqRedrawPreviewLabel)3491 }1 unmodified line3493 body := t.executeCommand(a.a, false, true, true, false)3494 actions := parseSingleActionList(strings.Trim(body, "\r\n"), func(message string) {})3495 return doActions(actions)3496 case actTransformBorderLabel:3497+ label := t.executeCommand(a.a, false, true, true, true)3498+ t.borderLabelOpts.label = label3499 if t.border != nil {3494- label := t.executeCommand(a.a, false, true, true, true)3500 t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(label, &tui.ColBorderLabel, false)3501 req(reqRedrawBorderLabel)3502 }3503 case actTransformPreviewLabel:3504+ label := t.executeCommand(a.a, false, true, true, true)3505+ t.previewLabelOpts.label = label3506 if t.pborder != nil {3500- label := t.executeCommand(a.a, false, true, true, true)3507 t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(label, &tui.ColPreviewLabel, false)3508 req(reqRedrawPreviewLabel)3509 }3510 case actChangePrompt:738 unmodified linesmodified:test/test_go.rb+21 added
2875 unmodified lines2876 assert_includes(_1[-2], '─barfoo╯')2877 end2878 end2879 2880+ def test_labels_variables2881+ tmux.send_keys ': | fzf --border --border-label foobar --preview "echo \$FZF_BORDER_LABEL // \$FZF_PREVIEW_LABEL" --preview-label barfoo --bind "space:change-border-label(barbaz)+change-preview-label(bazbar)+refresh-preview,enter:transform-border-label(echo 123)+transform-preview-label(echo 456)+refresh-preview"', :Enter2882+ tmux.until do2883+ assert_includes(_1[0], '─foobar─')2884+ assert_includes(_1[1], '─barfoo─')2885+ assert_includes(_1[2], ' foobar // barfoo ')2886+ end2887+ tmux.send_keys :Space2888+ tmux.until do2889+ assert_includes(_1[0], '─barbaz─')2890+ assert_includes(_1[1], '─bazbar─')2891+ assert_includes(_1[2], ' barbaz // bazbar ')2892+ end2893+ tmux.send_keys :Enter2894+ tmux.until do2895+ assert_includes(_1[0], '─123─')2896+ assert_includes(_1[1], '─456─')2897+ assert_includes(_1[2], ' 123 // 456 ')2898+ end2899+ end2900+2901 def test_info_separator_unicode2902 tmux.send_keys 'seq 100 | fzf -q55', :Enter2903 tmux.until { assert_includes(_1[-2], ' 1/100 ─') }2904 end824 unmodified linesmodified:CHANGELOG.md+11 added
1 unmodified line2 =========3 4 0.49.05 ------6+- Added two environment variables exported to the child processes7+ - `FZF_PREVIEW_LABEL`8+ - `FZF_BORDER_LABEL`9+ ```sh10+ # Use the current value of $FZF_PREVIEW_LABEL to determine which actions to perform11+ git ls-files |12+ fzf --header 'Press CTRL-P to change preview mode' \13+ --bind='ctrl-p:transform:[[ $FZF_PREVIEW_LABEL =~ cat ]] \14+ && echo "change-preview(git log --color=always \{})+change-preview-label([[ log ]])" \15+ || echo "change-preview(bat --color=always \{})+change-preview-label([[ cat ]])"'16+ ```17 - Renamed `track` action to `track-current` to highlight the difference between the global tracking state set by `--track` and a one-off tracking action18 - `track` is still available as an alias19 - Added `untrack-current` and `toggle-track-current` actions20 - `*-current` actions are no-op when the global tracking state is set1951 unmodified lines