diff --git a/lua/neocrush/cvm/init.lua b/lua/neocrush/cvm/init.lua index 0ed3dc1..cc2fcfa 100644 --- a/lua/neocrush/cvm/init.lua +++ b/lua/neocrush/cvm/init.lua @@ -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 ------------------------------------------------------------------------------- @@ -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 @@ -413,4 +424,6 @@ M._get_config = function() return cvm_config end +M._expand_path = expand_path + return M diff --git a/tests/cvm_spec.lua b/tests/cvm_spec.lua index f7eadae..8dbd9a4 100644 --- a/tests/cvm_spec.lua +++ b/tests/cvm_spec.lua @@ -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