Aloxaf / fzf-tab

Replace zsh's default completion selection menu with fzf!
MIT License
3.18k stars 94 forks source link

[BUG] Preview always shows "fork/exec /usr/bin/zsh: invalid argument" #461

Open LoveCatc opened 1 month ago

LoveCatc commented 1 month ago

Describe the bug

The preview window shows "fork/exec /usr/bin/zsh: invalid argument" and it even happens when opening logs (C-x .).

I can make sure:

To Reproduce

Steps to reproduce the behavior:

  1. Type ls
  2. Press Tab
  3. See error

Expected behavior

The preview window should give correct information instead of an error.

Screenshots

image

Environment:

Minimal zshrc

.zshrc

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

if [[ ! -f ~/.zinit/bin/zinit.zsh ]]; then
    mkdir ~/.zinit
    git clone https://github.com/zdharma-continuum/zinit.git ~/.zinit/bin
fi

# load zinit
source ~/.zinit/bin/zinit.zsh

# 加载 OMZ 框架及部分插件
zinit snippet OMZ::lib/completion.zsh
zinit snippet OMZ::lib/history.zsh
zinit snippet OMZ::lib/key-bindings.zsh
zinit snippet OMZ::lib/theme-and-appearance.zsh
zinit snippet OMZ::lib/directories.zsh
zinit snippet OMZ::plugins/colored-man-pages/colored-man-pages.plugin.zsh
zinit snippet OMZ::plugins/sudo/sudo.plugin.zsh
zinit snippet OMZ::plugins/mvn/mvn.plugin.zsh
zinit snippet OMZ::plugins/tmux/tmux.plugin.zsh
zinit snippet OMZ::plugins/tmuxinator/tmuxinator.plugin.zsh
zinit snippet OMZ::plugins/command-not-found/command-not-found.plugin.zsh
zinit snippet OMZ::plugins/pip/pip.plugin.zsh

# zinit light denysdovhan/spaceship-prompt
zinit ice depth=1; zinit light romkatv/powerlevel10k

autoload -Uz compinit

# binary release, unpack provide fzf
zinit ice from"gh-r" as"program"
zinit light junegunn/fzf
zinit light Aloxaf/fzf-tab

# 语法高亮
zinit ice lucid wait='0' atinit='zpcompinit'
zinit light zdharma-continuum/fast-syntax-highlighting

# 自动建议
zinit ice lucid wait="0" atload='_zsh_autosuggest_start'
zinit light zsh-users/zsh-autosuggestions

# 补全
zinit ice lucid wait='0'
zinit light zsh-users/zsh-completions

source $HOME/dotfiles/zsh/fzf.zsh

[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

fzf.zsh

export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git --exclude .idea ""'

export FZF_DEFAULT_OPTS="--height 40% --layout=reverse --preview '(highlight -O ansi {} || cat {}) 2> /dev/null | head -500'"

# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# set descriptions format to enable group support
# NOTE: don't use escape sequences here, fzf-tab will ignore them
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# force zsh not to show completion menu, which allows fzf-tab to capture the unambiguous prefix
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'
# switch group using `<` and `>`
zstyle ':fzf-tab:*' switch-group '<' '>'

Log

If applicable, use C-x . to trigger completion and provide the log.

If there are only three lines in your log, please make sure your fzf-tab is loaded with the correct order (see the checklist above).

no logs are shown. image

NightWatcher314 commented 3 weeks ago

I have the same issue with you.

I reduce my config file step by step, and find the problem in line zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath' the command eza doesn't exsit on my computer. After I run sudo apt install eza, the problem fixed.

LoveCatc commented 3 weeks ago

Hi NightWatcher314, thank you for the sincere help! Unfortunately, this does not solve my problem. But you provide a very nice point, and I should look through the config more carefully. Anyway thank you again!

lsalazarm99 commented 2 days ago

I have the same problem. It's related to the FZF_DEFAULT_OPTS variable, specifically the "--preview" argument.

I know that's a fzf thing, but the issue only happens when I use fzf through this plugin. If I simply run fzf, the preview window works fine.

lsalazarm99 commented 2 days ago

Also, if I use the fzf plugin (for example, writing nano ** and pressing Tab) it also works fine.