Skip to content

Commit e12ddf7

Browse files
committed
change pane directory
+ added logic to change pane directory if its different from project directory, before running run/compile/debug command
1 parent a29e7a7 commit e12ddf7

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lua/tmux-compile/init.lua

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ local function tmux_window_exists(window_name)
5858
return result ~= ""
5959
end
6060

61+
-- change directory if not same as project
62+
local function change_dir(pane)
63+
local proj_dir = vim.fn.trim(vim.fn.system("pwd"))
64+
local win_dir = vim.fn.trim(vim.fn.system("tmux display -p -t " .. pane .. " '#{pane_current_path}'"))
65+
66+
if win_dir ~= proj_dir then
67+
return "cd " .. proj_dir .. "; "
68+
end
69+
70+
return ""
71+
end
72+
6173

6274
--# CALL FUNCTIONS #------------------------------------------------------------
6375

@@ -72,12 +84,7 @@ local function new_window(cmd, error_name)
7284
local window_name = M.config.build_run_window_title
7385

7486
if tmux_window_exists(window_name) then
75-
local proj_dir = vim.fn.trim(vim.fn.system("pwd"))
76-
local win_dir = vim.fn.trim(vim.fn.system("tmux display -p -t " .. window_name .. " '#{pane_current_path}'"))
77-
78-
if win_dir ~= proj_dir then
79-
cmd = "cd " .. proj_dir .. "; " .. cmd
80-
end
87+
cmd = change_dir(window_name) .. cmd
8188

8289
vim.fn.system("tmux selectw -t " .. window_name .. " \\; send-keys '" .. cmd .. "' C-m")
8390
else
@@ -123,6 +130,7 @@ local function split_window(cmd, side, error_name)
123130
if (vim.trim(current_pane) == vim.trim(moved_pane)) then
124131
vim.fn.system("tmux splitw -" .. side .. " '" .. cmd .. "; zsh'")
125132
else
133+
cmd = change_dir(vim.trim(moved_pane)) .. cmd
126134
vim.fn.system("tmux send -t " .. vim.trim(moved_pane) .. " '" .. cmd .. "' C-m")
127135
end
128136
end

0 commit comments

Comments
 (0)