galaxyline.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. local function get_attached_provider_name(msg)
  190. msg = msg or "LSP Inactive"
  191. local buf_clients = vim.lsp.buf_get_clients()
  192. if next(buf_clients) == nil then
  193. return msg
  194. end
  195. local buf_ft = vim.bo.filetype
  196. local buf_client_names = {}
  197. local null_ls_providers = require("lsp.null-ls").get_registered_providers_by_filetype(buf_ft)
  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. vim.list_extend(buf_client_names, null_ls_providers)
  204. return table.concat(buf_client_names, ", ")
  205. end
  206. table.insert(gls.right, {
  207. ShowLspClient = {
  208. provider = get_attached_provider_name,
  209. condition = function()
  210. local tbl = { ["dashboard"] = true, [" "] = true }
  211. if tbl[vim.bo.filetype] then
  212. return false
  213. end
  214. return true
  215. end,
  216. icon = " ",
  217. highlight = { colors.grey, colors.alt_bg },
  218. },
  219. })
  220. table.insert(gls.right, {
  221. LineInfo = {
  222. provider = "LineColumn",
  223. separator = " ",
  224. separator_highlight = { "NONE", colors.alt_bg },
  225. highlight = { colors.grey, colors.alt_bg },
  226. },
  227. })
  228. table.insert(gls.right, {
  229. PerCent = {
  230. provider = "LinePercent",
  231. separator = " ",
  232. separator_highlight = { "NONE", colors.alt_bg },
  233. highlight = { colors.grey, colors.alt_bg },
  234. },
  235. })
  236. table.insert(gls.right, {
  237. Tabstop = {
  238. provider = function()
  239. local label = "Spaces: "
  240. if not vim.api.nvim_buf_get_option(0, "expandtab") then
  241. label = "Tab size: "
  242. end
  243. return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
  244. end,
  245. condition = condition.hide_in_width,
  246. separator = " ",
  247. separator_highlight = { "NONE", colors.alt_bg },
  248. highlight = { colors.grey, colors.alt_bg },
  249. },
  250. })
  251. table.insert(gls.right, {
  252. BufferType = {
  253. provider = "FileTypeName",
  254. condition = condition.hide_in_width,
  255. separator = " ",
  256. separator_highlight = { "NONE", colors.alt_bg },
  257. highlight = { colors.grey, colors.alt_bg },
  258. },
  259. })
  260. table.insert(gls.right, {
  261. FileEncode = {
  262. provider = "FileEncode",
  263. condition = condition.hide_in_width,
  264. separator = " ",
  265. separator_highlight = { "NONE", colors.alt_bg },
  266. highlight = { colors.grey, colors.alt_bg },
  267. },
  268. })
  269. table.insert(gls.right, {
  270. Space = {
  271. provider = function()
  272. return " "
  273. end,
  274. separator = " ",
  275. separator_highlight = { "NONE", colors.alt_bg },
  276. highlight = { colors.grey, colors.alt_bg },
  277. },
  278. })
  279. table.insert(gls.short_line_left, {
  280. BufferType = {
  281. provider = "FileTypeName",
  282. separator = " ",
  283. separator_highlight = { "NONE", colors.alt_bg },
  284. highlight = { colors.alt_bg, colors.alt_bg },
  285. },
  286. })
  287. table.insert(gls.short_line_left, {
  288. SFileName = {
  289. provider = "SFileName",
  290. condition = condition.buffer_not_empty,
  291. highlight = { colors.alt_bg, colors.alt_bg },
  292. },
  293. })
  294. --table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}})