diff options
author | Abouzar Parvan <[email protected]> | 2021-07-08 00:00:55 +0430 |
---|---|---|
committer | GitHub <[email protected]> | 2021-07-07 15:30:55 -0400 |
commit | e02c7c5abb4fec1cc51588c96b6b4fdff938d1c2 (patch) | |
tree | e4e191d6ef82dbdd904ba5a02cb5ab3a0ca20879 /lua | |
parent | 51c0f489703b7db217c7ff12a1653ddc1abfcb8e (diff) |
WIP: show virtualenv inside galaxyline (#767)
Diffstat (limited to 'lua')
-rw-r--r-- | lua/lv-galaxyline/init.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lua/lv-galaxyline/init.lua b/lua/lv-galaxyline/init.lua index 69404b48..6bcf08f5 100644 --- a/lua/lv-galaxyline/init.lua +++ b/lua/lv-galaxyline/init.lua @@ -125,6 +125,47 @@ table.insert(gls.left, { highlight = "StatusLineGitDelete", }, }) +-- get output from shell command +function os.capture(cmd, raw) + local f = assert(io.popen(cmd, 'r')) + local s = assert(f:read('*a')) + f:close() + if raw then return s end + s = string.gsub(s, '^%s+', '') + s = string.gsub(s, '%s+$', '') + s = string.gsub(s, '[\n\r]+', ' ') + return s +end +-- cleanup virtual env +function env_cleanup(venv) + if string.find(venv, "/") then + final_venv = venv + for w in venv:gmatch("([^/]+)") do final_venv=w end + venv = final_venv + end + return venv +end +local PythonEnv = function () + if vim.bo.filetype == 'python' then + venv = os.getenv('CONDA_DEFAULT_ENV') + if venv ~= nil then + return "🅒 " .. env_cleanup(venv) + end + venv = os.getenv('VIRTUAL_ENV') + if venv ~= nil then + return "🐍 " .. env_cleanup(venv) + end + return '' + end + return '' +end +table.insert(gls.left, { + VirtualEnv = { + provider = PythonEnv, + highlight = {colors.green, colors.bg}, + event = 'BufEnter' + } +}) table.insert(gls.right, { DiagnosticError = { |