diff --git a/lua/hawtkeys/init.lua b/lua/hawtkeys/init.lua index e13b584..48c15d4 100644 --- a/lua/hawtkeys/init.lua +++ b/lua/hawtkeys/init.lua @@ -120,11 +120,27 @@ function M.setup(config) group = auGroup, }) - vim.api.nvim_create_user_command( - "Hawtkeys", - "lua require('hawtkeys.ui').show()", - {} - ) + vim.api.nvim_create_user_command("Hawtkeys", function(args) + local cmd = args.fargs[1] + and args.fargs[1]:gsub("^%s+", ""):gsub("%s$", ""):lower() + if cmd == "all" then + require("hawtkeys.ui").show_all() + elseif cmd == "dupes" then + require("hawtkeys.ui").show_dupes() + else + require("hawtkeys.ui").show() + end + end, { + desc = "Show Hawtkeys", + nargs = "?", + complete = function(arg_lead, _, pos) + if (pos - 9) > #arg_lead then + return {} + end + return { "all", "dupes", "search" } + end, + }) + vim.api.nvim_create_user_command( "HawtkeysAll", "lua require('hawtkeys.ui').show_all()", diff --git a/tests/hawtkeys/init_spec.lua b/tests/hawtkeys/init_spec.lua index 33d3924..0edbd4e 100644 --- a/tests/hawtkeys/init_spec.lua +++ b/tests/hawtkeys/init_spec.lua @@ -1,12 +1,17 @@ local hawtkeys = require("hawtkeys") ---@diagnostic disable-next-line: undefined-field local eq = assert.are.same ----@diagnostic disable-next-line: undefined-field -local falsy = assert.falsy + local userCommands = { - ["Hawtkeys"] = "lua require('hawtkeys.ui').show()", - ["HawtkeysAll"] = "lua require('hawtkeys.ui').show_all()", - ["HawtkeysDupes"] = "lua require('hawtkeys.ui').show_dupes()", + ["Hawtkeys"] = { definition = "Show Hawtkeys", nargs = "?" }, + ["HawtkeysAll"] = { + definition = "lua require('hawtkeys.ui').show_all()", + nargs = "0", + }, + ["HawtkeysDupes"] = { + definition = "lua require('hawtkeys.ui').show_dupes()", + nargs = "0", + }, } describe("set up function", function() @@ -69,17 +74,13 @@ describe("set up function", function() end) it("User commands should be available after setup", function() - local commandspresetup = vim.api.nvim_get_commands({}) hawtkeys.setup({}) local commandsPostSetup = vim.api.nvim_get_commands({}) - -- Check that the commands are not present before setup - for command, _ in ipairs(userCommands) do - falsy(commandspresetup[command]) - end -- Check that the commands are present after setup - for command, action in ipairs(userCommands) do - eq(action, commandsPostSetup[command].definition) + for command, action in pairs(userCommands) do + eq(action.definition, commandsPostSetup[command].definition) + eq(action.nargs, commandsPostSetup[command].nargs) end end) end)