Skip to content

Commit e631247

Browse files
committed
feat(utils): add optional parameter base to substitute_path()
1 parent 213fa85 commit e631247

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lua/orgmode/utils/fs.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ local utils = require('orgmode.utils')
33
local M = {}
44

55
---@param path_str string
6+
---@param base? string
67
---@return string | false
7-
function M.substitute_path(path_str)
8+
function M.substitute_path(path_str, base)
89
if path_str:match('^/') then
910
return path_str
1011
elseif path_str:match('^~/') then
1112
local home_path = os.getenv('HOME')
1213
return home_path and path_str:gsub('^~', home_path) or false
1314
elseif path_str:match('^%./') then
14-
local base = vim.fn.fnamemodify(utils.current_file_path(), ':p:h')
15+
if not base then
16+
base = vim.fn.fnamemodify(utils.current_file_path(), ':p:h')
17+
end
1518
return base .. '/' .. path_str:gsub('^%./', '')
1619
elseif path_str:match('^%.%./') then
17-
local base = vim.fn.fnamemodify(utils.current_file_path(), ':p:h')
20+
if not base then
21+
base = vim.fn.fnamemodify(utils.current_file_path(), ':p:h')
22+
end
1823
return base .. '/' .. path_str
1924
end
2025
return false

0 commit comments

Comments
 (0)