Skip to content
Myr

Add $FZF_RAW for conditional actions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 0eefcf3 · Browse files · 4 files+35 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+35 added−1 removed

  • tests:+10 added−1 removed
  • other:+25 added−0 removed

4 files+35 added−1 removed

modified:man/man1/fzf.1+2 added
1375 unmodified lines
1376.br1377.BR FZF_PREVIEW_LINES " Number of lines in the preview window"1378.br1379.BR FZF_PREVIEW_COLUMNS " Number of columns in the preview window"1380.br1381.BR FZF_RAW " Only in raw mode. 1 if the current item matches, 0 otherwise"13821383.SH EXTENDED SEARCH MODE13841385Unless specified otherwise, fzf will start in "extended\-search mode". In this
766 unmodified lines
modified:src/terminal.go+7 added
1303 unmodified lines
1304 env = append(env, "FZF_HEADER_LABEL="+t.headerLabelOpts.label)1305 if len(t.nthCurrent) > 0 {1306 env = append(env, "FZF_NTH="+RangesToString(t.nthCurrent))1307 }1308 if t.raw {1309 val := "0"1310 if t.isCurrentItemMatch() {1311 val = "1"1312 }1313 env = append(env, "FZF_RAW="+val)1314 }1315 inputState := "enabled"1316 if t.inputless {1317 inputState = "hidden"1318 } else if t.paused {
5918 unmodified lines
modified:test/test_raw.rb+10 added-1 removed
3 unmodified lines
45# Testing raw mode6class TestRaw < TestInteractive7 def test_raw_mode8 tmux.send_keys %(seq 1000 | #{FZF} --raw --bind ctrl-x:toggle-raw,a:enable-raw,b:disable-raw --gutter '▌' --multi), :Enter8 tmux.send_keys %(seq 1000 | #{FZF} --raw --bind ctrl-x:toggle-raw,a:enable-raw,b:disable-raw --gutter '▌' --multi --bind 'space:transform-prompt:echo "[[$FZF_RAW]] "'), :Enter9 tmux.until { assert_equal 1000, it.match_count }1011 tmux.send_keys 112 tmux.until { assert_equal 272, it.match_count }
50 unmodified lines
63 assert_includes it, '>>11'64 assert_includes it, '▖ 10'65 end6667 tmux.send_keys :Down, :Space68 tmux.until { assert_includes it, '[[0]] 11' }6970 tmux.send_keys :Up, :Space71 tmux.until { assert_includes it, '[[1]] 11' }7273 tmux.send_keys 'b'74 tmux.until do75 assert_equal 1, it.select_count76 assert_includes it, '▌ 110'77 assert_includes it, '>>11'78 end7980 tmux.send_keys :Space81 tmux.until { assert_includes it, '[[]] 11' }82 end83end
modified:CHANGELOG.md+16 added
48 unmodified lines
49# To unset the default 'dim' attribute, prefix the color spec with 'regular'50fzf --raw --color hidden:regular:red:strikethrough51```5253#### Conditional actions for raw mode5455You may want to perform different actions depending on whether the current item56is a match or not. For that, fzf now exports `$FZF_RAW` environment variable.5758It's:5960- Undefined if raw mode is disabled61- `1` if the current item is a match62- `0` otherwise6364```sh65# Do not allow selecting non-matching items66fzf --raw --bind 'enter:transform:[[ ${FZF_RAW-1} = 1 ]] && echo accept || echo bell'67```6869#### Leveraging raw mode in shell integration7071The `CTRL-R` binding (command history) now lets you toggle raw mode with72`CTRL-X`.
2840 unmodified lines