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
Provenance
- Commit
8f0c915- Tree
e670530- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
0eefcf3
4 files changed+35 added−1 removed
modified:man/man1/fzf.1+2 added
1375 unmodified lines1376 .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"1382 1383 .SH EXTENDED SEARCH MODE1384 1385 Unless specified otherwise, fzf will start in "extended\-search mode". In this766 unmodified linesmodified:src/terminal.go+7 added
1303 unmodified lines1304 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 linesmodified:test/test_raw.rb+10 added-1 removed
3 unmodified lines4 5 # Testing raw mode6 class 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 }10 11 tmux.send_keys 112 tmux.until { assert_equal 272, it.match_count }50 unmodified lines63 assert_includes it, '>>11'64 assert_includes it, '▖ 10'65 end66 67+ tmux.send_keys :Down, :Space68+ tmux.until { assert_includes it, '[[0]] 11' }69+70+ tmux.send_keys :Up, :Space71+ tmux.until { assert_includes it, '[[1]] 11' }72+73 tmux.send_keys 'b'74 tmux.until do75 assert_equal 1, it.select_count76 assert_includes it, '▌ 110'77 assert_includes it, '>>11'78 end79+80+ tmux.send_keys :Space81+ tmux.until { assert_includes it, '[[]] 11' }82 end83 endmodified:CHANGELOG.md+16 added
48 unmodified lines49 # To unset the default 'dim' attribute, prefix the color spec with 'regular'50 fzf --raw --color hidden:regular:red:strikethrough51 ```52 53+#### Conditional actions for raw mode54+55+You may want to perform different actions depending on whether the current item56+is a match or not. For that, fzf now exports `$FZF_RAW` environment variable.57+58+It's:59+60+- Undefined if raw mode is disabled61+- `1` if the current item is a match62+- `0` otherwise63+64+```sh65+# Do not allow selecting non-matching items66+fzf --raw --bind 'enter:transform:[[ ${FZF_RAW-1} = 1 ]] && echo accept || echo bell'67+```68+69 #### Leveraging raw mode in shell integration70 71 The `CTRL-R` binding (command history) now lets you toggle raw mode with72 `CTRL-X`.2840 unmodified lines