diff --git a/dots/.config/nvim/after/ftplugin/asm.lua b/dots/.config/nvim/after/ftplugin/asm.lua index 66d13735..4afe6ccc 100644 --- a/dots/.config/nvim/after/ftplugin/asm.lua +++ b/dots/.config/nvim/after/ftplugin/asm.lua @@ -1,20 +1,30 @@ vim.opt_local.commentstring = "# %s" vim.keymap.set("n", "fr", function() - local curr_file = vim.fn.expand("%:p") - vim.fn.expand("%:p") - local curr_dir = vim.fn.expand("%:p:h") - vim.fn.expand("%:p") - require("toggleterm").exec( - string.format( - "as %s -o %s/obj.o && ld %s/obj.o -o %s/out && %s/out", - curr_file, - curr_dir, - curr_dir, - curr_dir, - curr_dir - ) - ) + local curr_file = vim.api.nvim_buf_get_name(0) + local curr_dir = vim.fn.fnamemodify(curr_file, ":h") + local fname = vim.fn.fnamemodify(curr_file, ":t:r") + + local target_dir = curr_dir .. "/.target" + local object_path = target_dir .. "/obj.o" + local executable_path = target_dir .. "/" .. fname + + vim.fn.mkdir(target_dir, "p") + + local cmd = { + "as", + curr_file, + "-o", + object_path, + "&& \n", + "ld", + object_path, + "-o", + executable_path, + "&& \n", + executable_path + } + require("toggleterm").exec(table.concat(cmd, " ")) end, { buffer = true, })