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

Please install yazi. when running Neovim via desktop entry due to yazi being installed for current user #463

Closed
xfzv opened this issue Sep 17, 2024 · 6 comments

Comments

@xfzv
Copy link
Contributor

xfzv commented Sep 17, 2024

Linux user here. yazi is installed only for my regular user via cargo so ya and yazi binaries are in $XDG_DATA_HOME/cargo/bin directory.

When running nvim from my interactive shell, no issue whatsoever with yazi.nvim since $XDG_DATA_HOME/cargo/bin is in my $PATH. However, if I open Neovim from the desktop entry (/usr/share/applications/nvim.desktop), yazi.nvim won't open and the following message will be printed:

yazi.nvim/lua/yazi.lua

Lines 20 to 23 in 813b066

if utils.is_yazi_available() ~= true then
print("Please install yazi. Check the documentation for more information")
return
end

  • /usr/share/applications/nvim.desktop content:
[Desktop Entry]
Name=Neovim
GenericName=Text Editor
Comment=Edit text files
TryExec=nvim
Exec=nvim %F
Terminal=true
Type=Application
Keywords=Text;editor;
Icon=nvim
Categories=Utility;TextEditor;
StartupNotify=false
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;

Using Exec=sh -c "PATH=/home/xfzv/.local/share/cargo/bin:$PATH kitty -e nvim" in a local desktop entry ($XDG_DATA_HOME/applications/nvim.desktop) solves the problem.

Just wondering if there is a better way. I never run Neovim via the desktop entry as far as I'm concerned, but I thought this shouldn't be a problem if some users want to.

Maybe some additional checks for ya and yazi binaries availability could be implemented, or maybe adding a note in the README?


Edit: my yazi.nvim config just in case:

return {
  "mikavilpas/yazi.nvim",
  cmd = { "Yazi", "Yazi cwd", "Yazi toggle" },
  opts = {
    open_multiple_tabs = true,
    yazi_floating_window_border = "single",
    keymaps = {
      show_help = false,
      open_file_in_vertical_split = false,
      open_file_in_horizontal_split = false,
      open_file_in_tab = false,
      grep_in_directory = false,
      replace_in_directory = false,
      cycle_open_buffers = false,
      copy_relative_path_to_selected_files = false,
      send_to_quickfix_list = false,
    },
  },
@mikavilpas
Copy link
Owner

As far as I remember, there is no custom checking for path in this plugin. Do you get the same results in :term when using e.g. echo $PATH?

@xfzv
Copy link
Contributor Author

xfzv commented Sep 18, 2024

Do you get the same results in :term when using e.g. echo $PATH?

No I don't, XDG_DATA_HOME/cargo/bin is part of $PATH in this case.

@mikavilpas
Copy link
Owner

If you start the :term, does which yazi find the yazi executable for you?

Are you sure XDG_DATA_HOME is correct? rustup does not seem to support it rust-lang/cargo#1734

In my zsh config I only set XDG_CONFIG_HOME here but then again I am on osx.

This plugin uses this implementation for finding yazi:

function M.is_yazi_available()
return vim.fn.executable("yazi") == 1
end

My guess is your environment is somehow not set up correctly - I think neovim does not see yazi and that caused this issue.

@xfzv
Copy link
Contributor Author

xfzv commented Sep 18, 2024

If you start the :term, does which yazi find the yazi executable for you?

Yes.

:term
% which yazi
/home/xfzv/.local/share/cargo/bin/yazi

Are you sure XDG_DATA_HOME is correct? rustup does not seem to support it rust-lang/cargo#1734

I'm using the following in my zsh config:

export PATH="$XDG_DATA_HOME/cargo/bin:$PATH"

My guess is your environment is somehow not set up correctly - I think neovim does not see yazi and that caused this issue.

I think the problem is just that desktop entries use the default $PATH variable:

% mv ~/.config/zsh ~/.config/zsh.bak
# Start a new interactive shell
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin:/usr/lib/llvm/18/bin

# Same with root account, untouched `$PATH` variable
% su -
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin:/usr/lib/llvm/18/bin

so any binary outside of these paths will be considered as nonexistent. If I do:

sudo cp ~/.local/share/cargo/bin/{ya,yazi} /usr/bin

or use the custom desktop entry in order to explicitly add /home/xfzv/.local/share/cargo/bin to $PATH as mentioned earlier, yazi.nvim runs just fine when Neovim is run from the desktop entry.

@mikavilpas
Copy link
Owner

Ah I see, that makes sense - I think the desktop entry never extends the PATH variable so the yazi executable cannot be found.

My guess is running :=vim.fn.executable("yazi") without the PATH variable extension will not find it.

I agree that this is pretty surprising behaviour, but I think it's difficult to handle this in yazi.nvim. I would like managing the PATH to be the user's responsibility.

@xfzv
Copy link
Contributor Author

xfzv commented Sep 18, 2024

I agree that this is pretty surprising behaviour, but I think it's difficult to handle this in yazi.nvim. I would like managing the PATH to be the user's responsibility.

OK, fair enough. I doubt many users are launching Neovim with the desktop entry anyway. Creating a custom one to explicitly set $PATH is an easy workaround if this is really needed.

Thanks!

@xfzv xfzv closed this as completed Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants