From ed602389cb29106079ac1a1e96b1928169db5cdc Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Wed, 19 Mar 2025 21:09:55 -0400 Subject: [PATCH] Changing run to check for shell for fish. --- lua/Polydev/python.lua | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/lua/Polydev/python.lua b/lua/Polydev/python.lua index 92dec65..902eb5f 100644 --- a/lua/Polydev/python.lua +++ b/lua/Polydev/python.lua @@ -183,16 +183,42 @@ function M.install_dependency() end) end +-- function M.run() +-- local root = M.get_project_root() +-- if not root then return print("Error: Project root not found.") end +-- +-- local main_file = root .. "/main.py" +-- if vim.fn.filereadable(main_file) == 0 then return print("Error: main.py not found in project root.") end +-- +-- -- Check if virtual environment exists +-- local venv_path = root .. "/venv/bin/activate" +-- local venv_cmd = vim.fn.filereadable(venv_path) == 1 and "source " .. venv_path .. " && " or "" +-- +-- M.open_float_terminal(venv_cmd .. "python3 " .. main_file) +-- end + function M.run() local root = M.get_project_root() - if not root then return print("Error: Project root not found.") end + if not root then + return print("Error: Project root not found.") + end local main_file = root .. "/main.py" - if vim.fn.filereadable(main_file) == 0 then return print("Error: main.py not found in project root.") end + if vim.fn.filereadable(main_file) == 0 then + return print("Error: main.py not found in project root.") + end - -- Check if virtual environment exists - local venv_path = root .. "/venv/bin/activate" - local venv_cmd = vim.fn.filereadable(venv_path) == 1 and "source " .. venv_path .. " && " or "" + -- Detect current shell + local shell = vim.fn.getenv("SHELL") or "" + local venv_cmd + + if shell:match("fish") then + local venv_fish = root .. "/venv/bin/activate.fish" + venv_cmd = vim.fn.filereadable(venv_fish) == 1 and "source " .. venv_fish .. " && " or "" + else + local venv_bash = root .. "/venv/bin/activate" + venv_cmd = vim.fn.filereadable(venv_bash) == 1 and "source " .. venv_bash .. " && " or "" + end M.open_float_terminal(venv_cmd .. "python3 " .. main_file) end