Export FZF_* variables to 'reload' process as well
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 425dead · Browse files · 4 files·+26 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+26 added−11 removed
- tests:+1 added−1 removed
- other:+25 added−10 removed
Provenance
- Commit
5e6788c- Tree
74aeb08- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
425dead
4 files changed+26 added−11 removed
modified:src/core.go+9 added-4 removed
211 unmodified lines212 // Event coordination213 reading := true214 ticks := 0215 var nextCommand *string216+ var nextEnviron []string217 eventBox.Watch(EvtReadNew)218 total := 0219 query := []rune{}220 determine := func(final bool) {11 unmodified lines232 233 useSnapshot := false234 var snapshot []*Chunk235 var count int235- restart := func(command string) {236+ restart := func(command string, environ []string) {237 reading = true238 chunkList.Clear()239 itemIndex = 0240 inputRevision++241 header = make([]string, 0, opts.HeaderLines)241- go reader.restart(command)242+ go reader.restart(command, environ)243 }244 for {245 delay := true246 ticks++19 unmodified lines266 }267 os.Exit(value.(int))268 case EvtReadNew, EvtReadFin:269 if evt == EvtReadFin && nextCommand != nil {269- restart(*nextCommand)270+ restart(*nextCommand, nextEnviron)271 nextCommand = nil272+ nextEnviron = nil273 break274 } else {275 reading = reading && evt == EvtReadNew276 }16 unmodified lines293 matcher.Reset(snapshot, input(), false, !reading, sort, snapshotRevision)294 295 case EvtSearchNew:296 var command *string297+ var environ []string298 var changed bool299 switch val := value.(type) {300 case searchRequest:301 sort = val.sort302 command = val.command303+ environ = val.environ304 changed = val.changed305 if command != nil {306 useSnapshot = val.sync307 }1 unmodified line309 if command != nil {310 if reading {311 reader.terminate()312 nextCommand = command313+ nextEnviron = environ314 } else {310- restart(*command)315+ restart(*command, environ)316 }317 }318 if !changed {319 break64 unmodified linesmodified:src/reader.go+8 added-4 removed
83 unmodified lines84 }85 r.mutex.Unlock()86 }87 88-func (r *Reader) restart(command string) {88+func (r *Reader) restart(command string, environ []string) {89 r.event = int32(EvtReady)90 r.startEventPoller()91- success := r.readFromCommand(command)91+ success := r.readFromCommand(command, environ)92 r.fin(success)93 }94 95 // ReadSource reads data from the default command or from standard input4 unmodified lines100 cmd := os.Getenv("FZF_DEFAULT_COMMAND")101 if len(cmd) == 0 {102 success = r.readFiles()103 } else {104+ // We can't export FZF_* environment variables to the default command104- success = r.readFromCommand(cmd)105+ success = r.readFromCommand(cmd, nil)106 }107 } else {108 success = r.readFromStdin()109 }61 unmodified lines171 }172 return fastwalk.Walk(&conf, ".", fn) == nil173 }174 174-func (r *Reader) readFromCommand(command string) bool {175+func (r *Reader) readFromCommand(command string, environ []string) bool {176 r.mutex.Lock()177 r.killed = false178 r.command = &command179 r.exec = util.ExecCommand(command, true)180+ if environ != nil {181+ r.exec.Env = environ182+ }183 out, err := r.exec.StdoutPipe()184 if err != nil {185 r.mutex.Unlock()186 return false9 unmodified linesmodified:src/terminal.go+8 added-2 removed
497 unmodified lines498 type searchRequest struct {499 sort bool500 sync bool501 command *string502+ environ []string503 changed bool504 }505 506 type previewRequest struct {3574 unmodified lines4081 if queryChanged || t.cx != previousCx {4082 req(reqPrompt)4083 }4084 4085+ reload := changed || newCommand != nil4086+ var reloadRequest *searchRequest4087+ if reload {4088+ reloadRequest = &searchRequest{sort: t.sort, sync: reloadSync, command: newCommand, environ: t.environ(), changed: changed}4089+ }4090 t.mutex.Unlock() // Must be unlocked before touching reqBox4091 4086- if changed || newCommand != nil {4087- t.eventBox.Set(EvtSearchNew, searchRequest{sort: t.sort, sync: reloadSync, command: newCommand, changed: changed})4092+ if reload {4093+ t.eventBox.Set(EvtSearchNew, *reloadRequest)4094 }4095 for _, event := range events {4096 t.reqBox.Set(event, nil)4097 }110 unmodified linesmodified:test/test_go.rb+1 added-1 removed
1916 unmodified lines1917 tmux.until { |lines| assert_includes lines[1], ' 333foo ' }1918 end1919 1920 def test_reload1921- tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:reload(seq {q}),a:reload(seq 100),b:reload:seq 200' --header-lines 2 --multi 2), :Enter1921+ tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:reload(seq $FZF_QUERY),a:reload(seq 100),b:reload:seq 200' --header-lines 2 --multi 2), :Enter1922 tmux.until { |lines| assert_equal 998, lines.match_count }1923 tmux.send_keys 'a'1924 tmux.until do |lines|1925 assert_equal 98, lines.item_count1704 unmodified lines