From 710ebdf9c14e0c88b0cfc843ce08edcdd4554571 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 26 Feb 2025 00:24:41 +0900 Subject: Make --accept-nth compatible with --select-1 Fix #4287 --- src/core.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/core.go') diff --git a/src/core.go b/src/core.go index d639769d..404af12a 100644 --- a/src/core.go +++ b/src/core.go @@ -476,8 +476,17 @@ func Run(opts *Options) (int, error) { if len(opts.Expect) > 0 { opts.Printer("") } + transformer := func(item *Item) string { + return item.AsString(opts.Ansi) + } + if opts.AcceptNth != nil { + fn := opts.AcceptNth(opts.Delimiter) + transformer = func(item *Item) string { + return item.acceptNth(opts.Ansi, opts.Delimiter, fn) + } + } for i := 0; i < count; i++ { - opts.Printer(val.Get(i).item.AsString(opts.Ansi)) + opts.Printer(transformer(val.Get(i).item)) } if count == 0 { exitCode = ExitNoMatch -- cgit v1.2.3