Skip to content
Myr

Add `border-native` option to `--tmux` flag (#4157)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This commit adds the `border-native` resulting in the following: ``` --tmux[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]][,border-native]] ``` By default, when not specified, the `-B` flag is passed to the `tmux popup-window` command such that no border is drawn around the tmux popup window. When the `border-native` option is present, the `-B` flag is omitted and the popup window is drawn using the border style configured in the tmux config file. Fixes #4156

authored by Andreas Auernhammer · committed by GitHub · parent fb3bf6c · Browse files · 5 files+30 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Andreas Auernhammer <github@aead.dev>
  • Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>

Diff stats

5 files+30 added−12 removed

  • other:+30 added−12 removed

5 files+30 added−12 removed

modified:man/man1/fzf.1+5 added-2 removed
269 unmodified lines
270.BI "\-\-min\-height=" "HEIGHT"271Minimum height when \fB\-\-height\fR is given in percent (default: 10).272Ignored when \fB\-\-height\fR is not specified.273.TP274.BI "\-\-tmux" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]]"274.BI "\-\-tmux" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]][,border-native]]"275Start fzf in a tmux popup (default \fBcenter,50%\fR). Requires tmux 3.3 or276later. This option is ignored if you are not running fzf inside tmux.277278e.g.
6 unmodified lines
285 # Popup on the bottom with 100% width and 30% height286 fzf \-\-tmux bottom,30%287288 # Popup on the top with 80% width and 40% height289 fzf \-\-tmux top,80%,40%\fR289 fzf \-\-tmux top,80%,40%290291 # Popup with a native tmux border in the center with 80% width and height292 fzf \-\-tmux center,80%,border\-native\fR293294.TP295.BI "\-\-layout=" "LAYOUT"296Choose the layout (default: default)297
1429 unmodified lines
modified:src/options.go+12 added-3 removed
75 unmodified lines
76 --min-height=HEIGHT Minimum height when --height is given in percent77 (default: 10)78 --tmux[=OPTS] Start fzf in a tmux popup (requires tmux 3.3+)79 [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]80 (default: center,50%)80 [,border-native] (default: center,50%)81 --layout=LAYOUT Choose layout: [default|reverse|reverse-list]82 --border[=STYLE] Draw border around the finder83 [rounded|sharp|bold|block|thinblock|double|horizontal|vertical|84 top|bottom|left|right|none] (default: rounded)
168 unmodified lines
253 width sizeSpec254 height sizeSpec255 position windowPosition256 index int257 border bool258}259260type layoutType int261
54 unmodified lines
316func parseTmuxOptions(arg string, index int) (*tmuxOptions, error) {317 var err error318 opts := defaultTmuxOptions(index)319 tokens := splitRegexp.Split(arg, -1)319 errorToReturn := errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]])")320 if len(tokens) == 0 || len(tokens) > 3 {320 errorToReturn := errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]])")321 if len(tokens) == 0 || len(tokens) > 4 {322 return nil, errorToReturn323 }324325 for i, token := range tokens {326 if token == "border-native" {327 tokens = append(tokens[:i], tokens[i+1:]...) // cut the 'border-native' option328 opts.border = true329 break330 }331 }332333 // Defaults to 'center'334 switch tokens[0] {335 case "top", "up":336 opts.position = posUp
2869 unmodified lines
modified:src/tmux.go+11 added-5 removed
7 unmodified lines
8)910func runTmux(args []string, opts *Options) (int, error) {11 // Prepare arguments12 fzf := args[0]13 args = append([]string{"--bind=ctrl-z:ignore"}, args[1:]...)14 if opts.BorderShape == tui.BorderUndefined {12 fzf, rest := args[0], args[1:]13 args = []string{"--bind=ctrl-z:ignore"}14 if !opts.Tmux.border && opts.BorderShape == tui.BorderUndefined {15 args = append(args, "--border")16 }17 if opts.Tmux.border && opts.Margin == defaultMargin() {18 args = append(args, "--margin=0,1")19 }20 argStr := escapeSingleQuote(fzf)18 for _, arg := range args {21 for _, arg := range append(args, rest...) {22 argStr += " " + escapeSingleQuote(arg)23 }24 argStr += ` --no-tmux --no-height`25
9 unmodified lines
35 // P Both The bottom left of the pane36 // M Both The mouse position37 // W Both The window position on the status line38 // S -y The line above or below the status line36 tmuxArgs := []string{"display-popup", "-E", "-B", "-d", dir}39 tmuxArgs := []string{"display-popup", "-E", "-d", dir}40 if !opts.Tmux.border {41 tmuxArgs = append(tmuxArgs, "-B")42 }43 switch opts.Tmux.position {44 case posUp:45 tmuxArgs = append(tmuxArgs, "-xC", "-y0")46 case posDown:
20 unmodified lines
modified:ADVANCED.md+1 added-1 removed
126 unmodified lines
127128You can also specify the position, width, and height of the popup window in129the following format:130131* `[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]`131* `[center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]]`132133```sh134# 100% width and 60% height135fzf --tmux 100%,60% --border horizontal
541 unmodified lines
modified:README.md+1 added-1 removed
341 unmodified lines
342343With `--tmux` option, fzf will start in a tmux popup.344345```sh346# --tmux [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]346# --tmux [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]]347348fzf --tmux center # Center, 50% width and height349fzf --tmux 80% # Center, 80% width and height350fzf --tmux 100%,50% # Center, 100% width and 50% height
569 unmodified lines