Skip to content

Commit 6450bf5

Browse files
committed
fix(popup): use rstrip instead
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
1 parent c7da8cd commit 6450bf5

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

lua/project/popup.lua

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,15 @@ local function open_node(proj, only_cd, ran_cd)
136136
return item
137137
end
138138

139-
item = vim.fn.fnamemodify(item, ':p')
140-
item = item:sub(-1, -1) == '/' and item:sub(1, item:len() - 1) or item
139+
item = Util.rstrip('/', vim.fn.fnamemodify(item, ':p'))
141140
return vim.fn.isdirectory(item) == 1 and (item .. '/') or item
142141
end,
143142
}, function(item) ---@param item string
144143
if not item or in_list({ '', 'Exit' }, item) then
145144
return
146145
end
147146

148-
item = vim.fn.fnamemodify(item, ':p')
149-
item = item:sub(-1, -1) == '/' and item:sub(1, item:len() - 1) or item
147+
item = Util.rstrip('/', vim.fn.fnamemodify(item, ':p'))
150148
local stat = vim.uv.fs_stat(item)
151149
if not stat then
152150
return
@@ -230,14 +228,12 @@ function Popup.prompt_project(input)
230228
return
231229
end
232230

233-
input = vim.fn.fnamemodify(input, ':p')
234-
input = input:sub(-1, -1) == '/' and (input:sub(1, input:len() - 1)) or input
231+
input = Util.rstrip('/', vim.fn.fnamemodify(input, ':p'))
235232
if not (exists(input) and exists(vim.fn.fnamemodify(input, ':p:h'))) then
236233
error('Invalid path!', ERROR)
237234
end
238235
if not Util.dir_exists(input) then
239-
input = vim.fn.fnamemodify(input, ':p:h')
240-
input = input:sub(-1, -1) == '/' and (input:sub(1, input:len() - 1)) or input
236+
input = Util.rstrip('/', vim.fn.fnamemodify(input, ':p:h'))
241237
if not Util.dir_exists(input) then
242238
error('Path is not a directory, and parent could not be retrieved!', ERROR)
243239
end

0 commit comments

Comments
 (0)