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

Add use-fzf-default-opts #479

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ zstyle ':completion:*' menu no
# preview directory's content with eza when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
# custom fzf flags
# NOTE: fzf-tab does not follow FZF_DEFAULT_OPTS
# NOTE: fzf-tab does not follow FZF_DEFAULT_OPTS by default
zstyle ':fzf-tab:*' fzf-flags --color=fg:1,fg+:2 --bind=tab:accept
# To make fzf-tab follow FZF_DEFAULT_OPTS.
# NOTE: This may lead to unexpected behavior since some flags break this plugin. See Aloxaf/fzf-tab#455.
zstyle ':fzf-tab:*' use-fzf-default-opts yes
# switch group using `<` and `>`
zstyle ':fzf-tab:*' switch-group '<' '>'
```
Expand Down
8 changes: 7 additions & 1 deletion lib/-ftb-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ local ret=0
-ftb-zstyle -a switch-group switch_group || switch_group=(F1 F2)
-ftb-zstyle -s fzf-pad fzf_pad || fzf_pad=2
-ftb-zstyle -s fzf-min-height fzf_min_height || fzf_min_height=0
-ftb-zstyle -b use-fzf-default-opts use_fzf_default_opts || use_fzf_default_opts="no"

-ftb-zstyle -a debug-command debug_command && {
${(eX)debug_command} $fzf_flags
Expand Down Expand Up @@ -81,7 +82,12 @@ fi

_ftb_query="${_ftb_query}$(command "$dd" bs=1G count=1 status=none iflag=nonblock < /dev/tty 2>/dev/null)" || true

FZF_DEFAULT_OPTS='' SHELL=$ZSH_NAME $fzf_command \
local fzf_default_opts=''
if [[ "$use_fzf_default_opts" == "yes" ]]; then
fzf_default_opts=$FZF_DEFAULT_OPTS
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if fzf_default_opts couldn't be set outside like this:
zstyle ':fzf-tab:*' fzf-default-opts $FZF_DEFAULT_OPTS
?

I that case you could get ride off the use_fzf_default_opts option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was going for a quick change so didn't try that. I thought zstyle might parse things differently and lead to unintended behaviors.

Let me try that and get back here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I remember it now. Since FZF_DEFAULT_OPTS is a bunch of flags, we need to pass it as such and not as an environment variable.

And fzf-flags already exists in the plugin. But when I tried setting that equal to the flags in FZF_DEFAULT_OPTS (see below), it wasn't working. I think the reason is the same as what I mentioned in #475 (comment).

# this converts the string to a string array which is expected by fzf-flags.
export parsed_fzf_default_opts=(${=FZF_DEFAULT_OPTS})

zstyle ':fzf-tab:*' fzf-flags $parsed_fzf_default_opts

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion doesn't seem to be working for my case:

export FZF_DEFAULT_OPTS="          \
  --exact                          \
  --height ${FZF_TMUX_HEIGHT:-30%} \
  --layout=reverse                 \
  --info=hidden                    \
  --prompt='$  '                   \
  --pointer='=>'                   \
  --marker='+'                     \
  --cycle                          \
  --select-1                       \
  --color=dark                     \
  --bind '?:toggle-preview,ctrl-a:select-all,ctrl-d:half-page-down,ctrl-u:half-page-up,ctrl-l:clear-query,home:first,end:last,enter:accept-non-empty,alt-down:down,alt-up:up,right:accept-non-empty,alt-right:accept-non-empty,alt-left:close,left:close' \
  --color='fg:-1,bg:-1,hl:#fb8aa4,fg+:-1,bg+:-1,hl+:#55E579' \
  --color='info:#af87ff,prompt:#fb8aa4,pointer:#55E579,marker:#55E579,spinner:#55E579'
"

I think the --height ${FZF_TMUX_HEIGHT:-30%} is not correctly handle.

Copy link
Owner

@Aloxaf Aloxaf Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pablospe can you try this?

zstyle ':fzf-tab:*' fzf-flags ${(Q)${(Z:nC:)FZF_DEFAULT_OPTS}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is magic! It is working, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are my flags,

# Set fzf options
export FZF_DEFAULT_OPTS=$FZF_DEFAULT_OPTS'
    --color=bg:#1b1b1b
    --color=preview-bg:#1b1b1b
    --color=hl+:#fb4934
    --color=gutter:#1b1b1b
    --color=pointer:#f9f5d7,marker:#f9f5d7
    --color=info:#ebdbb2,spinner:#f9f5d7
    --color=query:#ebdbb2,prompt:#ebdbb2
    --color=border:#ebdbb2
    --border="rounded" --prompt="> "
    --marker="" --pointer="->" --layout="reverse"
'

While echo ${(Q)${(Z:nC:)FZF_DEFAULT_OPTS}} looks as expected, when I try to open fzf-tab, it fails with an eval error.

fi

FZF_DEFAULT_OPTS=$fzf_default_opts SHELL=$ZSH_NAME $fzf_command \
--ansi \
--bind=$binds \
--bind="${switch_group[1]}:reload($reload_command -1),${switch_group[2]}:reload($reload_command 1)" \
Expand Down