From 960ab882336dea1125c45ca5dc49ed67159c7034 Mon Sep 17 00:00:00 2001 From: Philippe Richard Date: Tue, 19 Mar 2024 12:21:36 -0400 Subject: [PATCH] fix: fix absolute paths --- README.md | 2 +- doc/vwd.txt | 4 ++-- lua/telescope/_extensions/vwd/actions.lua | 2 +- lua/vwd/config.lua | 2 +- lua/vwd/store.lua | 9 +++++++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 07e25fc..eb8b05a 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ require('vwd').get_vwd() Set the VWD with: ```lua -require('vwd').set_vwd(vwd) +require('vwd').set_vwd(vwd, absolute) ``` Reset the VWD with: diff --git a/doc/vwd.txt b/doc/vwd.txt index 259ca6f..4433e4e 100644 --- a/doc/vwd.txt +++ b/doc/vwd.txt @@ -73,9 +73,9 @@ COMMANDS Returns the current VWD. *vwd-api-set* -`require('vwd').set_vwd(vwd)` +`require('vwd').set_vwd(vwd, absolute)` - Sets the VWD to {vwd}. + Sets the VWD to {vwd}. If the path is absolute, set the boolean to true. *vwd-api-reset* `require('vwd').reset_vwd()` diff --git a/lua/telescope/_extensions/vwd/actions.lua b/lua/telescope/_extensions/vwd/actions.lua index 69c1093..0009bf0 100644 --- a/lua/telescope/_extensions/vwd/actions.lua +++ b/lua/telescope/_extensions/vwd/actions.lua @@ -6,7 +6,7 @@ local manatee = require("vwd") M.set_vwd = function(prompt_bufnr) local action_state = require("telescope.actions.state") local current_picker = action_state.get_current_picker(prompt_bufnr) - manatee.set_vwd(current_picker.finder.path) + manatee.set_vwd(current_picker.finder.path, true) end return M diff --git a/lua/vwd/config.lua b/lua/vwd/config.lua index c4ea75a..a810ae0 100644 --- a/lua/vwd/config.lua +++ b/lua/vwd/config.lua @@ -10,7 +10,7 @@ local defaults = {} local cmd = { ["set"] = function(...) local args = ... - require("vwd").set_vwd(args[1]) + require("vwd").set_vwd(args[1], false) notify.info("VWD updated to '%s'", require("vwd").get_vwd()) end, ["get"] = function() diff --git a/lua/vwd/store.lua b/lua/vwd/store.lua index 7f1f3e4..9db905c 100644 --- a/lua/vwd/store.lua +++ b/lua/vwd/store.lua @@ -6,8 +6,13 @@ M._state = { --- set_vwd sets the VWD. ---@param dir string the directory to set as the VWD. -M.set_vwd = function(dir) - M._state.vwd = vim.fn.resolve(vim.fn.getcwd() .. "/" .. dir) +---@param absolute boolean Wether the provided dir is an absolute path or a CWD relative path. +M.set_vwd = function(dir, absolute) + if absolute then + M._state.vwd = dir + else + M._state.vwd = vim.fn.resolve(vim.fn.getcwd() .. "/" .. dir) + end end --- get_vwd gets the currently set VWD.