Skip to content

Commit 2b09935

Browse files
committed
feat: add configurable shell navigation commands
1 parent 9156d2a commit 2b09935

4 files changed

Lines changed: 51 additions & 2 deletions

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ local M = {}
5050
--- ClaudeCodeShell class for shell configuration
5151
-- @table ClaudeCodeShell
5252
-- @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)
5355

5456
--- ClaudeCodeConfig class for main configuration
5557
-- @table ClaudeCodeConfig
@@ -89,6 +91,8 @@ M.default_config = {
8991
-- Shell-specific settings
9092
shell = {
9193
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
9296
},
9397
-- Command settings
9498
command = 'claude', -- Command used to launch Claude Code
@@ -197,6 +201,14 @@ local function validate_config(config)
197201
return false, 'shell.separator must be a string'
198202
end
199203

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+
200212
-- Validate command settings
201213
if type(config.command) ~= 'string' then
202214
return false, 'command must be a string'

lua/claude-code/terminal.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +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-
local separator = (config.shell and config.shell.separator) or config.shell.separator
153-
cmd = 'terminal pushd ' .. git_root .. ' ' .. separator .. ' ' .. config.command .. ' ' .. separator .. ' 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
154156
end
155157
end
156158

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)