init.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. -- get output from shell command
  121. function os.capture(cmd, raw)
  122. local f = assert(io.popen(cmd, "r"))
  123. local s = assert(f:read "*a")
  124. f:close()
  125. if raw then
  126. return s
  127. end
  128. s = string.gsub(s, "^%s+", "")
  129. s = string.gsub(s, "%s+$", "")
  130. s = string.gsub(s, "[\n\r]+", " ")
  131. return s
  132. end
  133. -- cleanup virtual env
  134. local function env_cleanup(venv)
  135. if string.find(venv, "/") then
  136. local final_venv = venv
  137. for w in venv:gmatch "([^/]+)" do
  138. final_venv = w
  139. end
  140. venv = final_venv
  141. end
  142. return venv
  143. end
  144. local PythonEnv = function()
  145. if vim.bo.filetype == "python" then
  146. local venv = os.getenv "CONDA_DEFAULT_ENV"
  147. if venv ~= nil then
  148. return "🅒 (" .. env_cleanup(venv) .. ")"
  149. end
  150. venv = os.getenv "VIRTUAL_ENV"
  151. if venv ~= nil then
  152. return "  (" .. env_cleanup(venv) .. ")"
  153. end
  154. return ""
  155. end
  156. return ""
  157. end
  158. table.insert(gls.left, {
  159. VirtualEnv = {
  160. provider = PythonEnv,
  161. highlight = "StatusLineTreeSitter",
  162. event = "BufEnter",
  163. },
  164. })
  165. table.insert(gls.right, {
  166. DiagnosticError = {
  167. provider = "DiagnosticError",
  168. icon = "  ",
  169. highlight = "StatusLineLspDiagnosticsError",
  170. },
  171. })
  172. table.insert(gls.right, {
  173. DiagnosticWarn = {
  174. provider = "DiagnosticWarn",
  175. icon = "  ",
  176. highlight = "StatusLineLspDiagnosticsWarning",
  177. },
  178. })
  179. table.insert(gls.right, {
  180. DiagnosticInfo = {
  181. provider = "DiagnosticInfo",
  182. icon = "  ",
  183. highlight = "StatusLineLspDiagnosticsInformation",
  184. },
  185. })
  186. table.insert(gls.right, {
  187. DiagnosticHint = {
  188. provider = "DiagnosticHint",
  189. icon = "  ",
  190. highlight = "StatusLineLspDiagnosticsHint",
  191. },
  192. })
  193. table.insert(gls.right, {
  194. TreesitterIcon = {
  195. provider = function()
  196. if next(vim.treesitter.highlighter.active) ~= nil then
  197. return " "
  198. end
  199. return ""
  200. end,
  201. separator = " ",
  202. separator_highlight = "StatusLineSeparator",
  203. highlight = "StatusLineTreeSitter",
  204. },
  205. })
  206. local get_lsp_client = function(msg)
  207. msg = msg or "LSP Inactive"
  208. local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
  209. local clients = vim.lsp.get_active_clients()
  210. if next(clients) == nil then
  211. return msg
  212. end
  213. local lsps = ""
  214. for _, client in ipairs(clients) do
  215. local filetypes = client.config.filetypes
  216. if filetypes and vim.fn.index(filetypes, buf_ft) ~= 1 then
  217. -- print(client.name)
  218. if lsps == "" then
  219. -- print("first", lsps)
  220. lsps = client.name
  221. else
  222. lsps = lsps .. ", " .. client.name
  223. -- print("more", lsps)
  224. end
  225. end
  226. end
  227. if lsps == "" then
  228. return msg
  229. else
  230. return lsps
  231. end
  232. end
  233. table.insert(gls.right, {
  234. ShowLspClient = {
  235. provider = get_lsp_client,
  236. condition = function()
  237. local tbl = { ["dashboard"] = true, [" "] = true }
  238. if tbl[vim.bo.filetype] then
  239. return false
  240. end
  241. return true
  242. end,
  243. icon = " ",
  244. highlight = "StatusLineNC",
  245. },
  246. })
  247. table.insert(gls.right, {
  248. LineInfo = {
  249. provider = "LineColumn",
  250. separator = " ",
  251. separator_highlight = "StatusLineSeparator",
  252. highlight = "StatusLineNC",
  253. },
  254. })
  255. table.insert(gls.right, {
  256. PerCent = {
  257. provider = "LinePercent",
  258. separator = " ",
  259. separator_highlight = "StatusLineSeparator",
  260. highlight = "StatusLineNC",
  261. },
  262. })
  263. table.insert(gls.right, {
  264. Tabstop = {
  265. provider = function()
  266. return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
  267. end,
  268. condition = condition.hide_in_width,
  269. separator = " ",
  270. separator_highlight = "StatusLineSeparator",
  271. highlight = "StatusLineNC",
  272. },
  273. })
  274. table.insert(gls.right, {
  275. BufferType = {
  276. provider = "FileTypeName",
  277. condition = condition.hide_in_width,
  278. separator = " ",
  279. separator_highlight = "StatusLineSeparator",
  280. highlight = "StatusLineNC",
  281. },
  282. })
  283. table.insert(gls.right, {
  284. FileEncode = {
  285. provider = "FileEncode",
  286. condition = condition.hide_in_width,
  287. separator = " ",
  288. separator_highlight = "StatusLineSeparator",
  289. highlight = "StatusLineNC",
  290. },
  291. })
  292. table.insert(gls.right, {
  293. Space = {
  294. provider = function()
  295. return " "
  296. end,
  297. separator = " ",
  298. separator_highlight = "StatusLineSeparator",
  299. highlight = "StatusLineNC",
  300. },
  301. })
  302. table.insert(gls.short_line_left, {
  303. BufferType = {
  304. provider = "FileTypeName",
  305. separator = " ",
  306. separator_highlight = "StatusLineSeparator",
  307. highlight = "StatusLineNC",
  308. },
  309. })
  310. table.insert(gls.short_line_left, {
  311. SFileName = {
  312. provider = "SFileName",
  313. condition = condition.buffer_not_empty,
  314. highlight = "StatusLineNC",
  315. },
  316. })
  317. --table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.bg}}})