diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cd8bea3..cf93b0f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 0.73.0 ------ - Timer-driven `every(N)` event for `--bind`, where `N` is seconds (fractional, floored to `0.01`). Ticks that overlap an in-flight action are coalesced, so a slow `reload` cannot accumulate a backlog. +- New `FZF_CURRENT_ITEM` environment variable exported to child processes, holding the text of the current item. Useful on shells where quoting `{}` is awkward (e.g. PowerShell on Windows). Unset when the list is empty (#4802). - New `FZF_IDLE_TIME` (whole seconds) and `FZF_IDLE_TIME_MS` (milliseconds) environment variables exported to child processes, holding the elapsed time since the last user activity. Pair with `every(N)` to build idle-based behavior such as auto-accept or auto-quit (#1211). ```sh # Live process list; --track --id-nth 2 keeps the cursor on the same PID across reloads diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 93f157fe..18fc8525 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -1475,6 +1475,8 @@ fzf exports the following environment variables to its child processes. .br .BR FZF_POS " Vertical position of the cursor in the list starting from 1" .br +.BR FZF_CURRENT_ITEM " Text of the current item (unset if the list is empty)" +.br .BR FZF_WRAP " The line wrapping mode (char, word) when enabled" .br .BR FZF_QUERY " Current query string" diff --git a/src/terminal.go b/src/terminal.go index 2a11ea37..47c41a59 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1438,6 +1438,9 @@ func (t *Terminal) environImpl(forPreview bool) []string { 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", min(t.merger.Length(), t.cy+1))) + if item := t.currentItem(); item != nil { + env = append(env, "FZF_CURRENT_ITEM="+item.AsString(t.ansi)) + } env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_LINE=%d", t.clickHeaderLine)) env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_COLUMN=%d", t.clickHeaderColumn)) env = append(env, fmt.Sprintf("FZF_CLICK_FOOTER_LINE=%d", t.clickFooterLine)) diff --git a/test/test_core.rb b/test/test_core.rb index d4acf103..119b94cd 100644 --- a/test/test_core.rb +++ b/test/test_core.rb @@ -2286,6 +2286,7 @@ class TestCore < TestInteractive FZF_ACTION: 'start', FZF_KEY: '', FZF_POS: '1', + FZF_CURRENT_ITEM: '1', FZF_QUERY: '', FZF_POINTER: '>', FZF_PROMPT: '> ', @@ -2301,12 +2302,12 @@ class TestCore < TestInteractive end tmux.send_keys :Tab, :Tab tmux.until do - expected.merge!(FZF_ACTION: 'toggle-down', FZF_KEY: 'tab', FZF_POS: '3', FZF_SELECT_COUNT: '2') + expected.merge!(FZF_ACTION: 'toggle-down', FZF_KEY: 'tab', FZF_POS: '3', FZF_CURRENT_ITEM: '3', FZF_SELECT_COUNT: '2') assert_equal expected, env_vars.slice(*expected.keys) end tmux.send_keys '99' tmux.until do - expected.merge!(FZF_ACTION: 'char', FZF_KEY: '9', FZF_QUERY: '99', FZF_MATCH_COUNT: '1', FZF_POS: '1') + expected.merge!(FZF_ACTION: 'char', FZF_KEY: '9', FZF_QUERY: '99', FZF_MATCH_COUNT: '1', FZF_POS: '1', FZF_CURRENT_ITEM: '99') assert_equal expected, env_vars.slice(*expected.keys) end tmux.send_keys :Space