init.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. -- if not package.loaded['galaxyline'] then
  2. -- return
  3. -- end
  4. local gl = require "galaxyline"
  5. -- get my theme in galaxyline repo
  6. -- local colors = require('galaxyline.theme').default
  7. local colors = {
  8. bg = "#2E2E2E",
  9. -- bg = '#292D38',
  10. yellow = "#DCDCAA",
  11. dark_yellow = "#D7BA7D",
  12. cyan = "#4EC9B0",
  13. green = "#608B4E",
  14. light_green = "#B5CEA8",
  15. string_orange = "#CE9178",
  16. orange = "#FF8800",
  17. purple = "#C586C0",
  18. magenta = "#D16D9E",
  19. grey = "#858585",
  20. blue = "#569CD6",
  21. vivid_blue = "#4FC1FF",
  22. light_blue = "#9CDCFE",
  23. red = "#D16969",
  24. error_red = "#F44747",
  25. info_yellow = "#FFCC66",
  26. }
  27. local condition = require "galaxyline.condition"
  28. local gls = gl.section
  29. gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" }
  30. table.insert(gls.left, {
  31. ViMode = {
  32. provider = function()
  33. -- auto change color according the vim mode
  34. local mode_color = {
  35. n = colors.blue,
  36. i = colors.green,
  37. v = colors.purple,
  38. [""] = colors.purple,
  39. V = colors.purple,
  40. c = colors.magenta,
  41. no = colors.blue,
  42. s = colors.orange,
  43. S = colors.orange,
  44. [""] = colors.orange,
  45. ic = colors.yellow,
  46. R = colors.red,
  47. Rv = colors.red,
  48. cv = colors.blue,
  49. ce = colors.blue,
  50. r = colors.cyan,
  51. rm = colors.cyan,
  52. ["r?"] = colors.cyan,
  53. ["!"] = colors.blue,
  54. t = colors.blue,
  55. }
  56. vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()])
  57. return "▊"
  58. end,
  59. separator_highlight = "StatusLineSeparator",
  60. highlight = "StatusLineNC",
  61. },
  62. })
  63. -- print(vim.fn.getbufvar(0, 'ts'))
  64. vim.fn.getbufvar(0, "ts")
  65. table.insert(gls.left, {
  66. GitIcon = {
  67. provider = function()
  68. return " "
  69. end,
  70. condition = condition.check_git_workspace,
  71. separator = " ",
  72. separator_highlight = "StatusLineSeparator",
  73. highlight = "StatusLineGit",
  74. },
  75. })
  76. table.insert(gls.left, {
  77. GitBranch = {
  78. provider = "GitBranch",
  79. condition = condition.check_git_workspace,
  80. separator = " ",
  81. separator_highlight = "StatusLineSeparator",
  82. highlight = "StatusLineNC",
  83. },
  84. })
  85. table.insert(gls.left, {
  86. DiffAdd = {
  87. provider = "DiffAdd",
  88. condition = condition.hide_in_width,
  89. icon = "  ",
  90. highlight = "StatusLineGitAdd",
  91. },
  92. })
  93. table.insert(gls.left, {
  94. DiffModified = {
  95. provider = "DiffModified",
  96. condition = condition.hide_in_width,
  97. icon = " 柳",
  98. highlight = "StatusLineGitChange",
  99. },
  100. })
  101. table.insert(gls.left, {
  102. DiffRemove = {
  103. provider = "DiffRemove",
  104. condition = condition.hide_in_width,
  105. icon = "  ",
  106. highlight = "StatusLineGitDelete",
  107. },
  108. })
  109. table.insert(gls.left, {
  110. Filler = {
  111. provider = function()
  112. return " "
  113. end,
  114. highlight = "StatusLineGitDelete",
  115. },
  116. })
  117. table.insert(gls.right, {
  118. DiagnosticError = {
  119. provider = "DiagnosticError",
  120. icon = "  ",
  121. highlight = "StatusLineLspDiagnosticsError",
  122. },
  123. })
  124. table.insert(gls.right, {
  125. DiagnosticWarn = {
  126. provider = "DiagnosticWarn",
  127. icon = "  ",
  128. highlight = "StatusLineLspDiagnosticsWarning",
  129. },
  130. })
  131. table.insert(gls.right, {
  132. DiagnosticInfo = {
  133. provider = "DiagnosticInfo",
  134. icon = "  ",
  135. highlight = "StatusLineLspDiagnosticsInformation",
  136. },
  137. })
  138. table.insert(gls.right, {
  139. DiagnosticHint = {
  140. provider = "DiagnosticHint",
  141. icon = "  ",
  142. highlight = "StatusLineLspDiagnosticsHint",
  143. },
  144. })
  145. table.insert(gls.right, {
  146. TreesitterIcon = {
  147. provider = function()
  148. if next(vim.treesitter.highlighter.active) ~= nil then
  149. return " "
  150. end
  151. return ""
  152. end,
  153. separator = " ",
  154. separator_highlight = "StatusLineSeparator",
  155. highlight = "StatusLineTreeSitter",
  156. },
  157. })
  158. local get_lsp_client = function(msg)
  159. msg = msg or "LSP Inactive"
  160. local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
  161. local clients = vim.lsp.get_active_clients()
  162. if next(clients) == nil then
  163. return msg
  164. end
  165. local lsps = ""
  166. for _, client in ipairs(clients) do
  167. local filetypes = client.config.filetypes
  168. if filetypes and vim.fn.index(filetypes, buf_ft) ~= 1 then
  169. -- print(client.name)
  170. if lsps == "" then
  171. -- print("first", lsps)
  172. lsps = client.name
  173. else
  174. lsps = lsps .. ", " .. client.name
  175. -- print("more", lsps)
  176. end
  177. end
  178. end
  179. if lsps == "" then
  180. return msg
  181. else
  182. return lsps
  183. end
  184. end
  185. table.insert(gls.right, {
  186. ShowLspClient = {
  187. provider = get_lsp_client,
  188. condition = function()
  189. local tbl = { ["dashboard"] = true, [" "] = true }
  190. if tbl[vim.bo.filetype] then
  191. return false
  192. end
  193. return true
  194. end,
  195. icon = " ",
  196. highlight = "StatusLineNC",
  197. },
  198. })
  199. table.insert(gls.right, {
  200. LineInfo = {
  201. provider = "LineColumn",
  202. separator = " ",
  203. separator_highlight = "StatusLineSeparator",
  204. highlight = "StatusLineNC",
  205. },
  206. })
  207. table.insert(gls.right, {
  208. PerCent = {
  209. provider = "LinePercent",
  210. separator = " ",
  211. separator_highlight = "StatusLineSeparator",
  212. highlight = "StatusLineNC",
  213. },
  214. })
  215. table.insert(gls.right, {
  216. Tabstop = {
  217. provider = function()
  218. return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
  219. end,
  220. condition = condition.hide_in_width,
  221. separator = " ",
  222. separator_highlight = "StatusLineSeparator",
  223. highlight = "StatusLineNC",
  224. },
  225. })
  226. table.insert(gls.right, {
  227. BufferType = {
  228. provider = "FileTypeName",
  229. condition = condition.hide_in_width,
  230. separator = " ",
  231. separator_highlight = "StatusLineSeparator",
  232. highlight = "StatusLineNC",
  233. },
  234. })
  235. table.insert(gls.right, {
  236. FileEncode = {
  237. provider = "FileEncode",
  238. condition = condition.hide_in_width,
  239. separator = " ",
  240. separator_highlight = "StatusLineSeparator",
  241. highlight = "StatusLineNC",
  242. },
  243. })
  244. table.insert(gls.right, {
  245. Space = {
  246. provider = function()
  247. return " "
  248. end,
  249. separator = " ",
  250. separator_highlight = "StatusLineSeparator",
  251. highlight = "StatusLineNC",
  252. },
  253. })
  254. table.insert(gls.short_line_left, {
  255. BufferType = {
  256. provider = "FileTypeName",
  257. separator = " ",
  258. separator_highlight = "StatusLineSeparator",
  259. highlight = "StatusLineNC",
  260. },
  261. })
  262. table.insert(gls.short_line_left, {
  263. SFileName = {
  264. provider = "SFileName",
  265. condition = condition.buffer_not_empty,
  266. highlight = "StatusLineNC",
  267. },
  268. })
  269. --table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.bg}}})