Make --tmux argument optional
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent 1d59ac0 · Browse files · 2 files·+23 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+23 added−20 removed
- other:+23 added−20 removed
Provenance
- Commit
12630b1- Tree
9183270- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
1d59ac0
2 files changed+23 added−20 removed
modified:man/man1/fzf.1+5 added-5 removed
226 unmodified lines227 .BI "--min-height=" "HEIGHT"228 Minimum height when \fB--height\fR is given in percent (default: 10).229 Ignored when \fB--height\fR is not specified.230 .TP231-.BI "--tmux=" "[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]"232-Start fzf in a tmux popup. Requires tmux 3.3 or later. This option is ignored233-if you are not running fzf inside tmux.231+.BI "--tmux" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]]"232+Start fzf in a tmux popup (default \fBcenter,50%\fR). Requires tmux 3.3 or233+later. This option is ignored if you are not running fzf inside tmux.234 235 e.g.236- \fB# Popup in the center with 80% width height237- fzf --tmux 80%236+ \fB# Popup in the center with 70% width and height237+ fzf --tmux 70%238 239 # Popup on the left with 40% width and 100% height240 fzf --tmux right,40%241 1377 unmodified linesmodified:src/options.go+18 added-15 removed
69 unmodified lines70 If prefixed with '~', fzf will determine the height71 according to the input size.72 --min-height=HEIGHT Minimum height when --height is given in percent73 (default: 10)74- --tmux=OPTS Start fzf in a tmux popup (requires tmux 3.3+)74+ --tmux[=OPTS] Start fzf in a tmux popup (requires tmux 3.3+)75 [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]76+ (default: center,50%)77 --layout=LAYOUT Choose layout: [default|reverse|reverse-list]78 --border[=STYLE] Draw border around the finder79 [rounded|sharp|bold|block|thinblock|double|horizontal|vertical|80 top|bottom|left|right|none] (default: rounded)197 unmodified lines278 func (o *previewOpts) Toggle() {279 o.hidden = !o.hidden280 }281 282+func defaultTmuxOptions() *tmuxOptions {283+ return &tmuxOptions{284+ position: posCenter,285+ width: sizeSpec{50, true},286+ height: sizeSpec{50, true}}287+}288+289 func parseTmuxOptions(arg string) (*tmuxOptions, error) {290 var err error283- opts := tmuxOptions{}291+ opts := defaultTmuxOptions()292 tokens := splitRegexp.Split(arg, -1)293 if len(tokens) == 0 || len(tokens) > 3 {294 return nil, errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]])")295 }12 unmodified lines308 case "right":309 opts.position = posRight310 opts.height = sizeSpec{100, true}311 case "center":304- opts.position = posCenter305- opts.width = sizeSpec{50, true}306- opts.height = sizeSpec{50, true}312 default:308- opts.position = posCenter309- opts.width = sizeSpec{50, true}310- opts.height = sizeSpec{50, true}313 tokens = append([]string{"center"}, tokens...)314 }315 316 // One size given27 unmodified lines344 opts.height = size1345 }346 }347 346- return &opts, nil348+ return opts, nil349 }350 351 func parseLabelPosition(opts *labelOpts, arg string) error {352 opts.column = 01589 unmodified lines1942 opts.Version = true1943 case "--no-winpty":1944 opts.NoWinpty = true1945 case "--tmux":1944- str, err := nextString(allArgs, &i, "tmux options required")1945- if err != nil {1946- return err1946+ given, str := optionalNextString(allArgs, &i)1947+ if given {1948+ if opts.Tmux, err = parseTmuxOptions(str); err != nil {1949+ return err1950+ }1951+ } else {1952+ opts.Tmux = defaultTmuxOptions()1953 }1948- if opts.Tmux, err = parseTmuxOptions(str); err != nil {1949- return err1950- }1954 case "--no-tmux":1955 opts.Tmux = nil1956 case "--force-tty-in":1957 // NOTE: We need this because `system('fzf --tmux < /dev/tty')` doesn't939 unmodified lines