Skip to content
Myr

Accept comma-separated list of sort criteria

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

authored by Junegunn Choi · committed by Junegunn Choi · parent d635b3f · Browse files · 12 files+298 added−120 removed
This commit

State

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

Diff stats

12 files+298 added−120 removed

  • tests:+122 added−22 removed
  • other:+176 added−98 removed

12 files+298 added−120 removed

modified:man/man1/fzf.1+12 added-3 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf 1 "Dec 2015" "fzf 0.11.1" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Jan 2016" "fzf 0.11.2" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
38 unmodified lines
67.RS68e.g. \fBhistory | fzf --tac --no-sort\fR69.RE70.TP71.BI "--tiebreak=" "CRI"72Sort criterion to use when the scores are tied71.BI "--tiebreak=" "CRI[,..]"72Comma-separated list of sort criteria to apply when the scores are tied.73.br74.R ""75.br76.BR length " Prefers item with shorter length"
3 unmodified lines
80.BR end " Prefers item with matched substring closer to the end"81.br82.BR index " Prefers item that appeared earlier in the input stream"83.br84.R ""85.br86- Each criterion should appear only once in the list87.br88- \fBindex\fR is only allowed at the end of the list89.br90- \fBindex\fR is implicitly appended to the list when not specified91.br92- Default is \fBlength\fR (or equivalently \fBlength\fR,index)93.SS Interface94.TP95.B "-m, --multi"96Enable multi-select with tab/shift-tab
344 unmodified lines
modified:src/chunklist_test.go+9 added-3 removed
4 unmodified lines
5 "testing"6)78func TestChunkList(t *testing.T) {9 // FIXME global10 sortCriteria = []criterion{byMatchLen, byLength, byIndex}1112 cl := NewChunkList(func(s []byte, i int) *Item {10 return &Item{text: []rune(string(s)), rank: Rank{0, 0, uint32(i * 2)}}13 return &Item{text: []rune(string(s)), rank: buildEmptyRank(int32(i * 2))}14 })1516 // Snapshot17 snapshot, count := cl.Snapshot()
20 unmodified lines
38 chunk1 := snapshot[0]39 if len(*chunk1) != 2 {40 t.Error("Snapshot should contain only two items")41 }42 last := func(arr []int32) int32 {43 return arr[len(arr)-1]44 }39 if string((*chunk1)[0].text) != "hello" || (*chunk1)[0].rank.index != 0 ||40 string((*chunk1)[1].text) != "world" || (*chunk1)[1].rank.index != 2 {45 if string((*chunk1)[0].text) != "hello" || last((*chunk1)[0].rank) != 0 ||46 string((*chunk1)[1].text) != "world" || last((*chunk1)[1].rank) != 2 {47 t.Error("Invalid data")48 }49 if chunk1.IsFull() {50 t.Error("Chunk should not have been marked full yet")
30 unmodified lines
modified:src/core.go+16 added-6 removed
50 unmodified lines
51func Run(opts *Options) {52 initProcs()5354 sort := opts.Sort > 055 rankTiebreak = opts.Tiebreak55 sortCriteria = opts.Criteria5657 if opts.Version {58 fmt.Println(version)59 os.Exit(exitOk)
42 unmodified lines
102 }103 runes, colors := ansiProcessor(data)104 return &Item{105 text: runes,106 index: uint32(index),106 index: int32(index),107 colors: colors,108 rank: Rank{0, 0, uint32(index)}}108 rank: buildEmptyRank(int32(index))}109 })110 } else {111 chunkList = NewChunkList(func(data []byte, index int) *Item {112 runes := util.BytesToRunes(data)
6 unmodified lines
119 }120 item := Item{121 text: joinTokens(trans),122 origText: &runes,123 index: uint32(index),123 index: int32(index),124 colors: nil,125 rank: Rank{0, 0, uint32(index)}}125 rank: buildEmptyRank(int32(index))}126127 trimmed, colors := ansiProcessorRunes(item.text)128 item.text = trimmed129 item.colors = colors
10 unmodified lines
140 go reader.ReadSource()141 }142143 // Matcher144 forward := true145 for _, cri := range opts.Criteria[1:] {146 if cri == byEnd {147 forward = false148 break149 }150 if cri == byBegin {151 break152 }153 }154 patternBuilder := func(runes []rune) *Pattern {155 return BuildPattern(146 opts.Fuzzy, opts.Extended, opts.Case, opts.Tiebreak != byEnd,156 opts.Fuzzy, opts.Extended, opts.Case, forward,157 opts.Nth, opts.Delimiter, runes)158 }159 matcher := NewMatcher(patternBuilder, sort, opts.Tac, eventBox)160
133 unmodified lines
modified:src/item_test.go+16 added-13 removed
21 unmodified lines
22 }23}2425func TestRankComparison(t *testing.T) {26 if compareRanks(Rank{3, 0, 5}, Rank{2, 0, 7}, false) ||27 !compareRanks(Rank{3, 0, 5}, Rank{3, 0, 6}, false) ||28 !compareRanks(Rank{1, 2, 3}, Rank{1, 3, 2}, false) ||29 !compareRanks(Rank{0, 0, 0}, Rank{0, 0, 0}, false) {26 if compareRanks([]int32{3, 0, 5}, []int32{2, 0, 7}, false) ||27 !compareRanks([]int32{3, 0, 5}, []int32{3, 0, 6}, false) ||28 !compareRanks([]int32{1, 2, 3}, []int32{1, 3, 2}, false) ||29 !compareRanks([]int32{0, 0, 0}, []int32{0, 0, 0}, false) {30 t.Error("Invalid order")31 }3233 if compareRanks(Rank{3, 0, 5}, Rank{2, 0, 7}, true) ||34 !compareRanks(Rank{3, 0, 5}, Rank{3, 0, 6}, false) ||35 !compareRanks(Rank{1, 2, 3}, Rank{1, 3, 2}, true) ||36 !compareRanks(Rank{0, 0, 0}, Rank{0, 0, 0}, false) {33 if compareRanks([]int32{3, 0, 5}, []int32{2, 0, 7}, true) ||34 !compareRanks([]int32{3, 0, 5}, []int32{3, 0, 6}, false) ||35 !compareRanks([]int32{1, 2, 3}, []int32{1, 3, 2}, true) ||36 !compareRanks([]int32{0, 0, 0}, []int32{0, 0, 0}, false) {37 t.Error("Invalid order (tac)")38 }39}4041// Match length, string length, index42func TestItemRank(t *testing.T) {43 // FIXME global44 sortCriteria = []criterion{byMatchLen, byLength, byIndex}4546 strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")}47 item1 := Item{text: strs[0], index: 1, offsets: []Offset{}}48 rank1 := item1.Rank(true)46 if rank1.matchlen != math.MaxUint16 || rank1.tiebreak != 3 || rank1.index != 1 {49 if rank1[0] != math.MaxInt32 || rank1[1] != 3 || rank1[2] != 1 {50 t.Error(item1.Rank(true))51 }52 // Only differ in index53 item2 := Item{text: strs[0], index: 0, offsets: []Offset{}}
11 unmodified lines
65 t.Error(items)66 }6768 // Sort by relevance66 item3 := Item{text: strs[1], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}67 item4 := Item{text: strs[1], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}68 item5 := Item{text: strs[2], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}69 item6 := Item{text: strs[2], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}69 item3 := Item{text: strs[1], rank: []int32{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}70 item4 := Item{text: strs[1], rank: []int32{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}71 item5 := Item{text: strs[2], rank: []int32{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}72 item6 := Item{text: strs[2], rank: []int32{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}73 items = []*Item{&item1, &item2, &item3, &item4, &item5, &item6}74 sort.Sort(ByRelevance(items))75 if items[0] != &item6 || items[1] != &item4 ||76 items[2] != &item5 || items[3] != &item3 ||
32 unmodified lines
modified:src/item.go+63 added-47 removed
18 unmodified lines
19type Item struct {20 text []rune21 origText *[]rune22 transformed []Token23 index uint3223 index int3224 offsets []Offset25 colors []ansiOffset26 rank Rank26 rank []int3227}2829// Rank is used to sort the search result30type Rank struct {31 matchlen uint1632 tiebreak uint1633 index uint3229// Sort criteria to use. Never changes once fzf is started.30var sortCriteria []criterion3132func isRankValid(rank []int32) bool {33 // Exclude ordinal index34 for i := 0; i < len(rank)-1; i++ {35 if rank[i] > 0 {36 return true37 }38 }39 return false40}4136// Tiebreak criterion to use. Never changes once fzf is started.37var rankTiebreak tiebreak42func buildEmptyRank(index int32) []int32 {43 len := len(sortCriteria)44 arr := make([]int32, len)45 arr[len-1] = index46 return arr47}4849// Rank calculates rank of the Item40func (item *Item) Rank(cache bool) Rank {41 if cache && (item.rank.matchlen > 0 || item.rank.tiebreak > 0) {50func (item *Item) Rank(cache bool) []int32 {51 if cache && isRankValid(item.rank) {52 return item.rank53 }54 matchlen := 055 prevEnd := 0
17 unmodified lines
73 matchlen += end - begin74 }75 }76 if matchlen == 0 {67 matchlen = math.MaxUint1677 matchlen = math.MaxInt3278 }79 rank := make([]int32, len(sortCriteria))80 for idx, criterion := range sortCriteria {81 var val int3282 switch criterion {69 var tiebreak uint1670 switch rankTiebreak {71 case byLength:72 // It is guaranteed that .transformed in not null in normal execution73 if item.transformed != nil {74 // If offsets is empty, lenSum will be 0, but we don't care75 tiebreak = uint16(lenSum)76 } else {77 tiebreak = uint16(len(item.text))83 case byMatchLen:84 val = int32(matchlen)85 case byLength:86 // It is guaranteed that .transformed in not null in normal execution87 if item.transformed != nil {88 // If offsets is empty, lenSum will be 0, but we don't care89 val = int32(lenSum)90 } else {91 val = int32(len(item.text))92 }93 case byBegin:94 // We can't just look at item.offsets[0][0] because it can be an inverse term95 val = int32(minBegin)96 case byEnd:97 if prevEnd > 0 {98 val = int32(1 + len(item.text) - prevEnd)99 } else {100 // Empty offsets due to inverse terms.101 val = 1102 }103 case byIndex:104 val = item.index105 }79 case byBegin:80 // We can't just look at item.offsets[0][0] because it can be an inverse term81 tiebreak = uint16(minBegin)82 case byEnd:83 if prevEnd > 0 {84 tiebreak = uint16(1 + len(item.text) - prevEnd)85 } else {86 // Empty offsets due to inverse terms.87 tiebreak = 188 }89 case byIndex:90 tiebreak = 1106 rank[idx] = val107 }92 rank := Rank{uint16(matchlen), tiebreak, item.index}108 if cache {109 item.rank = rank110 }111 return rank
156 unmodified lines
268269 return compareRanks(irank, jrank, true)270}271257func compareRanks(irank Rank, jrank Rank, tac bool) bool {258 if irank.matchlen < jrank.matchlen {259 return true260 } else if irank.matchlen > jrank.matchlen {261 return false272func compareRanks(irank []int32, jrank []int32, tac bool) bool {273 lastIdx := len(irank) - 1274 for idx, left := range irank {275 right := jrank[idx]276 if tac && idx == lastIdx {277 left = left * -1278 right = right * -1279 }280 if left < right {281 return true282 } else if left > right {283 return false284 }285 }263264 if irank.tiebreak < jrank.tiebreak {265 return true286 return true266 } else if irank.tiebreak > jrank.tiebreak {267 return false268 }269270 return (irank.index <= jrank.index) != tac287}
modified:src/merger_test.go+1 added-1 removed
21 unmodified lines
22 offsets[idx] = Offset{sidx, eidx}23 }24 return &Item{25 text: []rune(str),26 index: rand.Uint32(),26 index: rand.Int31(),27 offsets: offsets}28}2930func TestEmptyMerger(t *testing.T) {
63 unmodified lines
modified:src/merger.go+1 added-1 removed
86 unmodified lines
87}8889func (mg *Merger) mergedGet(idx int) *Item {90 for i := len(mg.merged); i <= idx; i++ {91 minRank := Rank{0, 0, 0}91 minRank := buildEmptyRank(0)92 minIdx := -193 for listIdx, list := range mg.lists {94 cursor := mg.cursors[listIdx]95 if cursor < 0 || cursor == len(list) {
23 unmodified lines
modified:src/options.go+45 added-20 removed
25 unmodified lines
26 --with-nth=N[,..] Transform item using index expressions within finder27 -d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)28 +s, --no-sort Do not sort the result29 --tac Reverse the order of the input30 --tiebreak=CRITERION Sort criterion when the scores are tied;30 --tiebreak=CRI[,..] Comma-separated list of sort criteria to apply31 when the scores are tied;32 [length|begin|end|index] (default: length)3334 Interface35 -m, --multi Enable multi-select with tab/shift-tab
39 unmodified lines
75 CaseRespect76)7778// Sort criteria78type tiebreak int79type criterion int8081const (81 byLength tiebreak = iota82 byMatchLen criterion = iota83 byLength84 byBegin85 byEnd86 byIndex87)
11 unmodified lines
99 WithNth []Range100 Delimiter Delimiter101 Sort int102 Tac bool101 Tiebreak tiebreak103 Criteria []criterion104 Multi bool105 Ansi bool106 Mouse bool107 Theme *curses.ColorTheme
38 unmodified lines
146 WithNth: make([]Range, 0),147 Delimiter: Delimiter{},148 Sort: 1000,149 Tac: false,148 Tiebreak: byLength,150 Criteria: []criterion{byMatchLen, byLength, byIndex},151 Multi: false,152 Ansi: false,153 Mouse: true,154 Theme: defaultTheme(),
207 unmodified lines
362 }363 return chords364}365364func parseTiebreak(str string) tiebreak {365 switch strings.ToLower(str) {366 case "length":367 return byLength368 case "index":369 return byIndex370 case "begin":371 return byBegin372 case "end":373 return byEnd374 default:375 errorExit("invalid sort criterion: " + str)366func parseTiebreak(str string) []criterion {367 criteria := []criterion{byMatchLen}368 hasIndex := false369 hasLength := false370 hasBegin := false371 hasEnd := false372 check := func(notExpected *bool, name string) {373 if *notExpected {374 errorExit("duplicate sort criteria: " + name)375 }376 if hasIndex {377 errorExit("index should be the last criterion")378 }379 *notExpected = true380 }377 return byLength381 for _, str := range strings.Split(strings.ToLower(str), ",") {382 switch str {383 case "index":384 check(&hasIndex, "index")385 criteria = append(criteria, byIndex)386 case "length":387 check(&hasLength, "length")388 criteria = append(criteria, byLength)389 case "begin":390 check(&hasBegin, "begin")391 criteria = append(criteria, byBegin)392 case "end":393 check(&hasEnd, "end")394 criteria = append(criteria, byEnd)395 default:396 errorExit("invalid sort criterion: " + str)397 }398 }399 if !hasIndex {400 criteria = append(criteria, byIndex)401 }402 return criteria403}404405func dupeTheme(theme *curses.ColorTheme) *curses.ColorTheme {406 if theme != nil {
332 unmodified lines
739 opts.Filter = &filter740 case "--expect":741 opts.Expect = parseKeyChords(nextString(allArgs, &i, "key names required"), "key names required")742 case "--tiebreak":718 opts.Tiebreak = parseTiebreak(nextString(allArgs, &i, "sort criterion required"))743 opts.Criteria = parseTiebreak(nextString(allArgs, &i, "sort criterion required"))744 case "--bind":745 keymap, opts.Execmap, opts.ToggleSort =746 parseKeymap(keymap, opts.Execmap, opts.ToggleSort, nextString(allArgs, &i, "bind expression required"))747 case "--color":
126 unmodified lines
874 opts.ToggleSort = true875 } else if match, value := optString(arg, "--expect="); match {876 opts.Expect = parseKeyChords(value, "key names required")877 } else if match, value := optString(arg, "--tiebreak="); match {853 opts.Tiebreak = parseTiebreak(value)878 opts.Criteria = parseTiebreak(value)879 } else if match, value := optString(arg, "--color="); match {880 opts.Theme = parseTheme(opts.Theme, value)881 } else if match, value := optString(arg, "--bind="); match {882 keymap, opts.Execmap, opts.ToggleSort =
66 unmodified lines
modified:src/pattern.go+1 added-1 removed
307 unmodified lines
308 transformed: item.transformed,309 index: item.index,310 offsets: offsets,311 colors: item.colors,312 rank: Rank{0, 0, item.index}}312 rank: buildEmptyRank(item.index)}313}314315func (p *Pattern) basicMatch(item *Item) (int, int, int) {316 input := p.prepareInput(item)
57 unmodified lines
modified:src/terminal.go+3 added-3 removed
48 unmodified lines
49 count int50 progress int51 reading bool52 merger *Merger53 selected map[uint32]selectedItem53 selected map[int32]selectedItem54 reqBox *util.EventBox55 eventBox *util.EventBox56 mutex sync.Mutex57 initFunc func()
164 unmodified lines
222 header0: header,223 ansi: opts.Ansi,224 reading: true,225 merger: EmptyMerger,226 selected: make(map[uint32]selectedItem),226 selected: make(map[int32]selectedItem),227 reqBox: util.NewEventBox(),228 eventBox: eventBox,229 mutex: sync.Mutex{},230 suppress: true,
234 unmodified lines
465 item := &Item{466 text: []rune(trimmed),467 index: 0,468 colors: colors,469 rank: Rank{0, 0, 0}}469 rank: buildEmptyRank(0)}470471 t.move(line, 2, true)472 t.printHighlighted(item, false, C.ColHeader, 0, false)473 }
682 unmodified lines
modified:test/test_go.rb+122 added-22 removed
457 unmodified lines
458 end459460 def test_unicode_case461 writelines tempname, %w[строКА1 СТРОКА2 строка3 Строка4]462 assert_equal %w[СТРОКА2 Строка4], `cat #{tempname} | #{FZF} -fС`.split($/)463 assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `cat #{tempname} | #{FZF} -fс`.split($/)462 assert_equal %w[СТРОКА2 Строка4], `#{FZF} -fС < #{tempname}`.split($/)463 assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `#{FZF} -fс < #{tempname}`.split($/)464 end465466 def test_tiebreak467 input = %w[
3 unmodified lines
471 -------foobar-472 ]473 writelines tempname, input474475 assert_equal input, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=index`.split($/)475 assert_equal input, `#{FZF} -ffoobar --tiebreak=index < #{tempname}`.split($/)476477 by_length = %w[478 ----foobar--479 -----foobar---480 -------foobar-481 --foobar--------482 ]483 assert_equal by_length, `cat #{tempname} | #{FZF} -ffoobar`.split($/)484 assert_equal by_length, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=length`.split($/)483 assert_equal by_length, `#{FZF} -ffoobar < #{tempname}`.split($/)484 assert_equal by_length, `#{FZF} -ffoobar --tiebreak=length < #{tempname}`.split($/)485486 by_begin = %w[487 --foobar--------488 ----foobar--489 -----foobar---490 -------foobar-491 ]492 assert_equal by_begin, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=begin`.split($/)493 assert_equal by_begin, `cat #{tempname} | #{FZF} -f"!z foobar" -x --tiebreak begin`.split($/)492 assert_equal by_begin, `#{FZF} -ffoobar --tiebreak=begin < #{tempname}`.split($/)493 assert_equal by_begin, `#{FZF} -f"!z foobar" -x --tiebreak begin < #{tempname}`.split($/)494495 assert_equal %w[496 -------foobar-497 ----foobar--498 -----foobar---499 --foobar--------500 ], `cat #{tempname} | #{FZF} -ffoobar --tiebreak end`.split($/)500 ], `#{FZF} -ffoobar --tiebreak end < #{tempname}`.split($/)501502 assert_equal input, `cat #{tempname} | #{FZF} -f"!z" -x --tiebreak end`.split($/)502 assert_equal input, `#{FZF} -f"!z" -x --tiebreak end < #{tempname}`.split($/)503 end504505 # Since 0.11.2506 def test_tiebreak_list507 input = %w[508 f-o-o-b-a-r509 foobar----510 --foobar511 ----foobar512 foobar--513 --foobar--514 foobar515 ]516 writelines tempname, input517518 assert_equal %w[519 foobar----520 --foobar521 ----foobar522 foobar--523 --foobar--524 foobar525 f-o-o-b-a-r526 ], `#{FZF} -ffb --tiebreak=index < #{tempname}`.split($/)527528 by_length = %w[529 foobar530 --foobar531 foobar--532 foobar----533 ----foobar534 --foobar--535 f-o-o-b-a-r536 ]537 assert_equal by_length, `#{FZF} -ffb < #{tempname}`.split($/)538 assert_equal by_length, `#{FZF} -ffb --tiebreak=length < #{tempname}`.split($/)539540 assert_equal %w[541 foobar542 foobar--543 --foobar544 foobar----545 --foobar--546 ----foobar547 f-o-o-b-a-r548 ], `#{FZF} -ffb --tiebreak=length,begin < #{tempname}`.split($/)549550 assert_equal %w[551 foobar552 --foobar553 foobar--554 ----foobar555 --foobar--556 foobar----557 f-o-o-b-a-r558 ], `#{FZF} -ffb --tiebreak=length,end < #{tempname}`.split($/)559560 assert_equal %w[561 foobar----562 foobar--563 foobar564 --foobar565 --foobar--566 ----foobar567 f-o-o-b-a-r568 ], `#{FZF} -ffb --tiebreak=begin < #{tempname}`.split($/)569570 by_begin_end = %w[571 foobar572 foobar--573 foobar----574 --foobar575 --foobar--576 ----foobar577 f-o-o-b-a-r578 ]579 assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=begin,length < #{tempname}`.split($/)580 assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=begin,end < #{tempname}`.split($/)581582 assert_equal %w[583 --foobar584 ----foobar585 foobar586 foobar--587 --foobar--588 foobar----589 f-o-o-b-a-r590 ], `#{FZF} -ffb --tiebreak=end < #{tempname}`.split($/)591592 by_begin_end = %w[593 foobar594 --foobar595 ----foobar596 foobar--597 --foobar--598 foobar----599 f-o-o-b-a-r600 ]601 assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=end,begin < #{tempname}`.split($/)602 assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=end,length < #{tempname}`.split($/)603 end604605 def test_tiebreak_length_with_nth606 input = %w[607 1:hell608 123:hello
7 unmodified lines
616 12345:he617 123:hello618 1234567:h619 ]520 assert_equal output, `cat #{tempname} | #{FZF} -fh`.split($/)620 assert_equal output, `#{FZF} -fh < #{tempname}`.split($/)621622 output = %w[623 1234567:h624 12345:he625 1:hell626 123:hello627 ]528 assert_equal output, `cat #{tempname} | #{FZF} -fh -n2 -d:`.split($/)628 assert_equal output, `#{FZF} -fh -n2 -d: < #{tempname}`.split($/)629 end630631 def test_tiebreak_length_with_nth_trim_length632 input = [
10 unmodified lines
643 "app ic bottle 4",644 "apple juice bottle 1",645 "apple ui bottle 2",646 ]547 assert_equal output, `cat #{tempname} | #{FZF} -fa -n1`.split($/)647 assert_equal output, `#{FZF} -fa -n1 < #{tempname}`.split($/)648649 # len(1 ~ 2)650 output = [651 "apple ui bottle 2",652 "app ic bottle 4",653 "apple juice bottle 1",654 "app ice bottle 3",655 ]556 assert_equal output, `cat #{tempname} | #{FZF} -fai -n1..2`.split($/)656 assert_equal output, `#{FZF} -fai -n1..2 < #{tempname}`.split($/)657658 # len(1) + len(2)659 output = [660 "app ic bottle 4",661 "app ice bottle 3",662 "apple ui bottle 2",663 "apple juice bottle 1",664 ]565 assert_equal output, `cat #{tempname} | #{FZF} -x -f"a i" -n1,2`.split($/)665 assert_equal output, `#{FZF} -x -f"a i" -n1,2 < #{tempname}`.split($/)666667 # len(2)668 output = [669 "apple ui bottle 2",670 "app ic bottle 4",671 "app ice bottle 3",672 "apple juice bottle 1",673 ]574 assert_equal output, `cat #{tempname} | #{FZF} -fi -n2`.split($/)575 assert_equal output, `cat #{tempname} | #{FZF} -fi -n2,1..2`.split($/)674 assert_equal output, `#{FZF} -fi -n2 < #{tempname}`.split($/)675 assert_equal output, `#{FZF} -fi -n2,1..2 < #{tempname}`.split($/)676 end677678 def test_tiebreak_end_backward_scan679 input = %w[
1 unmodified line
681 fubar682 ]683 writelines tempname, input684585 assert_equal input.reverse, `cat #{tempname} | #{FZF} -f fb`.split($/)586 assert_equal input, `cat #{tempname} | #{FZF} -f fb --tiebreak=end`.split($/)685 assert_equal input.reverse, `#{FZF} -f fb < #{tempname}`.split($/)686 assert_equal input, `#{FZF} -f fb --tiebreak=end < #{tempname}`.split($/)687 end688689 def test_invalid_cache690 tmux.send_keys "(echo d; echo D; echo x) | #{fzf '-q d'}", :Enter
21 unmodified lines
712 data = '.' * 256 * 1024713 File.open(tempname, 'w') do |f|714 f << data715 end616 assert_equal data, `cat #{tempname} | #{FZF} -f .`.chomp716 assert_equal data, `#{FZF} -f . < #{tempname}`.chomp717 end718719 def test_read0720 lines = `find .`.split($/)
266 unmodified lines
987 end988989 def test_with_nth990 writelines tempname, ['hello world ', 'byebye']891 assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp991 assert_equal 'hello world ', `#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 < #{tempname}`.chomp992 end993994 def test_with_nth_ansi995 writelines tempname, ["\x1b[33mhello \x1b[34;1mworld\x1b[m ", 'byebye']896 assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 --ansi`.chomp996 assert_equal 'hello world ', `#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 --ansi < #{tempname}`.chomp997 end998999 def test_with_nth_no_ansi1000 src = "\x1b[33mhello \x1b[34;1mworld\x1b[m "1001 writelines tempname, [src, 'byebye']902 assert_equal src, `cat #{tempname} | #{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi`.chomp1002 assert_equal src, `#{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi < #{tempname}`.chomp1003 end10041005 def test_exit_0_exit_code1006 `echo foo | #{FZF} -q bar -0`
331 unmodified lines
modified:CHANGELOG.md+9 added
1CHANGELOG2=========340.11.25------67- `--tiebreak` now accepts comma-separated list of sort criteria.8 - Each criterion should appear only once in the list9 - `index` is only allowed at the end of the list10 - `index` is implicitly appended to the list when not specified11 - Default is `length` (or equivalently `length,index`)12130.11.114------1516- Added `--tabstop=SPACES` option
335 unmodified lines