galaxyline.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 get_lsp_client = function(msg)
  190. msg = msg or "LSP Inactive"
  191. local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
  192. local clients = vim.lsp.get_active_clients()
  193. if next(clients) == nil then
  194. return msg
  195. end
  196. local lsps = ""
  197. for _, client in ipairs(clients) do
  198. local filetypes = client.config.filetypes
  199. if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
  200. -- print(client.name)
  201. if lsps == "" then
  202. -- print("first", lsps)
  203. lsps = client.name
  204. else
  205. if not string.find(lsps, client.name) then
  206. lsps = lsps .. ", " .. client.name
  207. end
  208. -- print("more", lsps)
  209. end
  210. end
  211. end
  212. if lsps == "" then
  213. return msg
  214. else
  215. return lsps
  216. end
  217. end
  218. table.insert(gls.right, {
  219. ShowLspClient = {
  220. provider = get_lsp_client,
  221. condition = function()
  222. local tbl = { ["dashboard"] = true, [" "] = true }
  223. if tbl[vim.bo.filetype] then
  224. return false
  225. end
  226. return true
  227. end,
  228. icon = " ",
  229. highlight = { colors.grey, colors.alt_bg },
  230. },
  231. })
  232. table.insert(gls.right, {
  233. LineInfo = {
  234. provider = "LineColumn",
  235. separator = " ",
  236. separator_highlight = { "NONE", colors.alt_bg },
  237. highlight = { colors.grey, colors.alt_bg },
  238. },
  239. })
  240. table.insert(gls.right, {
  241. PerCent = {
  242. provider = "LinePercent",
  243. separator = " ",
  244. separator_highlight = { "NONE", colors.alt_bg },
  245. highlight = { colors.grey, colors.alt_bg },
  246. },
  247. })
  248. table.insert(gls.right, {
  249. Tabstop = {
  250. provider = function()
  251. local label = "Spaces: "
  252. if not vim.api.nvim_buf_get_option(0, "expandtab") then
  253. label = "Tab size: "
  254. end
  255. return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
  256. end,
  257. condition = condition.hide_in_width,
  258. separator = " ",
  259. separator_highlight = { "NONE", colors.alt_bg },
  260. highlight = { colors.grey, colors.alt_bg },
  261. },
  262. })
  263. table.insert(gls.right, {
  264. BufferType = {
  265. provider = "FileTypeName",
  266. condition = condition.hide_in_width,
  267. separator = " ",
  268. separator_highlight = { "NONE", colors.alt_bg },
  269. highlight = { colors.grey, colors.alt_bg },
  270. },
  271. })
  272. table.insert(gls.right, {
  273. FileEncode = {
  274. provider = "FileEncode",
  275. condition = condition.hide_in_width,
  276. separator = " ",
  277. separator_highlight = { "NONE", colors.alt_bg },
  278. highlight = { colors.grey, colors.alt_bg },
  279. },
  280. })
  281. table.insert(gls.right, {
  282. Space = {
  283. provider = function()
  284. return " "
  285. end,
  286. separator = " ",
  287. separator_highlight = { "NONE", colors.alt_bg },
  288. highlight = { colors.grey, colors.alt_bg },
  289. },
  290. })
  291. table.insert(gls.short_line_left, {
  292. BufferType = {
  293. provider = "FileTypeName",
  294. separator = " ",
  295. separator_highlight = { "NONE", colors.alt_bg },
  296. highlight = { colors.alt_bg, colors.alt_bg },
  297. },
  298. })
  299. table.insert(gls.short_line_left, {
  300. SFileName = {
  301. provider = "SFileName",
  302. condition = condition.buffer_not_empty,
  303. highlight = { colors.alt_bg, colors.alt_bg },
  304. },
  305. })
  306. --table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}})