mirror of
https://github.com/neovim/neovim.git
synced 2026-08-25 00:21:55 +00:00
fix(man): allow :Man to open by absolute path #41401
Problem: man -w echoes any existent file back unchanged. :Man rejected all such paths, so :Man /usr/share/man/man1/bash.1 failed even for real man pages. Solution: Accept an echoed path when it looks like a man page (.../man1/foo.1).
This commit is contained in:
@@ -257,12 +257,15 @@ function M._match_manpage_path(paths, name, sect)
|
||||
return
|
||||
end
|
||||
|
||||
-- `man -w /some/path` will return `/some/path` for any existent file, which
|
||||
-- stops us from actually determining if a path has a corresponding man file.
|
||||
-- Since `:Man /some/path/to/man/file` isn't supported anyway, we should just
|
||||
-- error out here if we detect this is the case.
|
||||
-- `man -w /some/path` echoes the input for any existent file. Accept only
|
||||
-- paths that look like a man page (`.../man1/bash.1`). #30873
|
||||
if sect == '' and #paths == 1 and paths[1] == name then
|
||||
return
|
||||
local tail = vim.fs.basename(name)
|
||||
local parent = vim.fs.basename(vim.fs.dirname(name))
|
||||
if not (parent:find('^man') and tail:find('%.%d')) then
|
||||
return
|
||||
end
|
||||
return name
|
||||
end
|
||||
|
||||
-- find any that match the specified name
|
||||
|
||||
@@ -267,6 +267,19 @@ describe(':Man', function()
|
||||
end)
|
||||
end
|
||||
|
||||
eq(
|
||||
'/usr/share/man/man1/bash.1',
|
||||
_test({ '/usr/share/man/man1/bash.1' }, '/usr/share/man/man1/bash.1')
|
||||
)
|
||||
|
||||
eq(
|
||||
'/usr/share/man/man3/strlen.3.gz',
|
||||
_test({ '/usr/share/man/man3/strlen.3.gz' }, '/usr/share/man/man3/strlen.3.gz')
|
||||
)
|
||||
|
||||
eq(nil, _test({ '/tmp/not-a-manpage' }, '/tmp/not-a-manpage'))
|
||||
eq(nil, _test({ '/tmp/T10.1' }, '/tmp/T10.1'))
|
||||
|
||||
eq(
|
||||
'/usr/share/man/man3/strcpy.3',
|
||||
_test({
|
||||
|
||||
Reference in New Issue
Block a user