Skip to content
Mat edited this page Jan 12, 2024 · 4 revisions

Examples of how to authenticate other plugins with op.nvim

Octo.nvim

https://github.com/pwntester/octo.nvim

Assuming you have a 1Password item called "GitHub" with an access token in a field called "token":

require('octo').setup({
  gh_env = function()
    local github_token = require('op').get_secret('GitHub', 'token')
    if not github_token or not vim.startswith(github_token, 'ghp_') then
      error('Failed to get GitHub token.')
    end

    return { GITHUB_TOKEN = github_token }
  end,
})

sg.nvim

https://github.com/sourcegraph/sg.nvim

Assuming you have a 1Password item called "Sourcegraph" with fields "token" and "endpoint":

local output = require('op').get_secret('Sourcegraph', 'token,endpoint')
if output then
  error('Failed to get Sourcegraph token from 1Password')
end
local secrets = vim.split(output, ',')
local token = secrets[1]
local endpoint = secrets[2]
vim.env.SRC_ENDPOINT = endpoint
vim.env.SRC_ACCESS_TOKEN = token
require('sg').setup({
  enable_cody = false,
})
Clone this wiki locally