starter/lua/mj/alternate_file.lua

22 lines
565 B
Lua
Raw Normal View History

2024-06-07 02:44:06 +08:00
local runner = require("mj.command_runner")
M = {}
2024-06-07 03:18:51 +08:00
M._mj_alternative_file = function(file, subcommand, options)
local cmd = "mj alternative_file " .. subcommand .. " " .. file .. " " .. options
return runner.run(cmd)
end
2024-06-07 02:44:06 +08:00
M.open = function(subcommand, options)
local file_path = vim.fn.expand("%")
file_path = vim.fn.fnamemodify(file_path, ":~:.")
2024-06-07 03:18:51 +08:00
local files = M._mj_alternative_file(file_path, subcommand, options)
2024-06-07 02:44:06 +08:00
files = vim.split(files, " ")
local file = files[1]
if file ~= "" then
vim.api.nvim_command("e " .. file)
end
end
return M