Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui)!: support auto-resizing preview window by results length #31

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions gh-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ 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
'

# set shell so bash features can be used in subshells created by fzf
export SHELL="bash"

Expand All @@ -161,8 +173,14 @@ export FZF_DEFAULT_OPTS='
--color="info:#83a598,prompt:#bdae93,spinner:#fabd2f,pointer:#83a598,marker:#fe8019,header:#928374,label:#83a598"
'${GH_STATUS:+--preview-label=\"$GH_STATUS\" --color=\"preview-label:#b57614,preview-border:#b57614\"}'
--preview-window="right,wrap,<75(down,wrap)"
--bind "result:transform('"$PREVIEW_TRANSFORMER"')"
--bind "resize:transform('"$PREVIEW_TRANSFORMER"')"
--bind="alt-P:change-preview-window(down,70%,<75(down,70%,wrap)|hidden,<75(hidden)|)"
--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\")"
Expand Down Expand Up @@ -249,7 +267,6 @@ $global_binds
--preview='GH_FORCE_TTY=$((FZF_PREVIEW_COLUMNS-3)) gh issue view {1} --comments' \
--prompt="issue ❱ " \
--header="$issue_header" \
--bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \
--bind="ctrl-o:execute-silent(gh issue view --web {1} &)+refresh-preview" \
--bind="ctrl-y:execute-silent(gh fzf util copy-url issue {1})+refresh-preview" \
--bind="enter:execute(gh issue edit {1})+refresh-preview" \
Expand Down Expand Up @@ -335,7 +352,6 @@ $global_binds
--preview='GH_FORCE_TTY=$((FZF_PREVIEW_COLUMNS-3)) gh pr view {1} --comments' \
--prompt="pr ❱ " \
--header="$pr_header" \
--bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \
--bind="ctrl-o:execute-silent(gh pr view --web {1} &)+refresh-preview" \
--bind="ctrl-y:execute-silent(gh fzf util copy-url pr {1})+refresh-preview" \
--bind="alt-y:execute-silent(
Expand Down Expand Up @@ -428,7 +444,6 @@ $global_binds
--preview='GH_FORCE_TTY=$((FZF_PREVIEW_COLUMNS-3)) gh run view {-1}' \
--prompt="run ❱ " \
--header="$run_header" \
--bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \
--bind="ctrl-o:execute-silent(gh run view --web {-1} &)+refresh-preview" \
--bind="ctrl-y:execute-silent(gh fzf util copy-url run {-1})+refresh-preview" \
--bind="enter:execute(
Expand Down Expand Up @@ -502,7 +517,6 @@ $global_binds
--prompt="workflow ❱ " \
--preview='GH_FORCE_TTY=$((FZF_PREVIEW_COLUMNS-3)) gh workflow view --yaml {-1}' \
--header="$workflow_header" \
--bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \
--bind="ctrl-o:execute-silent(gh workflow view --web {-1} &)+refresh-preview" \
--bind="ctrl-y:execute-silent(gh browse --no-browser {-2} | $GH_FZF_COPY_CMD)+refresh-preview" \
--bind="enter:execute(gh fzf run --workflow {-1})+refresh-preview" \
Expand Down Expand Up @@ -567,7 +581,6 @@ $global_binds
--preview='GH_FORCE_TTY=$((FZF_PREVIEW_COLUMNS-3)) gh release view {1}' \
--prompt="release ❱ " \
--header="$release_header" \
--bind="start:${GH_FZF_HIDE_HINTS:+"toggle-header"}" \
--bind="ctrl-o:execute-silent(gh release view --web {1} &)+refresh-preview" \
--bind="ctrl-y:execute-silent(gh fzf util copy-url release {1})+refresh-preview" \
--bind="alt-enter:execute(gh release download {1})+refresh-preview" \
Expand Down Expand Up @@ -597,7 +610,6 @@ $global_binds
--prompt="label ❱ " \
--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 &)" \
--bind='alt-n:execute(
Expand Down Expand Up @@ -674,7 +686,6 @@ Globals > (ctrl-o: open url) (ctrl-y: copy url) (ctrl-r: reload)
--no-preview \
--prompt="milestone ❱ " \
--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' \
Expand Down Expand Up @@ -778,7 +789,6 @@ $global_binds
--prompt="repo ❱ " \
--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" \
Expand Down Expand Up @@ -812,7 +822,6 @@ Filters > (alt-p: public) (alt-s: secret)
--preview='GH_FORCE_TTY=$((FZF_PREVIEW_COLUMNS-3)) gh gist view {1}' \
--prompt="gist ❱ " \
--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
Expand Down