From 39974e0901fa927ae38b9757c9b34c4222a7c671 Mon Sep 17 00:00:00 2001 From: Mat Jones Date: Fri, 24 Mar 2023 08:25:32 -0400 Subject: [PATCH] restructure commands as data --- lua/op/commands.lua | 84 +++++++++++++++++++++++++++++++++++++++++++++ plugin/op.lua | 51 ++------------------------- 2 files changed, 87 insertions(+), 48 deletions(-) create mode 100644 lua/op/commands.lua diff --git a/lua/op/commands.lua b/lua/op/commands.lua new file mode 100644 index 0000000..f58eafa --- /dev/null +++ b/lua/op/commands.lua @@ -0,0 +1,84 @@ +return { + { + 'OpInsert', + function() + require('op').op_insert() + end, + { desc = 'Insert a 1Password item reference at the current cursor position' }, + }, + { + 'OpCreate', + function() + require('op').op_create() + end, + { desc = 'Create a new 1Password item from strings in the current buffer' }, + }, + { + 'OpView', + function() + require('op').op_view_item() + end, + { desc = 'Open an item in the 1Password 8 desktop app' }, + }, + { + 'OpEdit', + function() + require('op').op_edit_item() + end, + { desc = 'Open an item to the edit view in the 1Password 8 desktop app' }, + }, + { + 'OpOpen', + function() + require('op').op_open_and_fill() + end, + { desc = 'Open and fill an item in your default browser' }, + }, + { + 'OpSignin', + function(input) + local account_identifier = input and input.fargs and input.fargs[1] or nil + require('op').op_signin(account_identifier) + end, + { desc = 'Choose a 1Password account to sign in with', nargs = '?' }, + }, + { + 'OpSignout', + function() + require('op').op_signout() + end, + { desc = 'Sign out of 1Password CLI' }, + }, + { + 'OpWhoami', + function() + require('op').op_whoami() + end, + { desc = 'Check what 1Password account you are currently signed in with' }, + }, + { + 'OpNote', + function(args) + require('op').op_note(args and args.fargs and (args.fargs[1] == 'new' or args.fargs[1] == 'create')) + end, + { desc = 'Find and open a 1Password Secure Note', nargs = '?' }, + }, + { + 'OpSidebar', + function(input) + local should_refresh = false + if input and input.fargs and input.fargs[1] == 'refresh' then + should_refresh = true + end + require('op').op_sidebar(should_refresh) + end, + { desc = 'Toggle the 1Password sidebar', nargs = '?' }, + }, + { + 'OpAnalyzeBuffer', + function() + require('op').op_analyze_buffer() + end, + { desc = 'Run 1Password secret detection diagnostics on current buffer' }, + }, +} diff --git a/plugin/op.lua b/plugin/op.lua index a0d2d4a..70e2620 100644 --- a/plugin/op.lua +++ b/plugin/op.lua @@ -5,51 +5,6 @@ end state.commands_initialized = true -vim.api.nvim_create_user_command('OpInsert', function() - require('op').op_insert() -end, { desc = 'Insert a 1Password item reference at the current cursor position' }) - -vim.api.nvim_create_user_command('OpCreate', function() - require('op').op_create() -end, { desc = 'Create a new 1Password item from strings in the current buffer' }) - -vim.api.nvim_create_user_command('OpView', function() - require('op').op_view_item() -end, { desc = 'Open an item in the 1Password 8 desktop app' }) - -vim.api.nvim_create_user_command('OpEdit', function() - require('op').op_edit_item() -end, { desc = 'Open an item to the edit view in the 1Password 8 desktop app' }) - -vim.api.nvim_create_user_command('OpOpen', function() - require('op').op_open_and_fill() -end, { desc = 'Open and fill an item in your default browser' }) - -vim.api.nvim_create_user_command('OpSignin', function(input) - local account_identifier = input and input.fargs and input.fargs[1] or nil - require('op').op_signin(account_identifier) -end, { desc = 'Choose a 1Password account to sign in with', nargs = '?' }) - -vim.api.nvim_create_user_command('OpSignout', function() - require('op').op_signout() -end, { desc = 'Sign out of 1Password CLI' }) - -vim.api.nvim_create_user_command('OpWhoami', function() - require('op').op_whoami() -end, { desc = 'Check what 1Password account you are currently signed in with' }) - -vim.api.nvim_create_user_command('OpNote', function(args) - require('op').op_note(args and args.fargs and (args.fargs[1] == 'new' or args.fargs[1] == 'create')) -end, { desc = 'Find and open a 1Password Secure Note', nargs = '?' }) - -vim.api.nvim_create_user_command('OpSidebar', function(input) - local should_refresh = false - if input and input.fargs and input.fargs[1] == 'refresh' then - should_refresh = true - end - require('op').op_sidebar(should_refresh) -end, { desc = 'Toggle the 1Password sidebar', nargs = '?' }) - -vim.api.nvim_create_user_command('OpAnalyzeBuffer', function() - require('op').op_analyze_buffer() -end, { desc = 'Run 1Password secret detection diagnostics on current buffer' }) +vim.tbl_map(function(cmd) + vim.api.nvim_create_user_command(cmd[1], cmd[2], cmd[3]) +end, require('op.commands'))