Skip to content

Commit d7f55c7

Browse files
authored
Merge pull request #36 from MartianGreed/main
feat: add shell specific configurations
2 parents 12bc776 + 2b09935 commit d7f55c7

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ require("claude-code").setup({
109109
git = {
110110
use_git_root = true, -- Set CWD to git root when opening Claude Code (if in git project)
111111
},
112+
-- Shell-specific settings
113+
shell = {
114+
separator = '&&', -- Command separator used in shell commands
115+
pushd_cmd = 'pushd', -- Command to push directory onto stack (e.g., 'pushd' for bash/zsh, 'enter' for nushell)
116+
popd_cmd = 'popd', -- Command to pop directory from stack (e.g., 'popd' for bash/zsh, 'exit' for nushell)
117+
},
112118
-- Command settings
113119
command = "claude", -- Command used to launch Claude Code
114120
-- Command variants

lua/claude-code/config.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ local M = {}
4747
-- @field verbose string|boolean Enable verbose logging with full turn-by-turn output
4848
-- Additional options can be added as needed
4949

50+
--- ClaudeCodeShell class for shell configuration
51+
-- @table ClaudeCodeShell
52+
-- @field separator string Command separator used in shell commands (e.g., '&&', ';', '|')
53+
-- @field pushd_cmd string Command to push directory onto stack (e.g., 'pushd' for bash/zsh)
54+
-- @field popd_cmd string Command to pop directory from stack (e.g., 'popd' for bash/zsh)
55+
5056
--- ClaudeCodeConfig class for main configuration
5157
-- @table ClaudeCodeConfig
5258
-- @field window ClaudeCodeWindow Terminal window settings
5359
-- @field refresh ClaudeCodeRefresh File refresh settings
5460
-- @field git ClaudeCodeGit Git integration settings
61+
-- @field shell ClaudeCodeShell Shell-specific configuration
5562
-- @field command string Command used to launch Claude Code
5663
-- @field command_variants ClaudeCodeCommandVariants Command variants configuration
5764
-- @field keymaps ClaudeCodeKeymaps Keymaps configuration
@@ -81,6 +88,12 @@ M.default_config = {
8188
use_git_root = true, -- Set CWD to git root when opening Claude Code (if in git project)
8289
multi_instance = true, -- Use multiple Claude instances (one per git root)
8390
},
91+
-- Shell-specific settings
92+
shell = {
93+
separator = '&&', -- Command separator used in shell commands
94+
pushd_cmd = 'pushd', -- Command to push directory onto stack
95+
popd_cmd = 'popd', -- Command to pop directory from stack
96+
},
8497
-- Command settings
8598
command = 'claude', -- Command used to launch Claude Code
8699
-- Command variants
@@ -179,6 +192,23 @@ local function validate_config(config)
179192
return false, 'git.multi_instance must be a boolean'
180193
end
181194

195+
-- Validate shell settings
196+
if type(config.shell) ~= 'table' then
197+
return false, 'shell config must be a table'
198+
end
199+
200+
if type(config.shell.separator) ~= 'string' then
201+
return false, 'shell.separator must be a string'
202+
end
203+
204+
if type(config.shell.pushd_cmd) ~= 'string' then
205+
return false, 'shell.pushd_cmd must be a string'
206+
end
207+
208+
if type(config.shell.popd_cmd) ~= 'string' then
209+
return false, 'shell.popd_cmd must be a string'
210+
end
211+
182212
-- Validate command settings
183213
if type(config.command) ~= 'string' then
184214
return false, 'command must be a string'

lua/claude-code/terminal.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ function M.toggle(claude_code, config, git)
149149
local git_root = git.get_git_root()
150150
if git_root then
151151
-- Use pushd/popd to change directory instead of --cwd
152-
cmd = 'terminal pushd ' .. git_root .. ' && ' .. config.command .. ' && popd'
152+
local separator = config.shell.separator
153+
local pushd_cmd = config.shell.pushd_cmd
154+
local popd_cmd = config.shell.popd_cmd
155+
cmd = 'terminal ' .. pushd_cmd .. ' ' .. git_root .. ' ' .. separator .. ' ' .. config.command .. ' ' .. separator .. ' ' .. popd_cmd
153156
end
154157
end
155158

tests/spec/terminal_spec.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ describe('terminal module', function()
8585
use_git_root = true,
8686
multi_instance = true,
8787
},
88+
shell = {
89+
separator = '&&',
90+
pushd_cmd = 'pushd',
91+
popd_cmd = 'popd',
92+
},
8893
}
8994

9095
claude_code = {
@@ -300,6 +305,30 @@ describe('terminal module', function()
300305

301306
assert.is_true(git_root_cmd_found, 'Terminal command should include git root')
302307
end)
308+
309+
it('should use custom pushd/popd commands when configured', function()
310+
-- Set git config to use root
311+
config.git.use_git_root = true
312+
-- Configure custom directory commands for nushell
313+
config.shell.pushd_cmd = 'enter'
314+
config.shell.popd_cmd = 'exit'
315+
config.shell.separator = ';'
316+
317+
-- Call toggle
318+
terminal.toggle(claude_code, config, git)
319+
320+
-- Check that custom commands were used in terminal command
321+
local custom_cmd_found = false
322+
323+
for _, cmd in ipairs(vim_cmd_calls) do
324+
if cmd:match('terminal enter /test/git/root ; ' .. config.command .. ' ; exit') then
325+
custom_cmd_found = true
326+
break
327+
end
328+
end
329+
330+
assert.is_true(custom_cmd_found, 'Terminal command should use custom directory commands')
331+
end)
303332
end)
304333

305334
describe('start_in_normal_mode option', function()

0 commit comments

Comments
 (0)