unixorn / fzf-zsh-plugin

ZSH plugin to enable fzf searches of a lot more stuff - docker, tmux, homebrew and more.
Apache License 2.0
303 stars 27 forks source link

CTRL-t not working in zsh #50

Closed Dhruv-mak closed 6 months ago

Dhruv-mak commented 2 years ago

I am using oh-my-zsh for managing my zsh configuration. I installed fzf-zsh-plugin via these instructions.I have just installed Ubuntu:20.04.3 LTS. I went through this issue. but my ~/.zshrc contains this lines.

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

the CTRL-r is working perfectly. But when i press Alt-c or CTRL-t it gives me error msg that:

(eval):1: unknown file attribute:
   <  0/0 (0)

The output of bindkey | grep fzf is:

"^I" fzf-completion
"^R" fzf-history-widget
"^T" fzf-file-widget
"^[c" fzf-cd-widget
unixorn commented 2 years ago

Odd, things are working on my system. What's the output of printenv | grep FZF?

unixorn commented 2 years ago

Also, does which fzf-file-widget or which fzf-cd-widget show that they ended up defined?

Dhruv-mak commented 2 years ago

The output of printenv | grep FZF is:

FZF_DEFAULT_COMMAND=find . -type f ( -path .git -o -path node_modules ) -prune
FZF_ALT_C_COMMAND=find . -type d ( -path .git -o -path node_modules ) -prune
FZF_DEFAULT_OPTS=--layout=reverse
FZF_CTRL_T_COMMAND=find . -type f ( -path .git -o -path node_modules ) -prune

The output for which fzf-file-widget is:

fzf-file-widget () {
    LBUFFER="${LBUFFER}$(__fsel)" 
    local ret=$? 
    zle reset-prompt
    return $ret
}

And the output of which fzf-cd-widget is:

fzf-cd-widget () {
    local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune     -o -type d -print 2> /dev/null | cut -b3-"}" 
    setopt localoptions pipefail no_aliases 2> /dev/null
    local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)" 
    if [[ -z "$dir" ]]
    then
        zle redisplay
        return 0
    fi
    zle push-line
    BUFFER="cd -- ${(q)dir}" 
    zle accept-line
    local ret=$? 
    unset dir
    zle reset-prompt
    return $ret
}
unixorn commented 2 years ago

I'm getting a new work laptop Monday and will take a look at this in the clean environment on there before installing my dotfiles.

unixorn commented 2 years ago

It is working on my new work laptop. I'm loading it via zgenom instead of oh-my-zsh, though.

Dhruv-mak commented 2 years ago

I even tried it with zgenom. it's still not working for me.

fiskhest commented 2 years ago

I seem to be hitting some variation of this issue as well. Ctrl-R works, Alt-C gives:

(eval):1: unknown file attribute:
   <  0/0 (0)

Unsetting FZF_ALT_C_COMMAND takes away the error but leaves me with an empty list to choose from. I tried opening a new terminal and running the command in FZF_ALT_C_COMMAND manually:

❯ printenv | grep FZF_ALT_C
FZF_ALT_C_COMMAND=find . -type d ( -path .git -o -path node_modules ) -prune

❯ find . -type d ( -path .git -o -path node_modules ) -prune

zsh: unknown file attribute:

On my previous laptop, I did not use this plugin but instead opted for manually sourcing the files available at /usr/share/fzf/*.zsh. I looked at the code present there which among other contains:

# ALT-C - cd into the selected directory
fzf-cd-widget() {
  local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
    -o -type d -print 2> /dev/null | cut -b3-"}"
  setopt localoptions pipefail no_aliases 2> /dev/null
  local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)"

I tried manually exporting that command in my own terminal:

export FZF_ALT_C_COMMAND="find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune  -o -type d -print 2> /dev/null | cut -b3-"

Alt-C works as expected: Screenshot_2022-04-29-08-49-08_3840x2400

Ctrl-T works but gives me weird rendering issues related to No such file or directory (the files are symlinks with deleted targets): Screenshot_2022-04-29-08-43-46_3840x2400

Unsetting FZF_CTRL_T_COMMAND fixes the rendering issue.

I am running into this on a very clean arch linux installation with oh-my-zsh after following the simple installation instructions detailed in this repository. exa, rg, bat are installed through official repositories

My ~/.zshrc contains the following: plugins=(git zsh-autosuggestions zsh-syntax-highlighting zsh-vim-mode zsh-vimode-visual virtualenv kubectl sudo fzf fzf-zsh-plugin)

I've experimented with placing fzf-zsh-plugin and fzf both at the start and end of array, removing fzf, with no change in behavior.

To rule out conflicting plugins, I also just tried plugins=(fzf-zsh-plugin) with the same result.

a-monteiro commented 2 years ago

I have the same issue as @fiskhest... Didn't find a proper solution though

Pavel1114 commented 1 year ago

Error is in FZF_DEFAULT_COMMAND. My zsh throw error when tries eval 'find . -type f ( -path .git -o -path node_modules ) -prune' I have just removed this plugin. And replace it with standart one from oh-my-zsh (plugins=("fzf"))

nations-Xiong commented 10 months ago

I seem to be hitting some variation of this issue as well. Ctrl-R works, Alt-C gives:

(eval):1: unknown file attribute:
   <  0/0 (0)

Unsetting FZF_ALT_C_COMMAND takes away the error but leaves me with an empty list to choose from. I tried opening a new terminal and running the command in FZF_ALT_C_COMMAND manually:

❯ printenv | grep FZF_ALT_C
FZF_ALT_C_COMMAND=find . -type d ( -path .git -o -path node_modules ) -prune

❯ find . -type d ( -path .git -o -path node_modules ) -prune

zsh: unknown file attribute:

On my previous laptop, I did not use this plugin but instead opted for manually sourcing the files available at /usr/share/fzf/*.zsh. I looked at the code present there which among other contains:

# ALT-C - cd into the selected directory
fzf-cd-widget() {
  local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
    -o -type d -print 2> /dev/null | cut -b3-"}"
  setopt localoptions pipefail no_aliases 2> /dev/null
  local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)"

I tried manually exporting that command in my own terminal:

export FZF_ALT_C_COMMAND="find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune  -o -type d -print 2> /dev/null | cut -b3-"

Alt-C works as expected: Screenshot_2022-04-29-08-49-08_3840x2400

Ctrl-T works but gives me weird rendering issues related to No such file or directory (the files are symlinks with deleted targets): Screenshot_2022-04-29-08-43-46_3840x2400

Unsetting FZF_CTRL_T_COMMAND fixes the rendering issue.

I am running into this on a very clean arch linux installation with oh-my-zsh after following the simple installation instructions detailed in this repository. exa, rg, bat are installed through official repositories

My ~/.zshrc contains the following: plugins=(git zsh-autosuggestions zsh-syntax-highlighting zsh-vim-mode zsh-vimode-visual virtualenv kubectl sudo fzf fzf-zsh-plugin)

I've experimented with placing fzf-zsh-plugin and fzf both at the start and end of array, removing fzf, with no change in behavior.

To rule out conflicting plugins, I also just tried plugins=(fzf-zsh-plugin) with the same result.

I ran to the same trap as you when I installed fzf-zsh-plugin. Then I removed the plugin and tried fzf with sourcing the official config files /usr/share/doc/fzf/examples/*.zsh in my ~/.zshrc, but the result is the same. I tried printenv | grep FZF to list environment variables corelated to FZF, it turns out that they were set as wrong values. The installation process of fzf with apt will not introduce them. They may be introduced by fzf-zsh-plugin. The function __fsel() in key-bindings.zsh first check env variable FZF_CTRL_T_COMMAND, when it is empty, the later command will be adopted. So the probable solution is unset vars_fzf. Actually, it works for me.

svic321 commented 8 months ago

I'm using the fzf-zsh-plugin for oh-my-zsh. And I realized that the plugin search for either fdfind or find. And if fdfind is not found, then it sets the env verialbes to work with find. I solved it with:

sudo apt install fd-find

Then I started a new shell and the variables were set to work with fdfind which solved the problem. The file I looked into is located in $HOME/.oh-my-zsh/custom/plugins/fzf-zsh-plugin/fzf-zsh-plugin.plugin.zsh. A plugin from https://github.com/unixorn/fzf-zsh-plugin

cognitus commented 7 months ago

that's right installing fd-find fix the problem

@unixorn can you add as requirement?

unixorn commented 6 months ago

As of #50, the plugin doesn't use fdfind unless it finds it in $PATH, so I think this is fixed.