File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,20 @@ function Hyperlinks.find_by_filepath(url)
2323 if not file_base then
2424 return {}
2525 end
26+ local is_home_relative_path = file_base :match (' ^~/' )
27+ local process_file_to_home = function (home , file )
28+ -- file and home is of absolute path
29+ -- if there is a common prefix, replace it with ~
30+ if file :sub (1 , # home ) == home then
31+ return ' ~' .. file :sub (# home + 1 )
32+ end
33+ end
34+ if is_home_relative_path then
35+ local home_abs = fs .get_home_dir ()
36+ filenames = vim .tbl_map (function (f )
37+ return process_file_to_home (home_abs , f ) or f
38+ end , filenames )
39+ end
2640 -- TODO integrate with orgmode.utils.fs or orgmode.objects.url
2741 local file_base_no_start_path = vim .pesc (file_base :gsub (' ^%./' , ' ' ) .. ' ' )
2842 local is_relative_path = file_base :match (' ^%./' )
Original file line number Diff line number Diff line change @@ -39,4 +39,8 @@ function M.get_current_file_dir()
3939 return current_dir or ' '
4040end
4141
42+ function M .get_home_dir ()
43+ return os.getenv (' HOME' ) or ' '
44+ end
45+
4246return M
You can’t perform that action at this time.
0 commit comments