From 2b584586ed1caf15429625da981575ee35d407b8 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 9 Feb 2025 11:53:35 +0900 Subject: Add --accept-nth option to transform the output This option can be used to replace a sed or awk in the post-processing step. ps -ef | fzf --multi --header-lines 1 | awk '{print $2}' ps -ef | fzf --multi --header-lines 1 --accept-nth 2 This may not be a very "Unix-y" thing to do, so I've always felt that fzf shouldn't have such an option, but I've finally changed my mind because: * fzf can be configured with a custom delimiter that is a fixed string or a regular expression. * In such cases, you'd need to repeat the delimiter again in the post-processing step. * Also, tools like awk or sed may interpret a regular expression differently, causing mismatches. You can still use sed, cut, or awk if you prefer. Close #3987 Close #1323 --- src/tokenizer_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tokenizer_test.go') diff --git a/src/tokenizer_test.go b/src/tokenizer_test.go index 39f32dc8..a471a2fc 100644 --- a/src/tokenizer_test.go +++ b/src/tokenizer_test.go @@ -85,14 +85,14 @@ func TestTransform(t *testing.T) { { ranges, _ := splitNth("1,2,3") tx := Transform(tokens, ranges) - if joinTokens(tx) != "abc: def: ghi: " { + if JoinTokens(tx) != "abc: def: ghi: " { t.Errorf("%s", tx) } } { ranges, _ := splitNth("1..2,3,2..,1") tx := Transform(tokens, ranges) - if string(joinTokens(tx)) != "abc: def: ghi: def: ghi: jklabc: " || + if string(JoinTokens(tx)) != "abc: def: ghi: def: ghi: jklabc: " || len(tx) != 4 || tx[0].text.ToString() != "abc: def: " || tx[0].prefixLength != 2 || tx[1].text.ToString() != "ghi: " || tx[1].prefixLength != 14 || @@ -107,7 +107,7 @@ func TestTransform(t *testing.T) { { ranges, _ := splitNth("1..2,3,2..,1") tx := Transform(tokens, ranges) - if joinTokens(tx) != " abc: def: ghi: def: ghi: jkl abc:" || + if JoinTokens(tx) != " abc: def: ghi: def: ghi: jkl abc:" || len(tx) != 4 || tx[0].text.ToString() != " abc: def:" || tx[0].prefixLength != 0 || tx[1].text.ToString() != " ghi:" || tx[1].prefixLength != 12 || -- cgit v1.2.3