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

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

Signed-off-by: Andreas Auernhammer <github@aead.dev>
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit is contained in:
Andreas Auernhammer 2025-01-04 10:30:32 +01:00 committed by GitHub
parent fb3bf6c984
commit 120cd7f25a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 12 deletions

View File

@ -128,7 +128,7 @@ fzf --height 70% --tmux 70%
You can also specify the position, width, and height of the popup window in You can also specify the position, width, and height of the popup window in
the following format: the following format:
* `[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]` * `[center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]]`
```sh ```sh
# 100% width and 60% height # 100% width and 60% height

View File

@ -343,7 +343,7 @@ fzf --height -3
With `--tmux` option, fzf will start in a tmux popup. With `--tmux` option, fzf will start in a tmux popup.
```sh ```sh
# --tmux [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]] # --tmux [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]]
fzf --tmux center # Center, 50% width and height fzf --tmux center # Center, 50% width and height
fzf --tmux 80% # Center, 80% width and height fzf --tmux 80% # Center, 80% width and height

View File

@ -271,7 +271,7 @@ Adaptive height has the following limitations:
Minimum height when \fB\-\-height\fR is given in percent (default: 10). Minimum height when \fB\-\-height\fR is given in percent (default: 10).
Ignored when \fB\-\-height\fR is not specified. Ignored when \fB\-\-height\fR is not specified.
.TP .TP
.BI "\-\-tmux" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]]" .BI "\-\-tmux" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]][,border-native]]"
Start fzf in a tmux popup (default \fBcenter,50%\fR). Requires tmux 3.3 or Start fzf in a tmux popup (default \fBcenter,50%\fR). Requires tmux 3.3 or
later. This option is ignored if you are not running fzf inside tmux. later. This option is ignored if you are not running fzf inside tmux.
@ -286,7 +286,10 @@ e.g.
fzf \-\-tmux bottom,30% fzf \-\-tmux bottom,30%
# Popup on the top with 80% width and 40% height # Popup on the top with 80% width and 40% height
fzf \-\-tmux top,80%,40%\fR fzf \-\-tmux top,80%,40%
# Popup with a native tmux border in the center with 80% width and height
fzf \-\-tmux center,80%,border\-native\fR
.TP .TP
.BI "\-\-layout=" "LAYOUT" .BI "\-\-layout=" "LAYOUT"

View File

@ -77,7 +77,7 @@ Usage: fzf [options]
(default: 10) (default: 10)
--tmux[=OPTS] Start fzf in a tmux popup (requires tmux 3.3+) --tmux[=OPTS] Start fzf in a tmux popup (requires tmux 3.3+)
[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]] [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]
(default: center,50%) [,border-native] (default: center,50%)
--layout=LAYOUT Choose layout: [default|reverse|reverse-list] --layout=LAYOUT Choose layout: [default|reverse|reverse-list]
--border[=STYLE] Draw border around the finder --border[=STYLE] Draw border around the finder
[rounded|sharp|bold|block|thinblock|double|horizontal|vertical| [rounded|sharp|bold|block|thinblock|double|horizontal|vertical|
@ -254,6 +254,7 @@ type tmuxOptions struct {
height sizeSpec height sizeSpec
position windowPosition position windowPosition
index int index int
border bool
} }
type layoutType int type layoutType int
@ -316,11 +317,19 @@ func parseTmuxOptions(arg string, index int) (*tmuxOptions, error) {
var err error var err error
opts := defaultTmuxOptions(index) opts := defaultTmuxOptions(index)
tokens := splitRegexp.Split(arg, -1) tokens := splitRegexp.Split(arg, -1)
errorToReturn := errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]])") errorToReturn := errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]])")
if len(tokens) == 0 || len(tokens) > 3 { if len(tokens) == 0 || len(tokens) > 4 {
return nil, errorToReturn return nil, errorToReturn
} }
for i, token := range tokens {
if token == "border-native" {
tokens = append(tokens[:i], tokens[i+1:]...) // cut the 'border-native' option
opts.border = true
break
}
}
// Defaults to 'center' // Defaults to 'center'
switch tokens[0] { switch tokens[0] {
case "top", "up": case "top", "up":

View File

@ -9,13 +9,16 @@ import (
func runTmux(args []string, opts *Options) (int, error) { func runTmux(args []string, opts *Options) (int, error) {
// Prepare arguments // Prepare arguments
fzf := args[0] fzf, rest := args[0], args[1:]
args = append([]string{"--bind=ctrl-z:ignore"}, args[1:]...) args = []string{"--bind=ctrl-z:ignore"}
if opts.BorderShape == tui.BorderUndefined { if !opts.Tmux.border && opts.BorderShape == tui.BorderUndefined {
args = append(args, "--border") args = append(args, "--border")
} }
if opts.Tmux.border && opts.Margin == defaultMargin() {
args = append(args, "--margin=0,1")
}
argStr := escapeSingleQuote(fzf) argStr := escapeSingleQuote(fzf)
for _, arg := range args { for _, arg := range append(args, rest...) {
argStr += " " + escapeSingleQuote(arg) argStr += " " + escapeSingleQuote(arg)
} }
argStr += ` --no-tmux --no-height` argStr += ` --no-tmux --no-height`
@ -33,7 +36,10 @@ func runTmux(args []string, opts *Options) (int, error) {
// M Both The mouse position // M Both The mouse position
// W Both The window position on the status line // W Both The window position on the status line
// S -y The line above or below the status line // S -y The line above or below the status line
tmuxArgs := []string{"display-popup", "-E", "-B", "-d", dir} tmuxArgs := []string{"display-popup", "-E", "-d", dir}
if !opts.Tmux.border {
tmuxArgs = append(tmuxArgs, "-B")
}
switch opts.Tmux.position { switch opts.Tmux.position {
case posUp: case posUp:
tmuxArgs = append(tmuxArgs, "-xC", "-y0") tmuxArgs = append(tmuxArgs, "-xC", "-y0")