Rename FZF_IDLE_TIME to FZF_IDLE_MS

Seconds resolution is too coarse to combine with sub-second every()
bindings. Switching to milliseconds gives idle-based scripts useful
resolution at any every() interval.
This commit is contained in:
Junegunn Choi
2026-05-16 18:11:26 +09:00
parent 07f3b00bd4
commit 4364dc1d24
4 changed files with 14 additions and 12 deletions
+3 -3
View File
@@ -4,15 +4,15 @@ CHANGELOG
0.73.0 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. - 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_IDLE_TIME` environment variable (whole seconds since the last user activity) exported to child processes. Pair with `every(N)` to build idle-based behavior such as auto-accept or auto-quit (#1211). - New `FZF_IDLE_MS` environment variable (milliseconds since the last user activity) exported to child processes. Pair with `every(N)` to build idle-based behavior such as auto-accept or auto-quit (#1211).
```sh ```sh
# Live process list; --track --id-nth 2 keeps the cursor on the same PID across reloads # Live process list; --track --id-nth 2 keeps the cursor on the same PID across reloads
fzf --header-lines 1 --track --id-nth 2 --bind 'start,every(2):reload-sync:ps -ef' fzf --header-lines 1 --track --id-nth 2 --bind 'start,every(2):reload-sync:ps -ef'
# Auto-accept after 10 seconds of inactivity, with a countdown in the footer after 5s # Auto-accept after 10 seconds of inactivity, with a countdown in the footer after 5s
fzf --bind 'every(1):bg-transform: fzf --bind 'every(1):bg-transform:
if [[ $FZF_IDLE_TIME -lt 5 ]]; then echo change-footer: if [[ $FZF_IDLE_MS -lt 5000 ]]; then echo change-footer:
elif [[ $FZF_IDLE_TIME -lt 10 ]]; then echo "change-footer:auto-accept in $((10 - FZF_IDLE_TIME))s" elif [[ $FZF_IDLE_MS -lt 10000 ]]; then echo "change-footer:auto-accept in $(((10000 - FZF_IDLE_MS) / 1000))s"
else echo accept else echo accept
fi' fi'
``` ```
+6 -5
View File
@@ -1500,7 +1500,7 @@ fzf exports the following environment variables to its child processes.
.br .br
.BR FZF_KEY " The name of the last key pressed" .BR FZF_KEY " The name of the last key pressed"
.br .br
.BR FZF_IDLE_TIME " Whole seconds since the last user activity" .BR FZF_IDLE_MS " Milliseconds since the last user activity"
.br .br
.BR FZF_PORT " Port number when \-\-listen option is used" .BR FZF_PORT " Port number when \-\-listen option is used"
.br .br
@@ -1947,8 +1947,9 @@ Triggered every \fIN\fR seconds (\fIN\fR can be a fractional number, e.g.
\fB0.5\fR). The minimum interval is \fB0.01\fR seconds; values are floored \fB0.5\fR). The minimum interval is \fB0.01\fR seconds; values are floored
to that. to that.
Combine with the \fBFZF_IDLE_TIME\fR environment variable (seconds since Combine with the \fBFZF_IDLE_MS\fR environment variable (milliseconds
last user activity) to build idle\-based behavior without a separate event. since the last user activity) to build idle\-based behavior without a
separate event.
e.g. e.g.
\fB# Live process list, refreshed every 2 seconds. \fB# Live process list, refreshed every 2 seconds.
@@ -1958,8 +1959,8 @@ e.g.
# Auto\-accept after 10 seconds of inactivity, with a countdown in the footer after 5s. # Auto\-accept after 10 seconds of inactivity, with a countdown in the footer after 5s.
fzf \-\-bind 'every(1):bg\-transform: fzf \-\-bind 'every(1):bg\-transform:
if [[ $FZF_IDLE_TIME \-lt 5 ]]; then echo change\-footer: if [[ $FZF_IDLE_MS \-lt 5000 ]]; then echo change\-footer:
elif [[ $FZF_IDLE_TIME \-lt 10 ]]; then echo "change\-footer:auto\-accept in $((10 \- FZF_IDLE_TIME))s" elif [[ $FZF_IDLE_MS \-lt 10000 ]]; then echo "change\-footer:auto\-accept in $(((10000 \- FZF_IDLE_MS) / 1000))s"
else echo accept else echo accept
fi'\fR fi'\fR
.RE .RE
+1 -1
View File
@@ -1389,7 +1389,7 @@ func (t *Terminal) environImpl(forPreview bool) []string {
env = append(env, "FZF_QUERY="+string(t.input)) env = append(env, "FZF_QUERY="+string(t.input))
env = append(env, "FZF_ACTION="+t.lastAction.Name()) env = append(env, "FZF_ACTION="+t.lastAction.Name())
env = append(env, "FZF_KEY="+t.lastKey) env = append(env, "FZF_KEY="+t.lastKey)
env = append(env, fmt.Sprintf("FZF_IDLE_TIME=%d", int(time.Since(t.lastActivity).Seconds()))) env = append(env, fmt.Sprintf("FZF_IDLE_MS=%d", time.Since(t.lastActivity).Milliseconds()))
env = append(env, "FZF_PROMPT="+string(t.promptString)) env = append(env, "FZF_PROMPT="+string(t.promptString))
env = append(env, "FZF_GHOST="+string(t.ghost)) env = append(env, "FZF_GHOST="+string(t.ghost))
env = append(env, "FZF_POINTER="+string(t.pointer)) env = append(env, "FZF_POINTER="+string(t.pointer))
+4 -3
View File
@@ -1431,9 +1431,10 @@ class TestCore < TestInteractive
assert_includes tmux.capture[-3], 'STOPPED' assert_includes tmux.capture[-3], 'STOPPED'
end end
def test_fzf_idle_time_env def test_fzf_idle_ms_env
# FZF_IDLE_TIME, combined with every(), implements idle-based behavior. # FZF_IDLE_MS, combined with every(), implements idle-based behavior.
tmux.send_keys %(seq 100 | fzf --bind 'every(0.5):transform-header(echo "idle=$FZF_IDLE_TIME")'), :Enter # Print seconds derived from milliseconds for stable assertions.
tmux.send_keys %(seq 100 | fzf --bind 'every(0.2):transform-header(echo "idle=$((FZF_IDLE_MS / 1000))")'), :Enter
tmux.until { |lines| assert_equal 100, lines.match_count } tmux.until { |lines| assert_equal 100, lines.match_count }
# Idle counter advances without any input # Idle counter advances without any input
tmux.until { |lines| assert_includes lines[-3], 'idle=1' } tmux.until { |lines| assert_includes lines[-3], 'idle=1' }