feat: $NVIM_APPNAME #22128

This commit implements the ability to control all of the XDG paths
Neovim should use. This is done by setting an environment variable named
NVIM_APPNAME. For example, setting $NVIM_APPNAME makes Neovim look for
its configuration directory in $XDG_CONFIG_HOME/$NVIM_APPNAME instead of
$XDG_CONFIG_HOME/nvim.

If NVIM_APPNAME is not set or is an empty string, "nvim" will be used as
default.

The usecase for this feature is to enable an easy way to switch from
configuration to configuration. One might argue that the various $XDG
environment variables can already be used for this usecase. However,
setting $XDG environment variables also affects tools spawned by Neovim.
For example, while setting $XDG_CONFIG_HOME will enable Neovim to use a
different configuration directory, it will also prevent Git from finding
its "default" configuration.

Closes https://github.com/neovim/neovim/issues/21691
This commit is contained in:
Ghjuvan Lacambre
2023-02-16 13:15:02 +01:00
committed by GitHub
parent 631775c05d
commit d34c64e342
8 changed files with 99 additions and 36 deletions

View File

@@ -566,8 +566,12 @@ end)
describe('stdpath()', function()
-- Windows appends 'nvim-data' instead of just 'nvim' to prevent collisions
-- due to XDG_CONFIG_HOME, XDG_DATA_HOME and XDG_STATE_HOME being the same.
local datadir = is_os('win') and 'nvim-data' or 'nvim'
local statedir = is_os('win') and 'nvim-data' or 'nvim'
local function maybe_data(name)
return is_os('win') and name .. '-data' or name
end
local datadir = maybe_data('nvim')
local statedir = maybe_data('nvim')
local env_sep = is_os('win') and ';' or ':'
it('acceptance', function()
@@ -583,6 +587,24 @@ describe('stdpath()', function()
assert_alive() -- Check for crash. #8393
end)
it('reacts to #NVIM_APPNAME', function()
local appname = "NVIM_APPNAME_TEST____________________________________" ..
"______________________________________________________________________"
clear({env={ NVIM_APPNAME=appname }})
eq(appname, funcs.fnamemodify(funcs.stdpath('config'), ':t'))
eq(appname, funcs.fnamemodify(funcs.stdpath('cache'), ':t'))
eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('log'), ':t'))
eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('data'), ':t'))
eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('state'), ':t'))
-- config_dirs and data_dirs are empty on windows, so don't check them on
-- that platform
if not is_os('win') then
eq(appname, funcs.fnamemodify(funcs.stdpath('config_dirs')[1], ':t'))
eq(appname, funcs.fnamemodify(funcs.stdpath('data_dirs')[1], ':t'))
end
assert_alive() -- Check for crash. #8393
end)
context('returns a String', function()
describe('with "config"' , function ()