Przeglądaj źródła

WIP: show virtualenv inside galaxyline (#767)

Abouzar Parvan 4 lat temu
rodzic
commit
e02c7c5abb
1 zmienionych plików z 41 dodań i 0 usunięć
  1. 41 0
      lua/lv-galaxyline/init.lua

+ 41 - 0
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 = {