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/pattern.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/pattern.go') diff --git a/src/pattern.go b/src/pattern.go index 29149fe7..8919ad87 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -403,6 +403,8 @@ func (p *Pattern) transformInput(item *Item) []Token { tokens := Tokenize(item.text.ToString(), p.delimiter) ret := Transform(tokens, p.nth) + // TODO: We could apply StripLastDelimiter to exclude the last delimiter from + // the search allowing suffix match with a string or a regex delimiter. item.transformed = &transformed{p.revision, ret} return ret } -- cgit v1.2.3