From 336bea3973db7dc8339c0b4ed6216288ff4e2a60 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Tue, 5 Sep 2023 19:15:02 -0500 Subject: [PATCH] refactor(nvim): make asm files write to `.target` directory on compile --- dots/.config/nvim/after/ftplugin/asm.lua | 38 +++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) 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, })