Make --tmux argument optional

This commit is contained in:
Junegunn Choi
2024-05-29 02:09:32 +09:00
parent 1d59ac09d2
commit 12630b124d
2 changed files with 23 additions and 20 deletions

View File

@@ -228,13 +228,13 @@ 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[%]]]"
Start fzf in a tmux popup. Requires tmux 3.3 or later. This option is ignored Start fzf in a tmux popup (default \fBcenter,50%\fR). Requires tmux 3.3 or
if you are not running fzf inside tmux. later. This option is ignored if you are not running fzf inside tmux.
e.g. e.g.
\fB# Popup in the center with 80% width height \fB# Popup in the center with 70% width and height
fzf --tmux 80% fzf --tmux 70%
# Popup on the left with 40% width and 100% height # Popup on the left with 40% width and 100% height
fzf --tmux right,40% fzf --tmux right,40%

View File

@@ -71,8 +71,9 @@ Usage: fzf [options]
according to the input size. according to the input size.
--min-height=HEIGHT Minimum height when --height is given in percent --min-height=HEIGHT Minimum height when --height is given in percent
(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%)
--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|
@@ -278,9 +279,16 @@ func (o *previewOpts) Toggle() {
o.hidden = !o.hidden o.hidden = !o.hidden
} }
func defaultTmuxOptions() *tmuxOptions {
return &tmuxOptions{
position: posCenter,
width: sizeSpec{50, true},
height: sizeSpec{50, true}}
}
func parseTmuxOptions(arg string) (*tmuxOptions, error) { func parseTmuxOptions(arg string) (*tmuxOptions, error) {
var err error var err error
opts := tmuxOptions{} opts := defaultTmuxOptions()
tokens := splitRegexp.Split(arg, -1) tokens := splitRegexp.Split(arg, -1)
if len(tokens) == 0 || len(tokens) > 3 { if len(tokens) == 0 || len(tokens) > 3 {
return nil, errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]])") return nil, errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]])")
@@ -301,13 +309,7 @@ func parseTmuxOptions(arg string) (*tmuxOptions, error) {
opts.position = posRight opts.position = posRight
opts.height = sizeSpec{100, true} opts.height = sizeSpec{100, true}
case "center": case "center":
opts.position = posCenter
opts.width = sizeSpec{50, true}
opts.height = sizeSpec{50, true}
default: default:
opts.position = posCenter
opts.width = sizeSpec{50, true}
opts.height = sizeSpec{50, true}
tokens = append([]string{"center"}, tokens...) tokens = append([]string{"center"}, tokens...)
} }
@@ -343,7 +345,7 @@ func parseTmuxOptions(arg string) (*tmuxOptions, error) {
} }
} }
return &opts, nil return opts, nil
} }
func parseLabelPosition(opts *labelOpts, arg string) error { func parseLabelPosition(opts *labelOpts, arg string) error {
@@ -1941,12 +1943,13 @@ func parseOptions(opts *Options, allArgs []string) error {
case "--no-winpty": case "--no-winpty":
opts.NoWinpty = true opts.NoWinpty = true
case "--tmux": case "--tmux":
str, err := nextString(allArgs, &i, "tmux options required") given, str := optionalNextString(allArgs, &i)
if err != nil { if given {
return err if opts.Tmux, err = parseTmuxOptions(str); err != nil {
} return err
if opts.Tmux, err = parseTmuxOptions(str); err != nil { }
return err } else {
opts.Tmux = defaultTmuxOptions()
} }
case "--no-tmux": case "--no-tmux":
opts.Tmux = nil opts.Tmux = nil