From 9156d2a4f8b736b36f4f6dd761b80138b9e86b90 Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Tue, 3 Jun 2025 06:31:23 +0200 Subject: [PATCH 1/2] feat: add configurable shell command separator --- lua/claude-code/config.lua | 18 ++++++++++++++++++ lua/claude-code/terminal.lua | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/claude-code/config.lua b/lua/claude-code/config.lua index ab1d618..5f42184 100644 --- a/lua/claude-code/config.lua +++ b/lua/claude-code/config.lua @@ -47,11 +47,16 @@ local M = {} -- @field verbose string|boolean Enable verbose logging with full turn-by-turn output -- Additional options can be added as needed +--- ClaudeCodeShell class for shell configuration +-- @table ClaudeCodeShell +-- @field separator string Command separator used in shell commands (e.g., '&&', ';', '|') + --- ClaudeCodeConfig class for main configuration -- @table ClaudeCodeConfig -- @field window ClaudeCodeWindow Terminal window settings -- @field refresh ClaudeCodeRefresh File refresh settings -- @field git ClaudeCodeGit Git integration settings +-- @field shell ClaudeCodeShell Shell-specific configuration -- @field command string Command used to launch Claude Code -- @field command_variants ClaudeCodeCommandVariants Command variants configuration -- @field keymaps ClaudeCodeKeymaps Keymaps configuration @@ -81,6 +86,10 @@ M.default_config = { use_git_root = true, -- Set CWD to git root when opening Claude Code (if in git project) multi_instance = true, -- Use multiple Claude instances (one per git root) }, + -- Shell-specific settings + shell = { + separator = '&&', -- Command separator used in shell commands + }, -- Command settings command = 'claude', -- Command used to launch Claude Code -- Command variants @@ -179,6 +188,15 @@ local function validate_config(config) return false, 'git.multi_instance must be a boolean' end + -- Validate shell settings + if type(config.shell) ~= 'table' then + return false, 'shell config must be a table' + end + + if type(config.shell.separator) ~= 'string' then + return false, 'shell.separator must be a string' + end + -- Validate command settings if type(config.command) ~= 'string' then return false, 'command must be a string' diff --git a/lua/claude-code/terminal.lua b/lua/claude-code/terminal.lua index 6adaf16..85c449c 100644 --- a/lua/claude-code/terminal.lua +++ b/lua/claude-code/terminal.lua @@ -149,7 +149,8 @@ function M.toggle(claude_code, config, git) local git_root = git.get_git_root() if git_root then -- Use pushd/popd to change directory instead of --cwd - cmd = 'terminal pushd ' .. git_root .. ' && ' .. config.command .. ' && popd' + local separator = (config.shell and config.shell.separator) or config.shell.separator + cmd = 'terminal pushd ' .. git_root .. ' ' .. separator .. ' ' .. config.command .. ' ' .. separator .. ' popd' end end From 2b09935a8479feaa46a42eeeb3e670d27e7366c9 Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Tue, 3 Jun 2025 06:54:14 +0200 Subject: [PATCH 2/2] feat: add configurable shell navigation commands --- README.md | 6 ++++++ lua/claude-code/config.lua | 12 ++++++++++++ lua/claude-code/terminal.lua | 6 ++++-- tests/spec/terminal_spec.lua | 29 +++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 36fc78b..c3ff50c 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,12 @@ require("claude-code").setup({ git = { use_git_root = true, -- Set CWD to git root when opening Claude Code (if in git project) }, + -- Shell-specific settings + shell = { + separator = '&&', -- Command separator used in shell commands + pushd_cmd = 'pushd', -- Command to push directory onto stack (e.g., 'pushd' for bash/zsh, 'enter' for nushell) + popd_cmd = 'popd', -- Command to pop directory from stack (e.g., 'popd' for bash/zsh, 'exit' for nushell) + }, -- Command settings command = "claude", -- Command used to launch Claude Code -- Command variants diff --git a/lua/claude-code/config.lua b/lua/claude-code/config.lua index 5f42184..e1c99a8 100644 --- a/lua/claude-code/config.lua +++ b/lua/claude-code/config.lua @@ -50,6 +50,8 @@ local M = {} --- ClaudeCodeShell class for shell configuration -- @table ClaudeCodeShell -- @field separator string Command separator used in shell commands (e.g., '&&', ';', '|') +-- @field pushd_cmd string Command to push directory onto stack (e.g., 'pushd' for bash/zsh) +-- @field popd_cmd string Command to pop directory from stack (e.g., 'popd' for bash/zsh) --- ClaudeCodeConfig class for main configuration -- @table ClaudeCodeConfig @@ -89,6 +91,8 @@ M.default_config = { -- Shell-specific settings shell = { separator = '&&', -- Command separator used in shell commands + pushd_cmd = 'pushd', -- Command to push directory onto stack + popd_cmd = 'popd', -- Command to pop directory from stack }, -- Command settings command = 'claude', -- Command used to launch Claude Code @@ -197,6 +201,14 @@ local function validate_config(config) return false, 'shell.separator must be a string' end + if type(config.shell.pushd_cmd) ~= 'string' then + return false, 'shell.pushd_cmd must be a string' + end + + if type(config.shell.popd_cmd) ~= 'string' then + return false, 'shell.popd_cmd must be a string' + end + -- Validate command settings if type(config.command) ~= 'string' then return false, 'command must be a string' diff --git a/lua/claude-code/terminal.lua b/lua/claude-code/terminal.lua index 85c449c..2b8172d 100644 --- a/lua/claude-code/terminal.lua +++ b/lua/claude-code/terminal.lua @@ -149,8 +149,10 @@ function M.toggle(claude_code, config, git) local git_root = git.get_git_root() if git_root then -- Use pushd/popd to change directory instead of --cwd - local separator = (config.shell and config.shell.separator) or config.shell.separator - cmd = 'terminal pushd ' .. git_root .. ' ' .. separator .. ' ' .. config.command .. ' ' .. separator .. ' popd' + local separator = config.shell.separator + local pushd_cmd = config.shell.pushd_cmd + local popd_cmd = config.shell.popd_cmd + cmd = 'terminal ' .. pushd_cmd .. ' ' .. git_root .. ' ' .. separator .. ' ' .. config.command .. ' ' .. separator .. ' ' .. popd_cmd end end diff --git a/tests/spec/terminal_spec.lua b/tests/spec/terminal_spec.lua index d861c4a..bd5b5fd 100644 --- a/tests/spec/terminal_spec.lua +++ b/tests/spec/terminal_spec.lua @@ -85,6 +85,11 @@ describe('terminal module', function() use_git_root = true, multi_instance = true, }, + shell = { + separator = '&&', + pushd_cmd = 'pushd', + popd_cmd = 'popd', + }, } claude_code = { @@ -300,6 +305,30 @@ describe('terminal module', function() assert.is_true(git_root_cmd_found, 'Terminal command should include git root') end) + + it('should use custom pushd/popd commands when configured', function() + -- Set git config to use root + config.git.use_git_root = true + -- Configure custom directory commands for nushell + config.shell.pushd_cmd = 'enter' + config.shell.popd_cmd = 'exit' + config.shell.separator = ';' + + -- Call toggle + terminal.toggle(claude_code, config, git) + + -- Check that custom commands were used in terminal command + local custom_cmd_found = false + + for _, cmd in ipairs(vim_cmd_calls) do + if cmd:match('terminal enter /test/git/root ; ' .. config.command .. ' ; exit') then + custom_cmd_found = true + break + end + end + + assert.is_true(custom_cmd_found, 'Terminal command should use custom directory commands') + end) end) describe('start_in_normal_mode option', function()