galaxyline.lua 7.8 KB

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