m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-13 05:43:48 -05:00

ADD $FZF_DIRECTION

This commit is contained in:
Junegunn Choi
2025-10-04 22:50:33 +09:00
parent e1de29bc40
commit 9ace1351ff
4 changed files with 22 additions and 0 deletions

View File

@@ -132,6 +132,20 @@ fzf --gutter ' ' --color gutter:reverse
As noted above, the `--gutter-raw CHAR` option was also added for customizing the gutter column in raw mode. As noted above, the `--gutter-raw CHAR` option was also added for customizing the gutter column in raw mode.
### Added environment variable
`$FZF_DIRECTION` is now exported to child processes, indicating the list direction of the current layout.
- `up` for the default layout
- `down` for `reverse` or `reverse-list`
This simplifies writing transform actions involving layout-dependent actions
like `{up,down}-match`, `{up,down}-selected`, and `toggle+{up,down}`.
```sh
fzf --raw --bind 'result:first+transform:[[ $FZF_RAW = 0 ]] && echo $FZF_DIRECTION-match'
```
### Breaking changes ### Breaking changes
#### Hiding the gutter column #### Hiding the gutter column

View File

@@ -1335,6 +1335,8 @@ fzf exports the following environment variables to its child processes.
.br .br
.BR FZF_COLUMNS " Number of columns fzf takes up excluding padding and margin" .BR FZF_COLUMNS " Number of columns fzf takes up excluding padding and margin"
.br .br
.BR FZF_DIRECTION " Direction of the list (\fBup\fR or \fBdown\fR)"
.br
.BR FZF_TOTAL_COUNT " Total number of items" .BR FZF_TOTAL_COUNT " Total number of items"
.br .br
.BR FZF_MATCH_COUNT " Number of matched items" .BR FZF_MATCH_COUNT " Number of matched items"

View File

@@ -1307,6 +1307,11 @@ func (t *Terminal) environImpl(forPreview bool) []string {
env = append(env, "FZF_LIST_LABEL="+t.listLabelOpts.label) env = append(env, "FZF_LIST_LABEL="+t.listLabelOpts.label)
env = append(env, "FZF_INPUT_LABEL="+t.inputLabelOpts.label) env = append(env, "FZF_INPUT_LABEL="+t.inputLabelOpts.label)
env = append(env, "FZF_HEADER_LABEL="+t.headerLabelOpts.label) env = append(env, "FZF_HEADER_LABEL="+t.headerLabelOpts.label)
direction := "down"
if t.layout == layoutDefault {
direction = "up"
}
env = append(env, "FZF_DIRECTION="+direction)
if len(t.nthCurrent) > 0 { if len(t.nthCurrent) > 0 {
env = append(env, "FZF_NTH="+RangesToString(t.nthCurrent)) env = append(env, "FZF_NTH="+RangesToString(t.nthCurrent))
} }

View File

@@ -1682,6 +1682,7 @@ class TestCore < TestInteractive
tmux.send_keys %(seq 100 | #{FZF} --multi --reverse --preview-window 0 --preview 'env | grep ^FZF_ | sort > #{tempname}' --no-input --bind enter:show-input+refresh-preview,space:disable-search+refresh-preview), :Enter tmux.send_keys %(seq 100 | #{FZF} --multi --reverse --preview-window 0 --preview 'env | grep ^FZF_ | sort > #{tempname}' --no-input --bind enter:show-input+refresh-preview,space:disable-search+refresh-preview), :Enter
expected = { expected = {
FZF_DIRECTION: 'down',
FZF_TOTAL_COUNT: '100', FZF_TOTAL_COUNT: '100',
FZF_MATCH_COUNT: '100', FZF_MATCH_COUNT: '100',
FZF_SELECT_COUNT: '0', FZF_SELECT_COUNT: '0',