From 0b880995e3ccdadbc9e1267c1f18ae8577caa49c Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Fri, 21 Mar 2025 08:13:35 -0400 Subject: [PATCH] Adding Custom Run to python --- lua/Polydev/python.lua | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lua/Polydev/python.lua b/lua/Polydev/python.lua index 902eb5f..264c9c0 100644 --- a/lua/Polydev/python.lua +++ b/lua/Polydev/python.lua @@ -196,16 +196,39 @@ end -- -- M.open_float_terminal(venv_cmd .. "python3 " .. main_file) -- end +-- +function M.custom_run() + vim.ui.input({ prompt = "Enter File Name: " }, function(custom_file) + if not custom_file or custom_file == "" then + return print("Run canceled") + end + + local root = M.get_project_root() + -- 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 " .. custom_file) + end) +end function M.run() local root = M.get_project_root() - if not root then - return print("Error: Project root not found.") + 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.") + if vim.fn.filereadable(main_file) == 0 then + return print("Error: main.py not found in project root.") end -- Detect current shell