diff --git a/after/ftplugin/c.lua b/after/ftplugin/c.lua new file mode 100644 index 0000000..cd1cc3b --- /dev/null +++ b/after/ftplugin/c.lua @@ -0,0 +1 @@ +require('build').create_commands() diff --git a/after/ftplugin/cpp.lua b/after/ftplugin/cpp.lua index 1411d13..54962ef 100644 --- a/after/ftplugin/cpp.lua +++ b/after/ftplugin/cpp.lua @@ -1 +1,3 @@ vim.bo.commentstring = '//%s' + +require('build').create_commands() diff --git a/init.lua b/init.lua index 0ce3f8e..8bf6da7 100644 --- a/init.lua +++ b/init.lua @@ -2,6 +2,7 @@ require('settings') require('mappings') require('netrw') require('autocmds') +require('build') local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then diff --git a/lua/build.lua b/lua/build.lua new file mode 100644 index 0000000..f6c3ef1 --- /dev/null +++ b/lua/build.lua @@ -0,0 +1,80 @@ +local build = {} + +function build.dir(opts) + print(vim.inspect(opts)) + local num_fargs = table.maxn(opts.fargs) + local dir = nil + + for index, arg in ipairs(opts.fargs) do + print(index, arg) + end + + if num_fargs == 0 then + -- Find build directories + local dirs = build.list_dirs() + local num_dirs = table.maxn(dirs) + + if num_dirs == 0 then + vim.cmd.echoerr('no build directories found') + + elseif num_dirs == 1 then + -- One build directory found, use it + dir = dirs[1] + + else + -- TODO: Implement Telescope picker + -- Prompt user to choose dir with to inputlist + local choices = {} + for index, choice in ipairs(dirs) do + table.insert(choices, tostring(index) .. ': ' .. choice) + end + local index = vim.fn.inputlist(choices) + dir = dirs[index] + print(' ' .. dir) + end + + elseif num_fargs == 1 then + -- Single argument, invoked as :BuildDir