Skip to content

Commit

Permalink
fix(filetype): expand tildes in filetype patterns (#17091)
Browse files Browse the repository at this point in the history
This allows patterns like

  ["~/.config/foo"] = "fooscript"

to work.
  • Loading branch information
gpanders committed Jan 14, 2022
1 parent bac4bb1 commit 59ea8fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion runtime/lua/vim/filetype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ local pattern_sorted = sort_by_priority(pattern)

---@private
local function normalize_path(path)
return (path:gsub("\\", "/"))
return (path:gsub("\\", "/"):gsub("^~", vim.env.HOME))
end

--- Add new filetype mappings.
Expand Down
4 changes: 2 additions & 2 deletions test/functional/lua/filetype_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ describe('vim.filetype', function()
local root = ...
vim.filetype.add({
pattern = {
[root .. '/blog/.*%.txt'] = 'markdown',
['~/blog/.*%.txt'] = 'markdown',
}
})
vim.filetype.match(root .. '/blog/why_neovim_is_awesome.txt')
vim.filetype.match('~/blog/why_neovim_is_awesome.txt')
return vim.bo.filetype
]], root))
end)
Expand Down

0 comments on commit 59ea8fa

Please sign in to comment.