Skip to content

Commit d296017

Browse files
committed
feat: add ability to authenticate using env variable
Fixes #316
1 parent aecb0c7 commit d296017

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,23 @@ use { "zbirenbaum/copilot.lua" }
2222

2323
### Authentication
2424

25+
You can authenticate using one of the following methods:
26+
27+
#### Permanent sign-in (Recommended)
28+
2529
Once copilot is running, run `:Copilot auth` to start the authentication process.
2630

31+
#### Token
32+
33+
Get a token from the github cli using:
34+
35+
```sh
36+
gh auth token
37+
```
38+
39+
Set either the environment variable `GITHUB_COPILOT_TOKEN` or `GH_COPILOT_TOKEN` to that token.
40+
Note that if you have the variable set, even empty, the LSP will attempt to use it to log in.
41+
2742
## Setup and Configuration
2843

2944
You have to run the `require("copilot").setup(options)` function in order to start Copilot.

lua/copilot/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local config = require("copilot.config")
33
local highlight = require("copilot.highlight")
44
local logger = require("copilot.logger")
55
local client = require("copilot.client")
6+
local auth = require("copilot.auth")
67

78
local create_cmds = function()
89
vim.api.nvim_create_user_command("CopilotDetach", function()
@@ -47,6 +48,12 @@ M.setup = function(opts)
4748
-- logged here to ensure the logger is setup
4849
logger.debug("active LSP config (may change runtime):", client.config)
4950

51+
local token_env_set = (os.getenv("GITHUB_COPILOT_TOKEN") ~= nil) or (os.getenv("GH_COPILOT_TOKEN") ~= nil)
52+
53+
if token_env_set then
54+
auth.signin()
55+
end
56+
5057
M.setup_done = true
5158
end
5259

0 commit comments

Comments
 (0)