diff --git a/init.lua b/init.lua index 8bd36c1..77d2974 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,4 @@ -- Only required if you have packer configured as `opt` -require('buildcmd') require('statusline') require('packer_init') require('keybindings') diff --git a/lua/buildcmd.lua b/lua/buildcmd.lua index 0e1886d..54e0cf0 100644 --- a/lua/buildcmd.lua +++ b/lua/buildcmd.lua @@ -9,6 +9,25 @@ local function has_buffer() return job_buffer and vim.fn.buflisted(job_buffer) == 1 end +local function get_build_cmd() + for path, type in vim.fs.dir(vim.fn.getcwd(), nil) + do + if (path == "build.zig") then + return "zig build" + end + if (path == "build.bat" or path == "build.sh") then + if (vim.loop.os_uname().sysname == "Windows_NT") then + -- TODO(twig): if I move to llvm this should work, right now cl doesn't work because nvim spawns a command prompt that doesn't have vcvars in it (nor does it have my stuff) + return "build.bat" + else + -- TODO(twig): this is untested! + return "build.sh" + end + end + end + return "" +end + function save_all_and_build() if job_id then print("Job processing") @@ -29,7 +48,8 @@ function save_all_and_build() end vim.api.nvim_buf_set_option(job_buffer, 'filetype', 'build') vim.api.nvim_buf_set_option(job_buffer, 'modified', false) - -- TODO: if I want to get fancy I can set a build string per language. - job_id = vim.fn.termopen("zig build", {on_exit = job_exit}) + -- THis looks at files in the cwd and decides if there is something to build (build.zig for zig, build.bat/.sh for c++) + local build_cmd = get_build_cmd() + job_id = vim.fn.termopen(build_cmd, {on_exit = job_exit}) vim.api.nvim_buf_set_name(job_buffer, '[build]') end diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 47b52f7..000034d 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -20,6 +20,10 @@ vim.keymap.set('n', 'bb', save_all_and_build, opts) -- Would love to have this be alt but that doesn't work... vim.keymap.set('i', '', '// TODO(twig): ', opts) vim.keymap.set('i', '', '// NOTE(twig): ', opts) +-- This is horrendous on windows, can't use nvim for almost a minute! +vim.keymap.set('n', 'K', '') +vim.keymap.set('n', 'fs', 'Telescope grep_string', opts) +vim.keymap.set('n', 'ss', 'Telescope spell_suggest', opts) local on_attach = function(client, bufnr) vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')