summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md7
-rw-r--r--man/man1/fzf.12
-rw-r--r--src/terminal.go1
-rwxr-xr-xtest/test_go.rb11
4 files changed, 21 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 920bceff..c550c173 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,13 @@ CHANGELOG
0.51.0
------
+- Added a new environment variable `$FZF_POS` exported to the child processes. It's the vertical position of the cursor in the list starting from 1.
+ ```sh
+ # Toggle selection to the top or to the bottom
+ seq 30 | fzf --multi --bind 'load:pos(10)' \
+ --bind 'shift-up:transform:for _ in $(seq $FZF_POS $FZF_MATCH_COUNT); do echo -n +toggle-up; done' \
+ --bind 'shift-down:transform:for _ in $(seq 1 $FZF_POS); do echo -n +toggle-down; done'
+ ```
- Added `--with-shell` option to start child processes with a custom shell command and flags
```sh
gem list | fzf --with-shell 'ruby -e' \
diff --git a/man/man1/fzf.1 b/man/man1/fzf.1
index 742fba5a..8e79c2e4 100644
--- a/man/man1/fzf.1
+++ b/man/man1/fzf.1
@@ -984,6 +984,8 @@ fzf exports the following environment variables to its child processes.
.br
.BR FZF_SELECT_COUNT " Number of selected items"
.br
+.BR FZF_POS " Vertical position of the cursor in the list starting from 1"
+.br
.BR FZF_QUERY " Current query string"
.br
.BR FZF_PROMPT " Prompt string"
diff --git a/src/terminal.go b/src/terminal.go
index 8d114e1b..e9ec363b 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -856,6 +856,7 @@ func (t *Terminal) environ() []string {
env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected)))
env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))
env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))
+ env = append(env, fmt.Sprintf("FZF_POS=%d", util.Min(t.merger.Length(), t.cy+1)))
return env
}
diff --git a/test/test_go.rb b/test/test_go.rb
index f58b789e..2f93403c 100755
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -3250,6 +3250,17 @@ class TestGoFZF < TestBase
tmux.send_keys :Up
tmux.until { |lines| assert_includes lines, '> 2' }
end
+
+ def test_fzf_pos
+ tmux.send_keys "seq 100 | #{FZF} --preview 'echo $FZF_POS / $FZF_MATCH_COUNT'", :Enter
+ tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 100') }) }
+ tmux.send_keys :Up
+ tmux.until { |lines| assert(lines.any? { |line| line.include?('2 / 100') }) }
+ tmux.send_keys '99'
+ tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 1') }) }
+ tmux.send_keys '99'
+ tmux.until { |lines| assert(lines.any? { |line| line.include?('0 / 0') }) }
+ end
end
module TestShell