Support zellij floating pane via --popup (new name for --tmux) (#4145)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by GitHub · parent 87586ac · Browse files · 8 files·+95 added−43 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+95 added−43 removed
- other:+95 added−43 removed
Provenance
- Commit
6f17d49- Tree
7d6cf11- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
87586ac
8 files changed+95 added−43 removed
modified:man/man1/fzf.1+10 added-9 removed
413 unmodified lines414 layout options so that the specified number of items are visible in the list415 section (default: \fB10+\fR).416 Ignored when \fB\-\-height\fR is not specified or set as an absolute value.417 .TP418-.BI "\-\-tmux" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]][,border-native]]"419-Start fzf in a tmux popup (default \fBcenter,50%\fR). Requires tmux 3.3 or420-later. This option is ignored if you are not running fzf inside tmux.418+.BI "\-\-popup" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]][,border-native]]"419+Start fzf in a tmux popup or in a Zellij floating pane (default420+\fBcenter,50%\fR). Requires tmux 3.3+ or Zellij 0.44+. This option is ignored if you421+are not running fzf inside tmux or Zellij. \fB\-\-tmux\fR is an alias for this option.422 423 e.g.424 \fB# Popup in the center with 70% width and height424- fzf \-\-tmux 70%425+ fzf \-\-popup 70%426 427 # Popup on the left with 40% width and 100% height427- fzf \-\-tmux right,40%428+ fzf \-\-popup right,40%429 430 # Popup on the bottom with 100% width and 30% height430- fzf \-\-tmux bottom,30%431+ fzf \-\-popup bottom,30%432 433 # Popup on the top with 80% width and 40% height433- fzf \-\-tmux top,80%,40%434+ fzf \-\-popup top,80%,40%435 435- # Popup with a native tmux border in the center with 80% width and height436- fzf \-\-tmux center,80%,border\-native\fR436+ # Popup with a native tmux or Zellij border in the center with 80% width and height437+ fzf \-\-popup center,80%,border\-native\fR438 439 .SS LAYOUT440 .TP441 .BI "\-\-layout=" "LAYOUT"1828 unmodified linesmodified:src/core.go+3 added
54 unmodified lines55 if opts.Filter == nil {56 if opts.useTmux() {57 return runTmux(os.Args, opts)58 }59+ if opts.useZellij() {60+ return runZellij(os.Args, opts)61+ }62 63 if needWinpty(opts) {64 return runWinpty(os.Args, opts)65 }575 unmodified linesmodified:src/options.go+9 added-4 removed
73 unmodified lines74 according to the input size.75 --min-height=HEIGHT[+] Minimum height when --height is given as a percentage.76 Add '+' to automatically increase the value77 according to the other layout options (default: 10+).78- --tmux[=OPTS] Start fzf in a tmux popup (requires tmux 3.3+)78+ --popup[=OPTS] Start fzf in a popup window (requires tmux 3.3+ or Zellij 0.44+)79 [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]80 [,border-native] (default: center,50%)81+ --tmux[=OPTS] Alias for --popup82 83 LAYOUT84 --layout=LAYOUT Choose layout: [default|reverse|reverse-list]85 --margin=MARGIN Screen margin (TRBL | TB,RL | T,RL,B | T,R,B,L)331 unmodified lines417 func parseTmuxOptions(arg string, index int) (*tmuxOptions, error) {418 var err error419 opts := defaultTmuxOptions(index)420 tokens := splitRegexp.Split(arg, -1)420- errorToReturn := errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]])")421+ errorToReturn := errors.New("invalid popup option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]])")422 if len(tokens) == 0 || len(tokens) > 4 {423 return nil, errorToReturn424 }425 2210 unmodified lines2636 clearExitingOpts()2637 opts.Version = true2638 case "--no-winpty":2639 opts.NoWinpty = true2639- case "--tmux":2640+ case "--tmux", "--popup":2641 given, str := optionalNextString()2642 if given {2643 if opts.Tmux, err = parseTmuxOptions(str, index); err != nil {2644 return err2645 }2646 } else {2647 opts.Tmux = defaultTmuxOptions(index)2648 }2648- case "--no-tmux":2649+ case "--no-tmux", "--no-popup":2650 opts.Tmux = nil2651 case "--tty-default":2652 if opts.TtyDefault, err = nextString("tty device name required"); err != nil {2653 return err973 unmodified lines3627 func (opts *Options) useTmux() bool {3628 return opts.Tmux != nil && len(os.Getenv("TMUX")) > 0 && opts.Tmux.index >= opts.Height.index3629 }3630 3631+func (opts *Options) useZellij() bool {3632+ return opts.Tmux != nil && len(os.Getenv("ZELLIJ")) > 0 && opts.Tmux.index >= opts.Height.index3633+}3634+3635 func (opts *Options) noSeparatorLine() bool {3636 if opts.Inputless {3637 return true3638 }296 unmodified linesmodified:src/proxy.go+26 added
21 unmodified lines22 func escapeSingleQuote(str string) string {23 return "'" + strings.ReplaceAll(str, "'", "'\\''") + "'"24 }25 26+func popupArgStr(args []string, opts *Options) (string, string) {27+ fzf, rest := args[0], args[1:]28+ args = []string{"--bind=ctrl-z:ignore"}29+ if !opts.Tmux.border && (opts.BorderShape == tui.BorderUndefined || opts.BorderShape == tui.BorderLine) {30+ if tui.DefaultBorderShape == tui.BorderRounded {31+ rest = append(rest, "--border=rounded")32+ } else {33+ rest = append(rest, "--border=sharp")34+ }35+ }36+ if opts.Tmux.border && opts.Margin == defaultMargin() {37+ args = append(args, "--margin=0,1")38+ }39+ argStr := escapeSingleQuote(fzf)40+ for _, arg := range append(args, rest...) {41+ argStr += " " + escapeSingleQuote(arg)42+ }43+ argStr += ` --no-popup --no-height`44+45+ dir, err := os.Getwd()46+ if err != nil {47+ dir = "."48+ }49+ return argStr, dir50+}51+52 func fifo(name string) (string, error) {53 ns := time.Now().UnixNano()54 output := filepath.Join(os.TempDir(), fmt.Sprintf("fzf-%s-%d", name, ns))55 output, err := mkfifo(output, 0600)133 unmodified linesmodified:src/terminal.go+1 added-1 removed
2241 unmodified lines2242 screenWidth, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()2243 width := screenWidth - marginInt[1] - marginInt[3]2244 height := screenHeight - marginInt[0] - marginInt[2]2245 2246- t.prevLines = make([]itemLine, screenHeight)2246+ t.prevLines = make([]itemLine, max(1, screenHeight))2247 if t.border != nil && redrawBorder {2248 t.border = nil2249 }2250 if t.window != nil {5694 unmodified linesmodified:src/tmux.go+1 added-29 removed
1 package fzf2 3 import (4- "os"4 "os/exec"6-7- "github.com/junegunn/fzf/src/tui"5 )6 7 func runTmux(args []string, opts *Options) (int, error) {11- // Prepare arguments12- fzf, rest := args[0], args[1:]13- args = []string{"--bind=ctrl-z:ignore"}14- if !opts.Tmux.border && (opts.BorderShape == tui.BorderUndefined || opts.BorderShape == tui.BorderLine) {15- // We append --border option at the end, because `--style=full:STYLE`16- // may have changed the default border style.17- if tui.DefaultBorderShape == tui.BorderRounded {18- rest = append(rest, "--border=rounded")19- } else {20- rest = append(rest, "--border=sharp")21- }22- }23- if opts.Tmux.border && opts.Margin == defaultMargin() {24- args = append(args, "--margin=0,1")25- }26- argStr := escapeSingleQuote(fzf)27- for _, arg := range append(args, rest...) {28- argStr += " " + escapeSingleQuote(arg)29- }30- argStr += ` --no-tmux --no-height`8+ argStr, dir := popupArgStr(args, opts)9 32- // Get current directory33- dir, err := os.Getwd()34- if err != nil {35- dir = "."36- }37-10 // Set tmux options for popup placement11 // C Both The centre of the terminal12 // R -x The right side of the terminal13 // P Both The bottom left of the pane31 unmodified linesadded:src/zellij.go+41 added
1+package fzf2+3+import (4+ "os/exec"5+)6+7+func runZellij(args []string, opts *Options) (int, error) {8+ argStr, dir := popupArgStr(args, opts)9+10+ zellijArgs := []string{11+ "run", "--floating", "--close-on-exit", "--block-until-exit",12+ "--cwd", dir,13+ }14+ if !opts.Tmux.border {15+ zellijArgs = append(zellijArgs, "--borderless", "true")16+ }17+ switch opts.Tmux.position {18+ case posUp:19+ zellijArgs = append(zellijArgs, "-y", "0")20+ case posDown:21+ zellijArgs = append(zellijArgs, "-y", "9999")22+ case posLeft:23+ zellijArgs = append(zellijArgs, "-x", "0")24+ case posRight:25+ zellijArgs = append(zellijArgs, "-x", "9999")26+ case posCenter:27+ // Zellij centers floating panes by default28+ }29+ zellijArgs = append(zellijArgs, "--width", opts.Tmux.width.String())30+ zellijArgs = append(zellijArgs, "--height", opts.Tmux.height.String())31+ zellijArgs = append(zellijArgs, "--")32+33+ return runProxy(argStr, func(temp string, needBash bool) (*exec.Cmd, error) {34+ sh, err := sh(needBash)35+ if err != nil {36+ return nil, err37+ }38+ zellijArgs = append(zellijArgs, sh, temp)39+ return exec.Command("zellij", zellijArgs...), nil40+ }, opts, true)41+}modified:CHANGELOG.md+4 added
1 unmodified line2 =========3 4 0.71.05 ------6+- Added `--popup` as a new name for `--tmux` with Zellij support7+ - `--popup` starts fzf in a tmux popup or a Zellij floating pane8+ - `--tmux` is now an alias for `--popup`9+ - Requires tmux 3.3+ or Zellij 0.44+10 - Cross-reload item identity with `--id-nth`11 - Added `--id-nth=NTH` to define item identity fields for cross-reload operations12 - When a `reload` is triggered with tracking enabled, fzf searches for the tracked item by its identity fields in the new list.13 - `--track --id-nth ..` tracks by the entire line3235 unmodified lines