galaxyline.lua 8.3 KB

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