mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 18:41:48 +00:00
fix(startup): respect $NVIM_APPNAME in $XDG_CONFIG_DIRS paths
Problem:
$NVIM_APPNAME was not respected when searching $XDG_CONFIG_DIRS for
config files. Nvim hardcoded "nvim" when constructing paths like
`$XDG_CONFIG_DIRS/nvim/init.lua`, ignoring the $NVIM_APPNAME environment
variable.
This meant that config files like `$XDG_CONFIG_DIRS/myapp/init.lua` were
not loaded, even though $NVIM_APPNAME was set to "myapp".
Solution:
Use `get_appname()` instead of hardcoded "nvim" for $XDG_CONFIG_DIRS
paths in `do_system_initialization()` and `do_user_initialization()`.
This makes $XDG_CONFIG_DIRS behave consistently with $XDG_CONFIG_HOME,
which already respected $NVIM_APPNAME.
As documented in `runtime/doc/starting.txt` (L1440-L1441):
"In the help wherever `$XDG_CONFIG_…/nvim` is mentioned it is understood
as `$XDG_CONFIG_…/$NVIM_APPNAME`."
See:
43339dee40/runtime/doc/starting.txt (L1440-L1441)
Relates to #37405
This commit is contained in:
@@ -1192,6 +1192,22 @@ describe('sysinit', function()
|
||||
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))')
|
||||
)
|
||||
end)
|
||||
|
||||
it('respects NVIM_APPNAME in XDG_CONFIG_DIRS', function()
|
||||
local appname = 'mysysinitapp'
|
||||
mkdir(xdgdir .. pathsep .. appname)
|
||||
write_file(
|
||||
table.concat({ xdgdir, appname, 'sysinit.vim' }, pathsep),
|
||||
[[let g:appname_sysinit = 1]]
|
||||
)
|
||||
clear {
|
||||
args_rm = { '-u' },
|
||||
env = { HOME = xhome, XDG_CONFIG_DIRS = xdgdir, NVIM_APPNAME = appname },
|
||||
}
|
||||
eq(1, eval('g:appname_sysinit'))
|
||||
-- Should not load from nvim/ subdir (which has the default sysinit.vim from before_each)
|
||||
eq(0, eval('get(g:, "xdg", 0)'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('user config init', function()
|
||||
@@ -1472,6 +1488,29 @@ describe('user config init', function()
|
||||
}
|
||||
eq(1, eval('g:xdg_vim'))
|
||||
end)
|
||||
|
||||
it('respects NVIM_APPNAME', function()
|
||||
local appname = 'mytestapp'
|
||||
mkdir_p(xdgdir .. pathsep .. appname)
|
||||
-- Also create nvim/ with a config that should NOT be loaded
|
||||
write_file(table.concat({ xdgdir, 'nvim', 'init.lua' }, pathsep), [[vim.g.wrong = 1]])
|
||||
write_file(table.concat({ xdgdir, appname, 'init.lua' }, pathsep), [[vim.g.appname_lua = 1]])
|
||||
clear {
|
||||
args_rm = { '-u' },
|
||||
env = {
|
||||
XDG_CONFIG_HOME = xconfig,
|
||||
XDG_DATA_HOME = xdata,
|
||||
XDG_CONFIG_DIRS = xdgdir,
|
||||
NVIM_APPNAME = appname,
|
||||
},
|
||||
}
|
||||
eq(1, eval('g:appname_lua'))
|
||||
eq(0, eval('get(g:, "wrong", 0)'))
|
||||
eq(
|
||||
fn.fnamemodify(table.concat({ xdgdir, appname, 'init.lua' }, pathsep), ':p'),
|
||||
eval('$MYVIMRC')
|
||||
)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user