WIP: show virtualenv inside galaxyline (#767)

This commit is contained in:
Abouzar Parvan 2021-07-08 00:00:55 +04:30 committed by GitHub
parent 51c0f48970
commit e02c7c5abb
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 = {