galaxyline.lua 8.6 KB

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