summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-28 18:34:12 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-28 18:34:12 +0900
commiteb0257d48f8362ff91df162ac4bc07ac0693ba27 (patch)
tree3ca94beb69273ea7b08cc52388824cc528c81d18
parentb83dd6c6b426da99e11a8b3c58c075c70ee2700a (diff)
downloadfzf-eb0257d48f8362ff91df162ac4bc07ac0693ba27.tar.gz
Enhance --min-height option to take number followed by +
-rw-r--r--CHANGELOG.md9
-rw-r--r--man/man1/fzf.19
-rw-r--r--shell/completion.bash2
-rw-r--r--shell/completion.zsh2
-rw-r--r--shell/key-bindings.bash2
-rw-r--r--shell/key-bindings.fish2
-rw-r--r--shell/key-bindings.zsh2
-rw-r--r--src/options.go26
-rw-r--r--test/test_layout.rb31
9 files changed, 71 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c961a11..e4d51c75 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -53,6 +53,15 @@ CHANGELOG
# Load 'ps -ef' output on start and reload it on CTRL-R
fzf --bind 'start,ctrl-r:reload:ps -ef'
```
+- `--min-height` option now takes a number followed by `+`, which tells fzf to show at least that many items in the list section. The default value is now changed to `10+`.
+ ```sh
+ # You will only see the input section which takes 3 lines
+ fzf --style=full --height 1% --min-height 3
+
+ # You will see 3 items in the list section
+ fzf --style full --height 1% --min-height 3+
+ ```
+ - Shell integration scripts were updated to use `--min-height 20+` by default
- Added `bell` action to ring the terminal bell
```sh
# Press CTRL-Y to copy the current line to the clipboard and ring the bell
diff --git a/man/man1/fzf.1 b/man/man1/fzf.1
index eefb1fbc..ad205920 100644
--- a/man/man1/fzf.1
+++ b/man/man1/fzf.1
@@ -336,9 +336,12 @@ Adaptive height has the following limitations:
* It will not find the right size when there are multi-line items
.TP
-.BI "\-\-min\-height=" "HEIGHT"
-Minimum height when \fB\-\-height\fR is given in percent (default: 10).
-Ignored when \fB\-\-height\fR is not specified.
+.BI "\-\-min\-height=" "HEIGHT[+]"
+Minimum height when \fB\-\-height\fR is given as a percentage.
+Add \fB+\fR to automatically increase the value according to the other
+layout options so that the specified number of items are visible in the list
+section (default: \fB10+\fR).
+Ignored when \fB\-\-height\fR is not specified or set as an absolute value.
.TP
.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
diff --git a/shell/completion.bash b/shell/completion.bash
index 686ca4c6..d1fc57b9 100644
--- a/shell/completion.bash
+++ b/shell/completion.bash
@@ -37,7 +37,7 @@ bind '"\e[0n": redraw-current-line' 2> /dev/null
__fzf_defaults() {
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
- echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
+ echo "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
echo "${FZF_DEFAULT_OPTS-} $2"
}
diff --git a/shell/completion.zsh b/shell/completion.zsh
index 22c662b0..ebc5a820 100644
--- a/shell/completion.zsh
+++ b/shell/completion.zsh
@@ -99,7 +99,7 @@ if [[ -o interactive ]]; then
__fzf_defaults() {
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
- echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
+ echo "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
echo "${FZF_DEFAULT_OPTS-} $2"
}
diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash
index 2da32cba..8b0ef76c 100644
--- a/shell/key-bindings.bash
+++ b/shell/key-bindings.bash
@@ -20,7 +20,7 @@ if [[ $- =~ i ]]; then
__fzf_defaults() {
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
- echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
+ echo "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
echo "${FZF_DEFAULT_OPTS-} $2"
}
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index 15c53ef2..18280a94 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -20,7 +20,7 @@ function fzf_key_bindings
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
- echo "--height $FZF_TMUX_HEIGHT --bind=ctrl-z:ignore" $argv[1]
+ echo "--height $FZF_TMUX_HEIGHT --min-height 20+ --bind=ctrl-z:ignore" $argv[1]
test -r "$FZF_DEFAULT_OPTS_FILE"; and string collect -N -- <$FZF_DEFAULT_OPTS_FILE
echo $FZF_DEFAULT_OPTS $argv[2]
end
diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh
index 3c17401c..46580670 100644
--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -41,7 +41,7 @@ if [[ -o interactive ]]; then
__fzf_defaults() {
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
- echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
+ echo "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
echo "${FZF_DEFAULT_OPTS-} $2"
}
diff --git a/src/options.go b/src/options.go
index 9c0bd2ed..cc627ee1 100644
--- a/src/options.go
+++ b/src/options.go
@@ -69,8 +69,9 @@ Usage: fzf [options]
minus the given value.
If prefixed with '~', fzf will determine the height
according to the input size.
- --min-height=HEIGHT Minimum height for percent --height is given in percent
- (default: 10 or above depending on the other options)
+ --min-height=HEIGHT[+] Minimum height when --height is given as a percentage.
+ Add '+' to automatically increase the value
+ according to the other layout options (default: 10+).
--tmux[=OPTS] Start fzf in a tmux popup (requires tmux 3.3+)
[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]
[,border-native] (default: center,50%)
@@ -673,7 +674,7 @@ func defaultOptions() *Options {
Theme: theme,
Black: false,
Bold: true,
- MinHeight: -1,
+ MinHeight: -10,
Layout: layoutDefault,
Cycle: false,
Wrap: false,
@@ -2662,9 +2663,23 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
return err
}
case "--min-height":
- if opts.MinHeight, err = nextInt("height required: HEIGHT"); err != nil {
+ expr, err := nextString("minimum height required: HEIGHT[+]")
+ if err != nil {
return err
}
+ auto := false
+ if strings.HasSuffix(expr, "+") {
+ expr = expr[:len(expr)-1]
+ auto = true
+ }
+ num, err := atoi(expr)
+ if err != nil || num < 0 {
+ return errors.New("minimum height must be a non-negative integer")
+ }
+ if auto {
+ num *= -1
+ }
+ opts.MinHeight = num
case "--no-height":
opts.Height = heightSpec{}
case "--no-margin":
@@ -3220,8 +3235,7 @@ func postProcessOptions(opts *Options) error {
// Sets --min-height automatically
if opts.Height.size > 0 && opts.Height.percent && opts.MinHeight < 0 {
- // 10 items and 1 prompt line
- opts.MinHeight = 10 + 1 + borderLines(opts.BorderShape) + borderLines(opts.ListBorderShape) + borderLines(opts.InputBorderShape)
+ opts.MinHeight = -opts.MinHeight + 1 + borderLines(opts.BorderShape) + borderLines(opts.ListBorderShape) + borderLines(opts.InputBorderShape)
if len(opts.Header) > 0 {
opts.MinHeight += borderLines(opts.HeaderBorderShape) + len(opts.Header)
}
diff --git a/test/test_layout.rb b/test/test_layout.rb
index 5bf441d2..dcfe1d78 100644
--- a/test/test_layout.rb
+++ b/test/test_layout.rb
@@ -845,4 +845,35 @@ class TestLayout < TestInteractive
assert lines[1]&.end_with?('1000││')
end
end
+
+ def test_min_height_no_auto
+ tmux.send_keys %(seq 100 | #{FZF} --border sharp --style full:sharp --height 1% --min-height 5), :Enter
+
+ block = <<~BLOCK
+ ┌───────
+ │ ┌─────
+ │ │ >
+ │ └─────
+ └───────
+ BLOCK
+ tmux.until { assert_block(block, _1) }
+ end
+
+ def test_min_height_auto
+ tmux.send_keys %(seq 100 | #{FZF} --style full:sharp --height 1% --min-height 5+), :Enter
+
+ block = <<~BLOCK
+ ┌─────────
+ │ 5
+ │ 4
+ │ 3
+ │ 2
+ │ > 1
+ └─────────
+ ┌─────────
+ │ >
+ └─────────
+ BLOCK
+ tmux.until { assert_block(block, _1) }
+ end
end