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

Symlink binaries from .../nvim/mason/bin to XDG_BIN_HOME if exists #1505

Closed
1 task done
tony-sol opened this issue Sep 25, 2023 · 7 comments
Closed
1 task done

Symlink binaries from .../nvim/mason/bin to XDG_BIN_HOME if exists #1505

tony-sol opened this issue Sep 25, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@tony-sol
Copy link

I've searched open issues for similar requests

  • Yes

Is your feature request related to a problem? Please describe.

It's a common thing to install via mason some cli tools, linters, lang-servers, etc. and for now, i have to add ${XDG_DATA_HOME}/nvim/mason/bin into $PATH to have access to them.

In my case, gopls requires golangci-lint, both installed via mason, but they can't "see" each other, 'cause both of them not in $PATH

Describe the solution you'd like

I guess it will be more convenient to link binaries not only from ${XDG_DATA_HOME}/nvim/mason/packages/** to ${XDG_DATA_HOME}/nvim/mason/bin, but also from ${XDG_DATA_HOME}/nvim/mason/bin to ${XDG_BIN_HOME}/

Describe potential alternatives you've considered

Alternative is adding ${XDG_DATA_HOME}/nvim/mason/bin into $PATH, but it relates not only mason directory structure won't change, but also nvim's one.

In case of $XDG_BIN_HOME is not set - nothing needs to be done

Additional context

No response

@tony-sol tony-sol added the enhancement New feature or request label Sep 25, 2023
@mochaaP
Copy link

mochaaP commented Sep 29, 2023

I don't think ${XDG_BIN_HOME} is standardized?

https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html

@tony-sol
Copy link
Author

Yeah, there are some concerns about that env - it's a common thought, that there is a lack of default dir for executables, like ~/.local/bin, but ${XDG_BIN_HOME} is the most frequently used as i looked for

Here are some refs:
https://gitlab.freedesktop.org/xdg/xdg-specs/-/issues/63
https://theos.kyriasis.com/~kyrias/basedir-spec.html
adrg/xdg#28

@mochaaP
Copy link

mochaaP commented Sep 30, 2023

Personally I prefer to treat ~/.local as a prefix (like /usr/local), and follow the FHS.

Seems pip already honored this.

@wookayin
Copy link

wookayin commented Oct 3, 2023

This is something that an user would need to write a custom config for. This shouldn't be the default behavior or a feature by mason by any means. If you need mason-installed programs visible on your interactive shell, you should simply add $MASON/bin/ to $PATH in your bashrc/zshrc.

@tony-sol
Copy link
Author

@wookayin, yeah, i agree that this shouldn't be the default behavior, but may be configurable.

you should simply add $MASON/bin/ to $PATH

Yeah, i did like this, but it looks quite hardcoded, even as like

export PATH="${XDG_DATA_HOME}/nvim/mason/bin:${PATH}"

Is any way to execute nvim's lua via shell?, like

export MASON_BIN=$( ???? 'require("mason-core.path").bin_prefix()')
export PATH="${MASON_BIN}:${PATH}"

to fetch actual path to /bin directory and not relying that dir struct of mason won't change?

@wookayin
Copy link

wookayin commented Oct 11, 2023

$ nvim -i NONE --headless -c 'lua= require("mason-core.path").bin_prefix() .. "\n"' -c qa!
/home/xxxxx/.local/share/nvim/mason/bin

But this would be quite expensive to execute every single time SHELL is initialized, because the nvim instance should read and execute all the configs (50~100ms for a good config with reasonable lazy loading). Would you want to cache it?

Of course one can optimize this command line to load lazy.nvim and/or mason.nvim only to make it much faster (but it will be still 10~20ms at least):

nvim --clean -c 'lua= ...' 

but I'm not sure if it would be worth or better than doing compared to writing like $XDG_DATA_HOME/nvim/mason/bin directly.

If you really want to make a symbolic link made to somewhere among $PATH, then you could write such user vim configs by using vim.loop.fs_symlink() right after the mason.setup call.

@williamboman
Copy link
Owner

Hello! This would be out of scope so it won't be considered as a feature. If you want to easily access executables installed via Mason outside of Neovim you can simply add Mason's bin directory to your PATH. This location won't change. If you want to be extra certain you can explicitly provide a location for it during setup:

require("mason").setup {
  install_root_dir = vim.fn.expand("~/.mason")
}
$ export PATH=~/.mason/bin:$PATH
$ # yay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Closed
Development

No branches or pull requests

4 participants