mcchrish / nnn.vim

File manager for vim/neovim powered by n³
BSD 2-Clause "Simplified" License
646 stars 25 forks source link

Error when using fzopen after changing directory #133

Closed ram02z closed 3 years ago

ram02z commented 3 years ago

To Reproduce

  1. Add fzopen as a plugin
  2. Invoke NNNPicker
  3. Change directory
  4. Invoke fzopen and pick a file
  5. Error shown and the file doesn't get picked

Screenshots

image

Environment:

Additional context

The error doesn't occur for me if I don't change the directory that nnn.vim was invoked from.

nnn.vim config: https://github.com/ram02z/dotfiles/blob/6ee4aa967a18643a657f7d30cf4435fccb265f05/dot_config/nvim/plugin/50-plugins.lua#L321-L350

jarun commented 3 years ago

@mcchrish can you please take a look at it? Are you waiting for someone to pitch in?

mcchrish commented 3 years ago

@jarun I'm waiting for anyone to take a look. PR is welcome and I can take a review.

jarun commented 3 years ago

In that case please respond to the defect with a note so someone else bothers to look into it. What appears to be the problem? Do the error strings help?

N-R-K commented 3 years ago

This is probably a problem with fzopen plugin. I don't use it, so I'm not sure what's going on here. But seems to me that is the offending snippet.

# Check for picker mode
if [ "$3" ]; then
    if [ "$entry" ]; then
        if [ "-" = "$3" ]; then
            printf "%s\n" "$entry"
        else
            printf "%s\n" "$entry" > "$3"
        fi

        # Tell `nnn` to clear its internal selection
        printf "%s" "0p" > "$NNN_PIPE"
    fi

    exit 0
fi
N-R-K commented 3 years ago

Added the "help wanted" label so anyone who's interested can take a look.

jarun commented 3 years ago

@N-R-K fzopen is working as expected in this block. This is a case of calling a picker plugin while nnn is started in picker mode. See $3 in https://github.com/jarun/nnn/tree/master/plugins#access-level-of-plugins

So, if user is picking files using fzopen(), nnn should not pick files. The picker output file path is passed to the plugin (- if it's stdout) and the plugin will write picked files to it (nnn would skip writing to the output file).

jarun commented 3 years ago

@mizlan can you please have a look?

N-R-K commented 3 years ago

Can reproduce this with a dummy plugin with that block.

#!/bin/sh

# Check for picker mode
entry="$1"
if [ "$3" ]; then
    if [ "$entry" ]; then
        if [ "-" = "$3" ]; then
            printf "%s\n" "$entry"
        else
            printf "%s\n" "$entry" > "$3"
        fi

        # Tell `nnn` to clear its internal selection
        printf "%s" "0p" > "$NNN_PIPE"
    fi

    exit 0
fi
jarun commented 3 years ago

In explorer mode, it just opens the plugin file.

jarun commented 3 years ago

That's with pick a plugin method... and expected as per current code.

N-R-K commented 3 years ago

Okay, I know what's going on. The plugin is printing only filename, not full path. So if you change directory it becomes a problem.

jarun commented 3 years ago

OK. I fixed the other issue with opening the plugin (instead of run) at https://github.com/jarun/nnn/commit/bdbd182c65cee58c2d09374a93a9ca3425e4ab7b.

jarun commented 3 years ago

@ram02z the fzopen plugin is fixed. Please confirm if the patch works for you.

ram02z commented 3 years ago

@ram02z the fzopen plugin is fixed. Please confirm if the patch works for you.

The patch works great, thanks for the fix @N-R-K !