From 0a9220cdc27ccaee0f1b63049e4566e5db870494 Mon Sep 17 00:00:00 2001 From: Kasper Sternberg Date: Fri, 15 Mar 2024 14:00:27 +0100 Subject: [PATCH] fterm now looks at the current work directory When I open fterm, it nows checks for the current WD for the file I am working in. --- lua/custom/plugins/fterm.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lua/custom/plugins/fterm.lua b/lua/custom/plugins/fterm.lua index 49e3be04..c5a3a186 100644 --- a/lua/custom/plugins/fterm.lua +++ b/lua/custom/plugins/fterm.lua @@ -6,8 +6,22 @@ return { height = 0.6, width = 0.6, }, + -- Initial cmd setting is generic, will be dynamically updated later cmd = 'Powershell.exe', } + + -- Custom function to toggle FTerm with dynamic working directory + local function toggle_ft_with_cwd() + local cwd = vim.fn.getcwd() + -- Update the cmd to change directory to cwd upon opening + require('FTerm'):setup { + cmd = 'Powershell.exe -NoLogo -NoExit -Command "cd \'' .. cwd .. '\'"', + } + -- Toggle FTerm after updating the command + require('FTerm').toggle() + end + + -- Keymap to use the custom toggle function + vim.keymap.set('n', 'tt', toggle_ft_with_cwd, { noremap = true, silent = true, desc = '[T]oggle [T]erminal' }) end, - vim.keymap.set('n', 'tt', ':lua require("FTerm").toggle()', { noremap = true, silent = true, desc = '[T]oggle [T]erminal' }), }