galaxyline.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. -- if not package.loaded['galaxyline'] then
  2. -- return
  3. -- end
  4. local Log = require "core.log"
  5. local status_ok, gl = pcall(require, "galaxyline")
  6. if not status_ok then
  7. Log:get_default().error "Failed to load galaxyline"
  8. return
  9. end
  10. -- NOTE: if someone defines colors but doesn't have them then this will break
  11. local palette_status_ok, colors = pcall(require, lvim.colorscheme .. ".palette")
  12. if not palette_status_ok then
  13. colors = lvim.builtin.galaxyline.colors
  14. end
  15. local condition = require "galaxyline.condition"
  16. local gls = gl.section
  17. gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" }
  18. table.insert(gls.left, {
  19. ViMode = {
  20. provider = function()
  21. -- auto change color according the vim mode
  22. local mode_color = {
  23. n = colors.blue,
  24. i = colors.green,
  25. v = colors.purple,
  26. [""] = colors.purple,
  27. V = colors.purple,
  28. c = colors.magenta,
  29. no = colors.blue,
  30. s = colors.orange,
  31. S = colors.orange,
  32. [""] = colors.orange,
  33. ic = colors.yellow,
  34. R = colors.red,
  35. Rv = colors.red,
  36. cv = colors.blue,
  37. ce = colors.blue,
  38. r = colors.cyan,
  39. rm = colors.cyan,
  40. ["r?"] = colors.cyan,
  41. ["!"] = colors.blue,
  42. t = colors.blue,
  43. }
  44. vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()])
  45. return "▊"
  46. end,
  47. separator_highlight = { "NONE", colors.alt_bg },
  48. highlight = { "NONE", colors.alt_bg },
  49. },
  50. })
  51. -- print(vim.fn.getbufvar(0, 'ts'))
  52. vim.fn.getbufvar(0, "ts")
  53. table.insert(gls.left, {
  54. GitIcon = {
  55. provider = function()
  56. return " "
  57. end,
  58. condition = condition.check_git_workspace,
  59. separator = " ",
  60. separator_highlight = { "NONE", colors.alt_bg },
  61. highlight = { colors.orange, colors.alt_bg },
  62. },
  63. })
  64. table.insert(gls.left, {
  65. GitBranch = {
  66. provider = "GitBranch",
  67. condition = condition.check_git_workspace,
  68. separator = " ",
  69. separator_highlight = { "NONE", colors.alt_bg },
  70. highlight = { colors.grey, colors.alt_bg },
  71. },
  72. })
  73. table.insert(gls.left, {
  74. DiffAdd = {
  75. provider = "DiffAdd",
  76. condition = condition.hide_in_width,
  77. icon = "  ",
  78. highlight = { colors.green, colors.alt_bg },
  79. },
  80. })
  81. table.insert(gls.left, {
  82. DiffModified = {
  83. provider = "DiffModified",
  84. condition = condition.hide_in_width,
  85. icon = " 柳",
  86. highlight = { colors.blue, colors.alt_bg },
  87. },
  88. })
  89. table.insert(gls.left, {
  90. DiffRemove = {
  91. provider = "DiffRemove",
  92. condition = condition.hide_in_width,
  93. icon = "  ",
  94. highlight = { colors.red, colors.alt_bg },
  95. },
  96. })
  97. table.insert(gls.left, {
  98. Filler = {
  99. provider = function()
  100. return " "
  101. end,
  102. highlight = { colors.grey, colors.alt_bg },
  103. },
  104. })
  105. -- get output from shell command
  106. function os.capture(cmd, raw)
  107. local f = assert(io.popen(cmd, "r"))
  108. local s = assert(f:read "*a")
  109. f:close()
  110. if raw then
  111. return s
  112. end
  113. s = string.gsub(s, "^%s+", "")
  114. s = string.gsub(s, "%s+$", "")
  115. s = string.gsub(s, "[\n\r]+", " ")
  116. return s
  117. end
  118. -- cleanup virtual env
  119. local function env_cleanup(venv)
  120. if string.find(venv, "/") then
  121. local final_venv = venv
  122. for w in venv:gmatch "([^/]+)" do
  123. final_venv = w
  124. end
  125. venv = final_venv
  126. end
  127. return venv
  128. end
  129. local PythonEnv = function()
  130. if vim.bo.filetype == "python" then
  131. local venv = os.getenv "CONDA_DEFAULT_ENV"
  132. if venv ~= nil then
  133. return "  (" .. env_cleanup(venv) .. ")"
  134. end
  135. venv = os.getenv "VIRTUAL_ENV"
  136. if venv ~= nil then
  137. return "  (" .. env_cleanup(venv) .. ")"
  138. end
  139. return ""
  140. end
  141. return ""
  142. end
  143. table.insert(gls.left, {
  144. VirtualEnv = {
  145. provider = PythonEnv,
  146. event = "BufEnter",
  147. highlight = { colors.green, colors.alt_bg },
  148. },
  149. })
  150. table.insert(gls.right, {
  151. DiagnosticError = {
  152. provider = "DiagnosticError",
  153. icon = "  ",
  154. highlight = { colors.red, colors.alt_bg },
  155. },
  156. })
  157. table.insert(gls.right, {
  158. DiagnosticWarn = {
  159. provider = "DiagnosticWarn",
  160. icon = "  ",
  161. highlight = { colors.orange, colors.alt_bg },
  162. },
  163. })
  164. table.insert(gls.right, {
  165. DiagnosticInfo = {
  166. provider = "DiagnosticInfo",
  167. icon = "  ",
  168. highlight = { colors.yellow, colors.alt_bg },
  169. },
  170. })
  171. table.insert(gls.right, {
  172. DiagnosticHint = {
  173. provider = "DiagnosticHint",
  174. icon = "  ",
  175. highlight = { colors.blue, colors.alt_bg },
  176. },
  177. })
  178. table.insert(gls.right, {
  179. TreesitterIcon = {
  180. provider = function()
  181. if next(vim.treesitter.highlighter.active) ~= nil then
  182. return " "
  183. end
  184. return ""
  185. end,
  186. separator = " ",
  187. separator_highlight = { "NONE", colors.alt_bg },
  188. highlight = { colors.green, colors.alt_bg },
  189. },
  190. })
  191. local function get_attached_provider_name(msg)
  192. msg = msg or "LSP Inactive"
  193. local buf_clients = vim.lsp.buf_get_clients()
  194. if next(buf_clients) == nil then
  195. return msg
  196. end
  197. local buf_client_names = {}
  198. for _, client in pairs(buf_clients) do
  199. if client.name ~= "null-ls" then
  200. table.insert(buf_client_names, client.name)
  201. end
  202. end
  203. local null_ls = require "lsp.null-ls"
  204. local null_ls_providers = null_ls.list_supported_provider_names(vim.bo.filetype)
  205. vim.list_extend(buf_client_names, null_ls_providers)
  206. return table.concat(buf_client_names, ", ")
  207. end
  208. table.insert(gls.right, {
  209. ShowLspClient = {
  210. provider = get_attached_provider_name,
  211. condition = function()
  212. local tbl = { ["dashboard"] = true, [" "] = true }
  213. if tbl[vim.bo.filetype] then
  214. return false
  215. end
  216. return true
  217. end,
  218. icon = " ",
  219. highlight = { colors.grey, colors.alt_bg },
  220. },
  221. })
  222. table.insert(gls.right, {
  223. LineInfo = {
  224. provider = "LineColumn",
  225. separator = " ",
  226. separator_highlight = { "NONE", colors.alt_bg },
  227. highlight = { colors.grey, colors.alt_bg },
  228. },
  229. })
  230. table.insert(gls.right, {
  231. PerCent = {
  232. provider = "LinePercent",
  233. separator = " ",
  234. separator_highlight = { "NONE", colors.alt_bg },
  235. highlight = { colors.grey, colors.alt_bg },
  236. },
  237. })
  238. table.insert(gls.right, {
  239. Tabstop = {
  240. provider = function()
  241. local label = "Spaces: "
  242. if not vim.api.nvim_buf_get_option(0, "expandtab") then
  243. label = "Tab size: "
  244. end
  245. return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
  246. end,
  247. condition = condition.hide_in_width,
  248. separator = " ",
  249. separator_highlight = { "NONE", colors.alt_bg },
  250. highlight = { colors.grey, colors.alt_bg },
  251. },
  252. })
  253. table.insert(gls.right, {
  254. BufferType = {
  255. provider = "FileTypeName",
  256. condition = condition.hide_in_width,
  257. separator = " ",
  258. separator_highlight = { "NONE", colors.alt_bg },
  259. highlight = { colors.grey, colors.alt_bg },
  260. },
  261. })
  262. table.insert(gls.right, {
  263. FileEncode = {
  264. provider = "FileEncode",
  265. condition = condition.hide_in_width,
  266. separator = " ",
  267. separator_highlight = { "NONE", colors.alt_bg },
  268. highlight = { colors.grey, colors.alt_bg },
  269. },
  270. })
  271. table.insert(gls.right, {
  272. Space = {
  273. provider = function()
  274. return " "
  275. end,
  276. separator = " ",
  277. separator_highlight = { "NONE", colors.alt_bg },
  278. highlight = { colors.grey, colors.alt_bg },
  279. },
  280. })
  281. table.insert(gls.short_line_left, {
  282. BufferType = {
  283. provider = "FileTypeName",
  284. separator = " ",
  285. separator_highlight = { "NONE", colors.alt_bg },
  286. highlight = { colors.alt_bg, colors.alt_bg },
  287. },
  288. })
  289. table.insert(gls.short_line_left, {
  290. SFileName = {
  291. provider = "SFileName",
  292. condition = condition.buffer_not_empty,
  293. highlight = { colors.alt_bg, colors.alt_bg },
  294. },
  295. })
  296. --table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}})