Skip to content

Commit

Permalink
terminal: fixed file open on stdout tui explorer (lf, yeet) on narrow…
Browse files Browse the repository at this point in the history
… window sizes where paths broke to multiple lines

Signed-off-by: aserowy <[email protected]>
  • Loading branch information
aserowy committed Mar 19, 2024
1 parent cfd9019 commit 1b6b3ca
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
17 changes: 11 additions & 6 deletions lua/nvim/file.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
local M = {}

function M.exists(path)
local f = io.open(path, "r")
return f ~= nil and io.close(f)
end

function M.lines(path)
if not M.exists(path) then
if vim.fn.filereadable(path) ~= 1 then
return {}
end

Expand All @@ -18,4 +13,14 @@ function M.lines(path)
return lines
end

function M.resolve(lines)
for i = 1, #lines do
local file_path = table.concat(lines, "", 1, i)
if vim.fn.filereadable(file_path) == 1 then
return file_path
end
end
return nil
end

return M
4 changes: 2 additions & 2 deletions lua/nvim/lf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function M.close()
return 1
end

local path = lines[1]
if not file.exists(path) then
local path = file.resolve(lines)
if not path then
return 1
end

Expand Down
1 change: 0 additions & 1 deletion lua/nvim/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function M.setup()
for pattern, close_handle in pairs(case) do
if title:match(pattern) then
result = close_handle()

break
end
end
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim/yazi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function M.close()
return 1
end

local path = lines[1]
if not file.exists(path) then
local path = file.resolve(lines)
if not path then
return 1
end

Expand Down
4 changes: 2 additions & 2 deletions lua/nvim/yeet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function M.close()
return 1
end

local path = lines[1]
if not file.exists(path) then
local path = file.resolve(lines)
if not path then
return 1
end

Expand Down

0 comments on commit 1b6b3ca

Please sign in to comment.