init.lua 6.5 KB

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