diff --git a/src/proxy.go b/src/proxy.go index 590c6b68..c02aedcf 100644 --- a/src/proxy.go +++ b/src/proxy.go @@ -23,6 +23,32 @@ func escapeSingleQuote(str string) string { return "'" + strings.ReplaceAll(str, "'", "'\\''") + "'" } +func popupArgStr(args []string, opts *Options) (string, string) { + fzf, rest := args[0], args[1:] + args = []string{"--bind=ctrl-z:ignore"} + if !opts.Tmux.border && (opts.BorderShape == tui.BorderUndefined || opts.BorderShape == tui.BorderLine) { + if tui.DefaultBorderShape == tui.BorderRounded { + rest = append(rest, "--border=rounded") + } else { + rest = append(rest, "--border=sharp") + } + } + if opts.Tmux.border && opts.Margin == defaultMargin() { + args = append(args, "--margin=0,1") + } + argStr := escapeSingleQuote(fzf) + for _, arg := range append(args, rest...) { + argStr += " " + escapeSingleQuote(arg) + } + argStr += ` --no-popup --no-height` + + dir, err := os.Getwd() + if err != nil { + dir = "." + } + return argStr, dir +} + func fifo(name string) (string, error) { ns := time.Now().UnixNano() output := filepath.Join(os.TempDir(), fmt.Sprintf("fzf-%s-%d", name, ns)) diff --git a/src/tmux.go b/src/tmux.go index 47606688..60d81dc4 100644 --- a/src/tmux.go +++ b/src/tmux.go @@ -1,39 +1,11 @@ package fzf import ( - "os" "os/exec" - - "github.com/junegunn/fzf/src/tui" ) func runTmux(args []string, opts *Options) (int, error) { - // Prepare arguments - fzf, rest := args[0], args[1:] - args = []string{"--bind=ctrl-z:ignore"} - if !opts.Tmux.border && (opts.BorderShape == tui.BorderUndefined || opts.BorderShape == tui.BorderLine) { - // We append --border option at the end, because `--style=full:STYLE` - // may have changed the default border style. - if tui.DefaultBorderShape == tui.BorderRounded { - rest = append(rest, "--border=rounded") - } else { - rest = append(rest, "--border=sharp") - } - } - if opts.Tmux.border && opts.Margin == defaultMargin() { - args = append(args, "--margin=0,1") - } - argStr := escapeSingleQuote(fzf) - for _, arg := range append(args, rest...) { - argStr += " " + escapeSingleQuote(arg) - } - argStr += ` --no-popup --no-height` - - // Get current directory - dir, err := os.Getwd() - if err != nil { - dir = "." - } + argStr, dir := popupArgStr(args, opts) // Set tmux options for popup placement // C Both The centre of the terminal diff --git a/src/zellij.go b/src/zellij.go index 024009cd..dce9dd40 100644 --- a/src/zellij.go +++ b/src/zellij.go @@ -1,37 +1,11 @@ package fzf import ( - "os" "os/exec" - - "github.com/junegunn/fzf/src/tui" ) func runZellij(args []string, opts *Options) (int, error) { - // Prepare arguments - fzf, rest := args[0], args[1:] - args = []string{"--bind=ctrl-z:ignore"} - if !opts.Tmux.border && (opts.BorderShape == tui.BorderUndefined || opts.BorderShape == tui.BorderLine) { - if tui.DefaultBorderShape == tui.BorderRounded { - rest = append(rest, "--border=rounded") - } else { - rest = append(rest, "--border=sharp") - } - } - if opts.Tmux.border && opts.Margin == defaultMargin() { - args = append(args, "--margin=0,1") - } - argStr := escapeSingleQuote(fzf) - for _, arg := range append(args, rest...) { - argStr += " " + escapeSingleQuote(arg) - } - argStr += ` --no-popup --no-height` - - // Get current directory - dir, err := os.Getwd() - if err != nil { - dir = "." - } + argStr, dir := popupArgStr(args, opts) zellijArgs := []string{ "run", "--floating", "--close-on-exit", "--block-until-exit",