From 5c11cad2256038645af10dc79b471890fae629df Mon Sep 17 00:00:00 2001 From: Ben Elan Date: Sat, 13 Jul 2024 01:58:15 -0700 Subject: [PATCH] feat(ui)!: support auto-resizing preview window by results length - Add `alt-_` keybinding, which moves the preview window to the bottom and enables auto-resizing based on the list item count - Add `alt-|` keybinding, which switches back to the default preview window on the right with no auto-resizing - The preview window settings do not override a user's FZF_DEFAULT_OPTS configuration BREAKING CHANGE: Requires fzf version >= 0.45.0 for the transform action ref: https://github.com/junegunn/fzf/releases/tag/0.45.0 --- gh-fzf | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/gh-fzf b/gh-fzf index 88f65cd..e006c95 100755 --- a/gh-fzf +++ b/gh-fzf @@ -121,14 +121,32 @@ else GH_COLUMNS='9999999' fi +# https://github.com/junegunn/fzf/releases/tag/0.46.0 +PREVIEW_TRANSFORMER=' + lines=\$(( FZF_LINES - FZF_MATCH_COUNT - 8 )); + if [[ \$FZF_MATCH_COUNT -eq 0 ]]; then + echo \"change-preview-window:hidden,<75(hidden)\"; + elif [[ \$lines -gt 3 ]]; then + echo \"change-preview-window:down,border-top,\$lines,wrap,<75(down,border-top,\$lineswrap)\"; + elif [[ \$FZF_PREVIEW_LINES -ne 3 ]]; then + echo \"change-preview-window:down,border-top,wrap,<75(down,border-top,wrap)\" + fi +' + # The following fzf options are shared by all commands. They are prepended to # the FZF_DEFAULT_OPTS environment variable so they can be overridden by users. export FZF_DEFAULT_OPTS=' --no-hscroll --no-exit-0 --header-lines=1 --cycle --reverse --info=right ---color "fg:#ebdbb2,fg+:#ebdbb2,bg:#282828,bg+:#3c3836,hl:#d3869b:bold,hl+:#d3869b,info:#83a598,prompt:#bdae93,spinner:#fabd2f,pointer:#83a598,marker:#fe8019,header:#928374,label:#83a598" +--color "fg:#ebdbb2,fg+:#ebdbb2,bg:#282828,bg+:#3c3836,hl:#d3869b:bold,hl+:#d3869b" +--color "info:#83a598,prompt:#bdae93,spinner:#fabd2f,pointer:#83a598,marker:#fe8019,header:#928374,label:#83a598" --preview-window="right,border-left,wrap,<75(down,border-top,wrap)" ---bind="alt-P:change-preview-window(down,70%,border-top,<75(down,70%,border-top,wrap)|hidden,<75(hidden)|)" +--bind "result:transform('"$PREVIEW_TRANSFORMER"')" +--bind "resize:transform('"$PREVIEW_TRANSFORMER"')" --bind="alt-H:toggle-header" +--bind="start:unbind(resize)+unbind(result)'${GH_FZF_HIDE_HINTS:+"+toggle-header"}'" +--bind "alt-|:rebind(alt-H)+unbind(result)+unbind(resize)+change-preview-window(right,border-left,wrap,<75(down,border-top,wrap))" +--bind "alt-_:show-header+unbind(alt-H)+rebind(result)+rebind(resize)+change-preview-window(down,border-top,wrap)" +--bind="alt-P:change-preview-window(down,70%,border-top,<75(down,70%,border-top,wrap)|hidden,<75(hidden)|)" --bind="ctrl-r:reload(eval \"$FZF_DEFAULT_COMMAND\")" --bind="alt-1:reload(eval \"$FZF_DEFAULT_COMMAND -L100\")" --bind="alt-2:reload(eval \"$FZF_DEFAULT_COMMAND -L200\")" @@ -214,7 +232,6 @@ $global_binds fzf \ --preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh issue view {1} --comments '"$REPO_FLAG" \ --header="$issue_header" \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind="ctrl-o:execute-silent(gh issue view --web {1} $REPO_FLAG &)+refresh-preview" \ --bind="ctrl-y:execute-silent(gh fzf util copy-url issue {1})+refresh-preview" \ --bind="enter:execute(gh issue edit {1} $REPO_FLAG)+refresh-preview" \ @@ -297,7 +314,6 @@ $global_binds fzf \ --preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh pr view {1} --comments '"$REPO_FLAG" \ --header="$pr_header" \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind="ctrl-o:execute-silent(gh pr view --web {1} $REPO_FLAG &)+refresh-preview" \ --bind="ctrl-y:execute-silent(gh fzf util copy-url pr {1})+refresh-preview" \ --bind="alt-y:execute-silent( @@ -389,7 +405,6 @@ $global_binds fzf \ --preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh run view {-1} '"$REPO_FLAG" \ --header="$run_header" \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind="ctrl-o:execute-silent(gh run view --web {-1} $REPO_FLAG &)+refresh-preview" \ --bind="ctrl-y:execute-silent(gh fzf util copy-url run {-1})+refresh-preview" \ --bind="enter:execute( @@ -438,7 +453,6 @@ $global_binds fzf \ --preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh workflow view --yaml {-1} '"$REPO_FLAG" \ --header="$workflow_header" \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind="ctrl-o:execute-silent(gh workflow view --web {-1} $REPO_FLAG &)+refresh-preview" \ --bind="enter:execute(gh fzf run --workflow {-1} $REPO_FLAG)+refresh-preview" \ --bind="alt-d:execute(gh workflow run {-1} $REPO_FLAG)+refresh-preview" \ @@ -501,7 +515,6 @@ $global_binds fzf \ --preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh release view {1} '"$REPO_FLAG" \ --header="$release_header" \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind="ctrl-o:execute-silent(gh release view --web {1} $REPO_FLAG &)+refresh-preview" \ --bind="ctrl-y:execute-silent(gh fzf util copy-url release {1})+refresh-preview" \ --bind="alt-enter:execute(gh release download {1} $REPO_FLAG)+refresh-preview" \ @@ -530,7 +543,6 @@ $global_binds --no-preview \ --header-lines=4 \ --header="$label_header" \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind="enter:become(printf '%s\n' {+} | awk -F' ' '{print \$1}')" \ --bind="ctrl-o:execute-silent(gh label list --web $REPO_FLAG &)" \ --bind='alt-n:execute( @@ -606,7 +618,6 @@ Globals > (ctrl-o: open url) (ctrl-y: copy url) (ctrl-r: reload) fzf \ --no-preview \ --header="$milestone_header" \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind="enter:become(echo {1})" \ --bind="ctrl-y:execute-silent( gh api --jq '.html_url' \ @@ -709,7 +720,6 @@ $global_binds --preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh repo view {1}' \ --header="$repo_header" \ --header-lines=4 \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind="ctrl-o:execute-silent(gh repo view --web {1} &)+refresh-preview" \ --bind="ctrl-y:execute-silent(gh fzf util copy-url repo {1})+refresh-preview" \ --bind="alt-p:execute(gh fzf pr --repo {1})+refresh-preview" \ @@ -742,7 +752,6 @@ Filters > (alt-p: public) (alt-s: secret) fzf \ --preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh gist view {1}' \ --header="$gist_header" \ - --bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \ --bind='ctrl-o:execute-silent(gh gist view --web {1} &)+refresh-preview' \ --bind="ctrl-y:execute-silent( echo https://gist.github.com/$(gh api user -q .login)/{1} | $GH_FZF_COPY_CMD