Extract common popup argument building into popupArgStr

This commit is contained in:
Junegunn Choi
2026-03-26 21:14:00 +09:00
parent a5646b46e8
commit a099d76fa6
3 changed files with 28 additions and 56 deletions
+26
View File
@@ -23,6 +23,32 @@ func escapeSingleQuote(str string) string {
return "'" + strings.ReplaceAll(str, "'", "'\\''") + "'" 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) { func fifo(name string) (string, error) {
ns := time.Now().UnixNano() ns := time.Now().UnixNano()
output := filepath.Join(os.TempDir(), fmt.Sprintf("fzf-%s-%d", name, ns)) output := filepath.Join(os.TempDir(), fmt.Sprintf("fzf-%s-%d", name, ns))
+1 -29
View File
@@ -1,39 +1,11 @@
package fzf package fzf
import ( import (
"os"
"os/exec" "os/exec"
"github.com/junegunn/fzf/src/tui"
) )
func runTmux(args []string, opts *Options) (int, error) { func runTmux(args []string, opts *Options) (int, error) {
// Prepare arguments argStr, dir := popupArgStr(args, opts)
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 = "."
}
// Set tmux options for popup placement // Set tmux options for popup placement
// C Both The centre of the terminal // C Both The centre of the terminal
+1 -27
View File
@@ -1,37 +1,11 @@
package fzf package fzf
import ( import (
"os"
"os/exec" "os/exec"
"github.com/junegunn/fzf/src/tui"
) )
func runZellij(args []string, opts *Options) (int, error) { func runZellij(args []string, opts *Options) (int, error) {
// Prepare arguments argStr, dir := popupArgStr(args, opts)
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 = "."
}
zellijArgs := []string{ zellijArgs := []string{
"run", "--floating", "--close-on-exit", "--block-until-exit", "run", "--floating", "--close-on-exit", "--block-until-exit",