From b712f2bb6a5c1eed5661072604e308951ef655f2 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 16 Jan 2025 09:23:25 +0900 Subject: Export the current nth value as $FZF_NTH --- src/terminal.go | 3 +++ src/tokenizer.go | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/terminal.go b/src/terminal.go index 1f1e2ba0..7e7de9d6 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1046,6 +1046,9 @@ func (t *Terminal) environImpl(forPreview bool) []string { env = append(env, "FZF_PREVIEW_LABEL="+t.previewLabelOpts.label) env = append(env, "FZF_BORDER_LABEL="+t.borderLabelOpts.label) env = append(env, "FZF_LIST_LABEL="+t.listLabelOpts.label) + if len(t.nthCurrent) > 0 { + env = append(env, "FZF_NTH="+RangesToString(t.nthCurrent)) + } env = append(env, fmt.Sprintf("FZF_TOTAL_COUNT=%d", t.count)) env = append(env, fmt.Sprintf("FZF_MATCH_COUNT=%d", t.merger.Length())) env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected))) diff --git a/src/tokenizer.go b/src/tokenizer.go index 7f4aef48..fade1d10 100644 --- a/src/tokenizer.go +++ b/src/tokenizer.go @@ -18,6 +18,32 @@ type Range struct { end int } +func RangesToString(ranges []Range) string { + strs := []string{} + for _, r := range ranges { + s := "" + if r.begin == rangeEllipsis && r.end == rangeEllipsis { + s = ".." + } else if r.begin == r.end { + s = strconv.Itoa(r.begin) + } else { + if r.begin != rangeEllipsis { + s += strconv.Itoa(r.begin) + } + + if r.begin != -1 { + s += ".." + if r.end != rangeEllipsis { + s += strconv.Itoa(r.end) + } + } + } + strs = append(strs, s) + } + + return strings.Join(strs, ",") +} + // Token contains the tokenized part of the strings and its prefix length type Token struct { text *util.Chars @@ -41,7 +67,7 @@ func (d Delimiter) String() string { } func newRange(begin int, end int) Range { - if begin == 1 { + if begin == 1 && end != 1 { begin = rangeEllipsis } if end == -1 { -- cgit v1.2.3