File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -3,18 +3,23 @@ local utils = require('orgmode.utils')
3
3
local M = {}
4
4
5
5
--- @param path_str string
6
+ --- @param base ? string
6
7
--- @return string | false
7
- function M .substitute_path (path_str )
8
+ function M .substitute_path (path_str , base )
8
9
if path_str :match (' ^/' ) then
9
10
return path_str
10
11
elseif path_str :match (' ^~/' ) then
11
12
local home_path = os.getenv (' HOME' )
12
13
return home_path and path_str :gsub (' ^~' , home_path ) or false
13
14
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
15
18
return base .. ' /' .. path_str :gsub (' ^%./' , ' ' )
16
19
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
18
23
return base .. ' /' .. path_str
19
24
end
20
25
return false
Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ describe('substitute_path', function()
49
49
it (' fails on all other relative paths' , function ()
50
50
assert .is .False (fs_utils .substitute_path (' a/b/c' ))
51
51
end )
52
+
53
+ it (' allows passing a custom base' , function ()
54
+ local output = fs_utils .substitute_path (' ./b/c' , ' a/' )
55
+ assert (output )
56
+ assert .are .same (output , ' a//b/c' )
57
+ end )
52
58
end )
53
59
54
60
describe (' get_real_path' , function ()
You can’t perform that action at this time.
0 commit comments