File tree 2 files changed +12
-16
lines changed
2 files changed +12
-16
lines changed Original file line number Diff line number Diff line change @@ -12,23 +12,18 @@ function M.fire(event)
12
12
vim .api .nvim_exec_autocmds (" User" , { pattern = " Persisted" .. event })
13
13
end
14
14
15
- --- Get the current working directory
16
- --- @return string
17
- function M .cwd ()
18
- return utils .sanitize_dir (vim .fn .getcwd ())
19
- end
20
-
21
15
--- Get the current session for the current working directory and git branch
22
16
--- @param opts ? { branch ?: boolean }
23
17
--- @return string
24
18
function M .current (opts )
25
19
opts = opts or {}
26
- local name = M . cwd ( )
20
+ local name = utils . make_fs_safe ( vim . fn . getcwd () )
27
21
28
22
if config .use_git_branch and opts .branch ~= false then
29
23
local branch = M .branch ()
30
24
if branch then
31
- name = name .. " @@" .. branch :gsub (" [\\ /:]+" , " %%" )
25
+ branch = utils .make_fs_safe (branch )
26
+ name = name .. " @@" .. branch
32
27
end
33
28
end
34
29
@@ -164,7 +159,7 @@ function M.allowed_dir(opts)
164
159
end
165
160
166
161
opts = opts or {}
167
- local dir = opts .dir or M . cwd ()
162
+ local dir = opts .dir or vim . fn . getcwd ()
168
163
169
164
return utils .dirs_match (dir , config .allowed_dirs ) and not utils .dirs_match (dir , config .ignored_dirs )
170
165
end
Original file line number Diff line number Diff line change 1
1
local M = {}
2
2
3
- --- Escape special pattern matching characters in a string
4
- --- @param dir string
5
- function M .sanitize_dir (dir )
6
- return dir :gsub (" [\\ /:]+" , " %%" )
3
+ --- Escapes the given text to be safe for use in file-system paths/names,
4
+ --- accounting for cross-platform use.
5
+ --- @param text string
6
+ function M .make_fs_safe (text )
7
+ return text :gsub (" [\\ /:]+" , " %%" )
7
8
end
8
9
9
10
--- Get the directory pattern based on OS
29
30
--- @param dirs table The table of directories to search in
30
31
--- @return boolean
31
32
function M .dirs_match (dir , dirs )
32
- dir = M .sanitize_dir (vim .fn .expand (dir ))
33
+ dir = M .make_fs_safe (vim .fn .expand (dir ))
33
34
34
35
for _ , search in ipairs (dirs ) do
35
36
if type (search ) == " string" then
36
- search = M .sanitize_dir (vim .fn .expand (search ))
37
+ search = M .make_fs_safe (vim .fn .expand (search ))
37
38
if M .is_subdirectory (search , dir ) then
38
39
return true
39
40
end
40
41
elseif type (search ) == " table" then
41
42
if search .exact then
42
- search = M .sanitize_dir (vim .fn .expand (search [1 ]))
43
+ search = M .make_fs_safe (vim .fn .expand (search [1 ]))
43
44
if dir == search then
44
45
return true
45
46
end
You can’t perform that action at this time.
0 commit comments