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
Provenance
- Commit
b712f2b- Tree
553697e- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
938c15e
4 files changed+60 added−11 removed
modified:src/terminal.go+3 added
1044 unmodified lines1045 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 linesmodified:src/tokenizer.go+27 added-1 removed
16 unmodified lines17 begin int18 end int19 }20 21+func 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+ }33+34+ 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+ }43+44+ return strings.Join(strs, ",")45+}46+47 // Token contains the tokenized part of the strings and its prefix length48 type Token struct {49 text *util.Chars50 prefixLength int3215 unmodified lines66 return fmt.Sprintf("Delimiter{regex: %v, str: &%q}", d.regex, *d.str)67 }68 69 func 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 = rangeEllipsis205 unmodified linesmodified:test/test_go.rb+26 added-7 removed
3727 unmodified lines3728 '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}), :Enter3734 3734- 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 end3765 end3766 3767 module TestShell538 unmodified linesmodified:CHANGELOG.md+4 added-3 removed
90 unmodified lines91 92 # Dim the other parts93 ls -al | fzf --nth -1 --color nth:regular,fg:dim,current-fg:dim94 95- # 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 fixes2331 unmodified lines