Skip to content

Commit f588df0

Browse files
authored
feat: allow using alternative opencode binaries (#180)
1 parent 07b7a8c commit f588df0

6 files changed

Lines changed: 11 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ require('opencode').setup({
112112
default_global_keymaps = true, -- If false, disables all default global keymaps
113113
default_mode = 'build', -- 'build' or 'plan' or any custom configured. @see [OpenCode Agents](https://opencode.ai/docs/modes/)
114114
keymap_prefix = '<leader>o', -- Default keymap prefix for global keymaps change to your preferred prefix and it will be applied to all keymaps starting with <leader>o
115+
opencode_executable = 'opencode', -- Name of your opencode binary
115116
keymap = {
116117
editor = {
117118
['<leader>og'] = { 'toggle' }, -- Open opencode. Close if opened

lua/opencode/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ M.defaults = {
1212
default_mode = 'build',
1313
legacy_commands = true,
1414
keymap_prefix = '<leader>o',
15+
opencode_executable = 'opencode',
1516
keymap = {
1617
editor = {
1718
['<leader>og'] = { 'toggle', desc = 'Toggle Opencode window' },

lua/opencode/core.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ M.cancel = Promise.async(function()
317317
end)
318318

319319
M.opencode_ok = Promise.async(function()
320-
if vim.fn.executable('opencode') == 0 then
320+
if vim.fn.executable(config.opencode_executable) == 0 then
321321
vim.notify(
322322
'opencode command not found - please install and configure opencode before using this plugin',
323323
vim.log.levels.ERROR
@@ -326,7 +326,7 @@ M.opencode_ok = Promise.async(function()
326326
end
327327

328328
if not state.opencode_cli_version or state.opencode_cli_version == '' then
329-
local result = Promise.system({ 'opencode', '--version' }):await()
329+
local result = Promise.system({ config.opencode_executable, '--version' }):await()
330330
local out = (result and result.stdout or ''):gsub('%s+$', '')
331331
state.opencode_cli_version = out:match('(%d+%%.%d+%%.%d+)') or out
332332
end

lua/opencode/health.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
local M = {}
22

33
local health = vim.health or require('health')
4+
local config = require('opencode.config')
45
local util = require('opencode.util')
56

67
local function command_exists(cmd)
78
return vim.fn.executable(cmd) == 1
89
end
910

1011
local function get_opencode_version()
11-
if not command_exists('opencode') then
12+
if not command_exists(config.opencode_executable) then
1213
return nil, 'opencode command not found'
1314
end
1415

15-
local result = vim.system({ 'opencode', '--version' }):wait()
16+
local result = vim.system({ config.opencode_executable, '--version' }):wait()
1617
if result.code ~= 0 then
1718
return nil, 'Failed to get opencode version: ' .. (result.stderr or 'unknown error')
1819
end
@@ -28,7 +29,7 @@ local function check_opencode_cli()
2829
local state = require('opencode.state')
2930
local required_version = state.required_version
3031

31-
if not command_exists('opencode') then
32+
if not command_exists(config.opencode_executable) then
3233
health.error('opencode command not found', {
3334
'Install opencode CLI from: https://docs.opencode.com/installation',
3435
'Ensure opencode is in your PATH',

lua/opencode/opencode_server.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local util = require('opencode.util')
22
local safe_call = util.safe_call
33
local Promise = require('opencode.promise')
4+
local config = require('opencode.config')
45

56
--- @class OpencodeServer
67
--- @field job any The vim.system job handle
@@ -80,7 +81,7 @@ function OpencodeServer:spawn(opts)
8081
opts = opts or {}
8182

8283
self.job = vim.system({
83-
'opencode',
84+
config.opencode_executable,
8485
'serve',
8586
}, {
8687
cwd = opts.cwd,

lua/opencode/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
---@field default_global_keymaps boolean
197197
---@field default_mode 'build' | 'plan' | string -- Default mode
198198
---@field keymap_prefix string
199+
---@field opencode_executable 'opencode' | string -- Command run for calling opencode
199200
---@field keymap OpencodeKeymap
200201
---@field ui OpencodeUIConfig
201202
---@field context OpencodeContextConfig

0 commit comments

Comments
 (0)