Do not 'become' inside a tmux popup
Before adoption: this commit came in with the history the project adopted, so no landing records it.
fzf --tmux center --bind 'enter:become:vim {}'
authored by Junegunn Choi · committed by Junegunn Choi · parent c24256c · Browse files · 4 files·+42 added−3 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+42 added−3 removed
- other:+42 added−3 removed
Provenance
- Commit
04dfb14- Tree
8ebb682- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
c24256c
4 files changed+42 added−3 removed
modified:src/constants.go+1 added-1 removed
65 unmodified lines66 EvtQuit67 )68 69 const (70- ExitCancel = -170 ExitOk = 071 ExitNoMatch = 172 ExitError = 273+ ExitBecome = 12674 ExitInterrupt = 13075 )modified:src/options.go+5 added
379 unmodified lines380 type Options struct {381 Input chan string382 Output chan string383 Tmux *tmuxOptions384+ TmuxScript string385 Bash bool386 Zsh bool387 Fish bool388 Fuzzy bool1493 unmodified lines1882 return err1883 }1884 case "--no-tmux":1885 opts.Tmux = nil1886+ case "--tmux-script":1887+ if opts.TmuxScript, err = nextString(allArgs, &i, ""); err != nil {1888+ return err1889+ }1890 case "-x", "--extended":1891 opts.Extended = true1892 case "-e", "--exact":1893 opts.Fuzzy = false855 unmodified linesmodified:src/terminal.go+14 added-1 removed
310 unmodified lines311 areaColumns int312 forcePreview bool313 clickHeaderLine int314 clickHeaderColumn int315+ tmuxScript string316 }317 318 type selectedItem struct {319 at time.Time31 unmodified lines351 reqPreviewEnqueue352 reqPreviewDisplay353 reqPreviewRefresh354 reqPreviewDelayed355+ reqBecome356 reqQuit357 reqFatal358 )359 423 unmodified lines783 jumping: jumpDisabled,784 jumpLabels: opts.JumpLabels,785 printer: opts.Printer,786 printsep: opts.PrintSep,787+ tmuxScript: opts.TmuxScript,788 merger: EmptyMerger(0),789 selected: make(map[int32]selectedItem),790 reqBox: util.NewEventBox(),791 initialPreviewOpts: opts.Preview,2509 unmodified lines3301 t.printer(string(t.input))3302 return ExitOk3303 })3304 return3305+ case reqBecome:3306+ exit(func() int { return ExitBecome })3307+ return3308 case reqQuit:3309 exit(func() int { return ExitInterrupt })3310 return3311 case reqFatal:166 unmodified lines3478 t.tui.Close()3479 if t.history != nil {3480 t.history.append(string(t.input))3481 }3482+3483+ if len(t.tmuxScript) > 0 {3484+ data := strings.Join(append([]string{command}, t.environ()...), "\x00")3485+ os.WriteFile(t.tmuxScript, []byte(data), 0600)3486+ req(reqBecome)3487+ } else {3476- t.executor.Become(t.ttyin, t.environ(), command)3488+ t.executor.Become(t.ttyin, t.environ(), command)3489+ }3490 }3491 case actExecute, actExecuteSilent:3492 t.executeCommand(a.a, false, a.t == actExecuteSilent, false, false)3493 case actExecuteMulti:925 unmodified linesmodified:src/tmux.go+22 added-1 removed
1 package fzf2 3 import (4 "bufio"5+ "errors"6 "fmt"7 "io"8 "os"9 "os/exec"35 unmodified lines45 for _, arg := range args {46 // %q formatting escapes $'foo\nbar' to "foo\nbar"47 argStr += " " + escapeSingleQuote(arg)48 }49+ argStr += ` --tmux-script "$0"`50 51 // Build command52 var command string53 if opts.Input == nil && util.IsTty() {88 unmodified lines142 143 cmd := exec.Command("tmux", tmuxArgs...)144 if err := cmd.Run(); err != nil {145 if exitError, ok := err.(*exec.ExitError); ok {144- return exitError.ExitCode(), err146+ code := exitError.ExitCode()147+ if code == ExitBecome {148+ data, err := os.ReadFile(temp)149+ if err != nil {150+ return ExitError, err151+ }152+ elems := strings.Split(string(data), "\x00")153+ if len(elems) < 1 {154+ return ExitError, errors.New("invalid become command")155+ }156+ command := elems[0]157+ env := []string{}158+ if len(elems) > 1 {159+ env = elems[1:]160+ }161+ os.Remove(temp)162+ executor := util.NewExecutor(opts.WithShell)163+ executor.Become(tui.TtyIn(), env, command)164+ }165+ return code, err166 }167 }168 169 return ExitOk, nil1 unmodified line