Skip to content

Commit 7928dd5

Browse files
feat(commands): added open command
1 parent 9b2017a commit 7928dd5

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lua/freeze-code/commands.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ function M.on_exit(msg, opts)
5151
if freeze_code.config.copy == true then
5252
freeze_code.copy(freeze_code.config)
5353
end
54+
if freeze_code.config.open == true then
55+
freeze_code.open(freeze_code.config)
56+
end
5457
if opts and opts.freeze then
5558
vim.wait(5000, function()
5659
local image_path = vim.loop.fs_fstat(opts.freeze.output)
@@ -127,4 +130,23 @@ M.copy = function(opts)
127130
logger.info("[freeze-code.nvim] image copied to clipboard")
128131
end
129132

133+
local open_by_os = function(opts)
134+
local cmd = {}
135+
local filename = vim.fn.expand(opts.output)
136+
if is_win then
137+
cmd = { "explorer", filename }
138+
else
139+
cmd = { "open", filename }
140+
end
141+
return vim.fn.system(table.concat(cmd, " "))
142+
end
143+
144+
M.open = function(opts)
145+
open_by_os(opts)
146+
if vim.v.shell_error ~= 0 then
147+
logger.err_once("[freeze-code.nvim] error while opening image")
148+
return
149+
end
150+
end
151+
130152
return M

lua/freeze-code/init.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ freeze_code.copy = function(opts)
5454
commands.copy(opts)
5555
end
5656

57+
---@class FreezeCode
58+
---@field open function: Opening image in default image viewer
59+
freeze_code.open = function(opts)
60+
commands.open(opts)
61+
end
62+
5763
local create_autocmds = function()
5864
vim.api.nvim_create_user_command("Freeze", function(opts)
5965
if opts.count > 0 then

0 commit comments

Comments
 (0)