Skip to content

Commit

Permalink
restructure commands as data
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Mar 24, 2023
1 parent b370bec commit 39974e0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 48 deletions.
84 changes: 84 additions & 0 deletions lua/op/commands.lua
Original file line number Diff line number Diff line change
@@ -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 # 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' },
},
}
51 changes: 3 additions & 48 deletions plugin/op.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 # 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'))

0 comments on commit 39974e0

Please # to comment.