From 3137850db67b1b45111656e8749b60eb936dfa7d Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 28 Sep 2023 09:41:36 +0200 Subject: [PATCH] Show Py virtual env on statusline --- lua/config/statusline.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lua/config/statusline.lua b/lua/config/statusline.lua index 1a521a66..e170df4c 100644 --- a/lua/config/statusline.lua +++ b/lua/config/statusline.lua @@ -97,6 +97,27 @@ local diff = function() return info end +local virtual_env = function() + -- only show virtual env for Python + if vim.bo.filetype ~= 'python' then + return "" + end + + local conda_env = os.getenv('CONDA_DEFAULT_ENV') + local venv_path = os.getenv('VIRTUAL_ENV') + + if venv_path == nil then + if conda_env == nil then + return "" + else + return string.format(" %s (conda)", conda_env) + end + else + local venv_name = vim.fn.fnamemodify(venv_path, ':t') + return string.format(" %s (venv)", venv_name) + end +end + require("lualine").setup { options = { icons_enabled = true, @@ -116,6 +137,10 @@ require("lualine").setup { "diff", source = diff, }, + { + virtual_env, + color = { fg = 'black', bg = "#F1CA81" } + } }, lualine_c = { "filename",