mirror of https://github.com/Llewellynvdm/fzf.git
Add environment variables: FZF_{BORDER,PREVIEW}_LABEL (#3693)
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. Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit is contained in:
parent
8a74976c1f
commit
f625c5aabe
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -3,6 +3,17 @@ CHANGELOG
|
|||
|
||||
0.49.0
|
||||
------
|
||||
- Added two environment variables exported to the child processes
|
||||
- `FZF_PREVIEW_LABEL`
|
||||
- `FZF_BORDER_LABEL`
|
||||
```sh
|
||||
# Use the current value of $FZF_PREVIEW_LABEL to determine which actions to perform
|
||||
git ls-files |
|
||||
fzf --header 'Press CTRL-P to change preview mode' \
|
||||
--bind='ctrl-p:transform:[[ $FZF_PREVIEW_LABEL =~ cat ]] \
|
||||
&& echo "change-preview(git log --color=always \{})+change-preview-label([[ log ]])" \
|
||||
|| echo "change-preview(bat --color=always \{})+change-preview-label([[ cat ]])"'
|
||||
```
|
||||
- Renamed `track` action to `track-current` to highlight the difference between the global tracking state set by `--track` and a one-off tracking action
|
||||
- `track` is still available as an alias
|
||||
- Added `untrack-current` and `toggle-track-current` actions
|
||||
|
|
|
@ -975,6 +975,10 @@ fzf exports the following environment variables to its child processes.
|
|||
.br
|
||||
.BR FZF_PROMPT " Prompt string"
|
||||
.br
|
||||
.BR FZF_PREVIEW_LABEL " Preview label string"
|
||||
.br
|
||||
.BR FZF_BORDER_LABEL " Border label string"
|
||||
.br
|
||||
.BR FZF_ACTION " The name of the last action performed"
|
||||
.br
|
||||
.BR FZF_PORT " Port number when --listen option is used"
|
||||
|
|
|
@ -852,6 +852,8 @@ func (t *Terminal) environ() []string {
|
|||
env = append(env, "FZF_QUERY="+string(t.input))
|
||||
env = append(env, "FZF_ACTION="+t.lastAction.Name())
|
||||
env = append(env, "FZF_PROMPT="+string(t.promptString))
|
||||
env = append(env, "FZF_PREVIEW_LABEL="+t.previewLabelOpts.label)
|
||||
env = append(env, "FZF_BORDER_LABEL="+t.borderLabelOpts.label)
|
||||
env = append(env, fmt.Sprintf("FZF_TOTAL_COUNT=%d", t.count))
|
||||
env = append(env, fmt.Sprintf("FZF_MATCH_COUNT=%d", t.merger.Length()))
|
||||
env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected)))
|
||||
|
@ -3476,11 +3478,13 @@ func (t *Terminal) Loop() {
|
|||
req(reqHeader)
|
||||
}
|
||||
case actChangeBorderLabel:
|
||||
t.borderLabelOpts.label = a.a
|
||||
if t.border != nil {
|
||||
t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(a.a, &tui.ColBorderLabel, false)
|
||||
req(reqRedrawBorderLabel)
|
||||
}
|
||||
case actChangePreviewLabel:
|
||||
t.previewLabelOpts.label = a.a
|
||||
if t.pborder != nil {
|
||||
t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(a.a, &tui.ColPreviewLabel, false)
|
||||
req(reqRedrawPreviewLabel)
|
||||
|
@ -3490,14 +3494,16 @@ func (t *Terminal) Loop() {
|
|||
actions := parseSingleActionList(strings.Trim(body, "\r\n"), func(message string) {})
|
||||
return doActions(actions)
|
||||
case actTransformBorderLabel:
|
||||
label := t.executeCommand(a.a, false, true, true, true)
|
||||
t.borderLabelOpts.label = label
|
||||
if t.border != nil {
|
||||
label := t.executeCommand(a.a, false, true, true, true)
|
||||
t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(label, &tui.ColBorderLabel, false)
|
||||
req(reqRedrawBorderLabel)
|
||||
}
|
||||
case actTransformPreviewLabel:
|
||||
label := t.executeCommand(a.a, false, true, true, true)
|
||||
t.previewLabelOpts.label = label
|
||||
if t.pborder != nil {
|
||||
label := t.executeCommand(a.a, false, true, true, true)
|
||||
t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(label, &tui.ColPreviewLabel, false)
|
||||
req(reqRedrawPreviewLabel)
|
||||
}
|
||||
|
|
|
@ -2877,6 +2877,27 @@ class TestGoFZF < TestBase
|
|||
end
|
||||
end
|
||||
|
||||
def test_labels_variables
|
||||
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"', :Enter
|
||||
tmux.until do
|
||||
assert_includes(_1[0], '─foobar─')
|
||||
assert_includes(_1[1], '─barfoo─')
|
||||
assert_includes(_1[2], ' foobar // barfoo ')
|
||||
end
|
||||
tmux.send_keys :Space
|
||||
tmux.until do
|
||||
assert_includes(_1[0], '─barbaz─')
|
||||
assert_includes(_1[1], '─bazbar─')
|
||||
assert_includes(_1[2], ' barbaz // bazbar ')
|
||||
end
|
||||
tmux.send_keys :Enter
|
||||
tmux.until do
|
||||
assert_includes(_1[0], '─123─')
|
||||
assert_includes(_1[1], '─456─')
|
||||
assert_includes(_1[2], ' 123 // 456 ')
|
||||
end
|
||||
end
|
||||
|
||||
def test_info_separator_unicode
|
||||
tmux.send_keys 'seq 100 | fzf -q55', :Enter
|
||||
tmux.until { assert_includes(_1[-2], ' 1/100 ─') }
|
||||
|
|
Loading…
Reference in New Issue