Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lua/neocrush/cvm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ local cvm_config = vim.deepcopy(default_cvm_config)
---@type string Go module base URL derived from upstream
local GO_MODULE = 'github.com/charmbracelet/crush'

-------------------------------------------------------------------------------
-- Paths
-------------------------------------------------------------------------------

---Expand user and environment variable references in configured paths.
---@param path string
---@return string
local function expand_path(path)
return vim.fn.expand(vim.fn.expandcmd(path))
end

-------------------------------------------------------------------------------
-- Highlight Groups
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -337,7 +348,7 @@ function M.pick_local(repo_path)
return
end

repo_path = vim.fn.expand(repo_path)
repo_path = expand_path(repo_path)
if vim.fn.isdirectory(repo_path) ~= 1 then
vim.notify('Not a directory: ' .. repo_path, vim.log.levels.ERROR)
return
Expand Down Expand Up @@ -413,4 +424,6 @@ M._get_config = function()
return cvm_config
end

M._expand_path = expand_path

return M
10 changes: 10 additions & 0 deletions tests/cvm_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ describe('neocrush.cvm', function()
end)
end)

describe('path expansion', function()
it('should expand environment variables and home directory', function()
vim.env.NEOCRUSH_CVM_TEST_DIR = 'neocrush-test'

local expanded = cvm._expand_path '~/$NEOCRUSH_CVM_TEST_DIR'

assert.are.same(vim.fn.expand '~/neocrush-test', expanded)
end)
end)

describe('get_current_version', function()
it('should call callback with nil when crush is not installed', function()
local original = vim.fn.executable
Expand Down
Loading