summaryrefslogtreecommitdiff
path: root/src/tmux.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-05-13 23:33:04 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-05-18 17:08:36 +0900
commit04dfb14e3215f578d44cdc117d9f19920af21faa (patch)
tree8ebb682c060dffa456588b7cbbbe3b720b199423 /src/tmux.go
parentc24256cba33233ed707b428249a1a1c766034e8c (diff)
downloadfzf-04dfb14e3215f578d44cdc117d9f19920af21faa.tar.gz
Do not 'become' inside a tmux popup
fzf --tmux center --bind 'enter:become:vim {}'
Diffstat (limited to 'src/tmux.go')
-rw-r--r--src/tmux.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/tmux.go b/src/tmux.go
index ea1816a5..5cc970fa 100644
--- a/src/tmux.go
+++ b/src/tmux.go
@@ -2,6 +2,7 @@ package fzf
import (
"bufio"
+ "errors"
"fmt"
"io"
"os"
@@ -45,6 +46,7 @@ func runTmux(args []string, opts *Options) (int, error) {
// %q formatting escapes $'foo\nbar' to "foo\nbar"
argStr += " " + escapeSingleQuote(arg)
}
+ argStr += ` --tmux-script "$0"`
// Build command
var command string
@@ -141,7 +143,26 @@ func runTmux(args []string, opts *Options) (int, error) {
cmd := exec.Command("tmux", tmuxArgs...)
if err := cmd.Run(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
- return exitError.ExitCode(), err
+ code := exitError.ExitCode()
+ if code == ExitBecome {
+ data, err := os.ReadFile(temp)
+ if err != nil {
+ return ExitError, err
+ }
+ elems := strings.Split(string(data), "\x00")
+ if len(elems) < 1 {
+ return ExitError, errors.New("invalid become command")
+ }
+ command := elems[0]
+ env := []string{}
+ if len(elems) > 1 {
+ env = elems[1:]
+ }
+ os.Remove(temp)
+ executor := util.NewExecutor(opts.WithShell)
+ executor.Become(tui.TtyIn(), env, command)
+ }
+ return code, err
}
}