Skip to content
Myr

Allow suffix match on --nth with custom --delimiter

Before adoption: this commit came in with the history the project adopted, so no landing records it.

When --nth is used with a custom --delimiter, the last delimiter was included in the search scope, forcing you to write the delimiter in a suffix-match query. This commit removes the last delimiter from the search scope. # No need to write 'bar,$' echo foo,bar,baz | fzf --delimiter , --nth 2 --filter 'bar$' This can be seen as a breaking change, but I'm gonna say it's a bug fix. Fix #3983

authored by Junegunn Choi · committed by Junegunn Choi · parent 84e2262 · Browse files · 3 files+18 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+18 added−2 removed

  • tests:+6 added−0 removed
  • other:+12 added−2 removed

3 files+18 added−2 removed

modified:src/pattern.go+7 added-2 removed
430 unmodified lines
431 }432433 tokens := Tokenize(item.text.ToString(), p.delimiter)434 ret := Transform(tokens, p.nth)435 // TODO: We could apply StripLastDelimiter to exclude the last delimiter from436 // the search allowing suffix match with a string or a regex delimiter.435 // Strip the last delimiter to allow suffix match436 if len(ret) > 0 && !p.delimiter.IsAwk() {437 chars := ret[len(ret)-1].text438 stripped := StripLastDelimiter(chars.ToString(), p.delimiter)439 newChars := util.ToChars(stringBytes(stripped))440 ret[len(ret)-1].text = &newChars441 }442 item.transformed = &transformed{p.revision, ret}443 return ret444}445
15 unmodified lines
modified:src/tokenizer.go+5 added
76 unmodified lines
77 regex *regexp.Regexp78 str *string79}8081// IsAwk returns true if the delimiter is an AWK-style delimiter82func (d Delimiter) IsAwk() bool {83 return d.regex == nil && d.str == nil84}8586// String returns the string representation of a Delimiter.87func (d Delimiter) String() string {88 return fmt.Sprintf("Delimiter{regex: %v, str: &%q}", d.regex, *d.str)89}
227 unmodified lines
modified:test/test_filter.rb+6 added
50 unmodified lines
51 lines.last,52 `find . -print0 | #{FZF} --read0 -e -f "^#{lines.last}$"`.chomp53 end5455 def test_nth_suffix_match56 assert_equal \57 'foo,bar,baz',58 `echo foo,bar,baz | #{FZF} -d, -f'bar$' -n2`.chomp59 end6061 def test_with_nth_basic62 writelines(['hello world ', 'byebye'])63 assert_equal \64 'hello world ',
251 unmodified lines