Skip to content
Myr

Export the current nth value as $FZF_NTH

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 938c15e · Browse files · 4 files+60 added−11 removed
This commit

State

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

Diff stats

4 files+60 added−11 removed

  • tests:+26 added−7 removed
  • other:+34 added−4 removed

4 files+60 added−11 removed

modified:src/terminal.go+3 added
1044 unmodified lines
1045 env = append(env, "FZF_PROMPT="+string(t.promptString))1046 env = append(env, "FZF_PREVIEW_LABEL="+t.previewLabelOpts.label)1047 env = append(env, "FZF_BORDER_LABEL="+t.borderLabelOpts.label)1048 env = append(env, "FZF_LIST_LABEL="+t.listLabelOpts.label)1049 if len(t.nthCurrent) > 0 {1050 env = append(env, "FZF_NTH="+RangesToString(t.nthCurrent))1051 }1052 env = append(env, fmt.Sprintf("FZF_TOTAL_COUNT=%d", t.count))1053 env = append(env, fmt.Sprintf("FZF_MATCH_COUNT=%d", t.merger.Length()))1054 env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected)))1055 env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))
4785 unmodified lines
modified:src/tokenizer.go+27 added-1 removed
16 unmodified lines
17 begin int18 end int19}2021func RangesToString(ranges []Range) string {22 strs := []string{}23 for _, r := range ranges {24 s := ""25 if r.begin == rangeEllipsis && r.end == rangeEllipsis {26 s = ".."27 } else if r.begin == r.end {28 s = strconv.Itoa(r.begin)29 } else {30 if r.begin != rangeEllipsis {31 s += strconv.Itoa(r.begin)32 }3334 if r.begin != -1 {35 s += ".."36 if r.end != rangeEllipsis {37 s += strconv.Itoa(r.end)38 }39 }40 }41 strs = append(strs, s)42 }4344 return strings.Join(strs, ",")45}4647// Token contains the tokenized part of the strings and its prefix length48type Token struct {49 text *util.Chars50 prefixLength int32
15 unmodified lines
66 return fmt.Sprintf("Delimiter{regex: %v, str: &%q}", d.regex, *d.str)67}6869func newRange(begin int, end int) Range {44 if begin == 1 {70 if begin == 1 && end != 1 {71 begin = rangeEllipsis72 }73 if end == -1 {74 end = rangeEllipsis
205 unmodified lines
modified:test/test_go.rb+26 added-7 removed
3727 unmodified lines
3728 'foo foo foo foo bar',3729 *[''] * 10003730 ]3731 writelines(input)3732 tmux.send_keys %(#{FZF} -qfoo -n1 --bind 'space:change-nth:2|3|4|5|' < #{tempname}), :Enter3732 nths = '1,2..4,-1,-3..,..2'3733 tmux.send_keys %(#{FZF} -qfoo -n#{nths} --bind 'space:change-nth(2|3|4|5|),result:transform-prompt:echo "[$FZF_NTH] "' < #{tempname}), :Enter37343734 tmux.until { |lines| assert_equal 4, lines.match_count }3735 tmux.until do |lines|3736 assert lines.any_include?("[#{nths}] foo")3737 assert_equal 4, lines.match_count3738 end3739 tmux.send_keys :Space3736 tmux.until { |lines| assert_equal 3, lines.match_count }3740 tmux.until do |lines|3741 assert lines.any_include?('[2] foo')3742 assert_equal 3, lines.match_count3743 end3744 tmux.send_keys :Space3738 tmux.until { |lines| assert_equal 2, lines.match_count }3745 tmux.until do |lines|3746 assert lines.any_include?('[3] foo')3747 assert_equal 2, lines.match_count3748 end3749 tmux.send_keys :Space3740 tmux.until { |lines| assert_equal 1, lines.match_count }3750 tmux.until do |lines|3751 assert lines.any_include?('[4] foo')3752 assert_equal 1, lines.match_count3753 end3754 tmux.send_keys :Space3742 tmux.until { |lines| assert_equal 0, lines.match_count }3755 tmux.until do |lines|3756 assert lines.any_include?('[5] foo')3757 assert_equal 0, lines.match_count3758 end3759 tmux.send_keys :Space3744 tmux.until { |lines| assert_equal 4, lines.match_count }3760 tmux.until do |lines|3761 assert lines.any_include?("[#{nths}] foo")3762 assert_equal 4, lines.match_count3763 end3764 end3765end37663767module TestShell
538 unmodified lines
modified:CHANGELOG.md+4 added-3 removed
90 unmodified lines
9192 # Dim the other parts93 ls -al | fzf --nth -1 --color nth:regular,fg:dim,current-fg:dim9495 # With 'change-nth'95 # With 'change-nth'. The current nth option is exported as $FZF_NTH.96 ps -ef | fzf --reverse --header-lines 1 --header-border bottom --input-border \97 --color nth:regular,fg:dim,current-fg:dim \98 --nth 8.. --bind 'ctrl-n:change-nth(..|1|2|3|4|5|6|7|)'97 --color nth:regular,fg:dim,current-fg:dim \98 --nth 8.. --bind 'ctrl-n:change-nth(1|2|3|4|5|6|7|)' \99 --bind 'result:transform-prompt:echo "${FZF_NTH}> "'100 ```101- A single-character delimiter is now treated as a plain string delimiter rather than a regular expression delimiter, even if it's a regular expression meta-character.102 - This means you can just write `--delimiter '|'` instead of escaping it as `--delimiter '\|'`103- Bug fixes
2331 unmodified lines